Skip site navigation (1)Skip section navigation (2)
Date:      Sat, 17 Nov 2018 20:51:43 -0500
From:      Mark Johnston <markj@freebsd.org>
To:        Mark Millard <marklmi@yahoo.com>
Cc:        freebsd-hackers Hackers <freebsd-hackers@freebsd.org>
Subject:   Re: 13-CURRENT: several GB swap being used despite plenty of free RAM
Message-ID:  <20181118015143.GD2799@raichu>
In-Reply-To: <F5ACF6D0-DBD7-416F-9AAC-7709771FE545@yahoo.com>
References:  <1748688.u6MfGjpqfb@photon.int.bluestop.org> <alpine.BSF.2.20.1811172251090.60846@puchar.net> <1542499188.56571.59.camel@freebsd.org> <20181118001318.GB2799@raichu> <F5ACF6D0-DBD7-416F-9AAC-7709771FE545@yahoo.com>

next in thread | previous in thread | raw e-mail | index | archive | help
On Sat, Nov 17, 2018 at 04:41:55PM -0800, Mark Millard wrote:
> On 2018-Nov-17, at 16:13, Mark Johnston <markj at freebsd.org> wrote:
> > 
> > On Sat, Nov 17, 2018 at 04:59:48PM -0700, Ian Lepore wrote:
> >> On Sat, 2018-11-17 at 22:52 +0100, Wojciech Puchar wrote:
> >>> freebsd will not swap with that lots of free ram.
> >>> but it's 90GB free NOW, how about before?
> >>> 
> >> 
> >> Your information is outdated. For at least a couple years now (since
> >> approximately the 10.1 - 10.2 timeframe is my vague estimate), freebsd
> >> will page out application memory that hasn't been referenced for some
> >> time, even when the system has no shortage of free memory at all.
> > 
> > No, FreeBSD will only ever swap when there is a free page shortage.  The
> > difference is that we now slowly age unreferenced pages into the
> > inactive queue, which makes them candidates for pageout and subsequent
> > eviction.  With pageout_update_period=0, anonymous memory won't get
> > paged out unless there's a shortage of inactive pages, or an application
> > calls madvise(MADV_DONTNEED) on a range of memory (which moves any
> > backing pages to the inactive queue).
> 
> Swapping is built on top of paging as I understand. The system
> can page without swapping but can not swap without (effectively)
> paging to implement the swapping, if I understand right.

Right.

> If I
> understand right, swapped-out means that kernel stacks have
> been written out and have to be loaded back in RAM before the
> process/threads can even run. (I might not understand.)

When free pages are scarce, one measure that the kernel may take to
address the shortage is to swap out the kernel stacks of the threads in
a process, thus allowing the pages backing the stacks to be reused for
some other purpose, but preventing that process from running on a CPU
until the stacks are swapped back in and "locked" (wired) into memory.

Most of the pages consumed by an application like firefox are not used
for kernel stacks.  Most of them are used for the application's heap
memory, and are thus private to that process.  In general, pieces of
such memory are subject to being paged out to the swap device,
particularly when they are not frequently referenced (read or written
to) by the application, in order to replenish the pool of free pages.
Such memory is often said to be swapped out.

As a side note, there are some system calls that modify this behaviour.
mlock(2) effectively prevents the kernel from swapping out pages backing
the specified virtual addresses; this guarantees that an access of the
virtual memory range will never incur the cost of an expensive page-in.
madvise(MADV_FREE) tells the kernel that the specified pages may be
freed without first being written to the swap device.  Thus, a
subsequent read of an affected page may return the page's previous
contents (if the page had not yet been reclaimed to make up for a
shortage), or all zeroes (if the page had been freed without saving its
contents to swap).

> If I've got that right, are there distinctions here for
> paging that is not part of swapping vs. actual swapping
> (and its use of paging)? Saying that something does not
> swap does not necessarily imply that it does not page:
> it still could have paging activity that does not include
> moving the kernel stacks for the process to backing media?

Indeed, as I tried to describe above, kernel stack swapouts usually
represent only a small portion of many applications' total swap
usage, to the point where I at least usually don't think much about
them.

> At times I have trouble interpreting when wording goes back
> and forth between swapping and paging, both for the intended
> meaning and for the technical implications.

When discussing paging activity related to the swap pager, I
typically use those terms interchangeably.  Sorry for the confusion.



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?20181118015143.GD2799>