Swap on SSD

Scott Bennett bennett at sdf.org
Fri Feb 9 11:11:27 UTC 2018


Frank Leonhardt <frank2 at fjl.co.uk> wrote:

> On 2018-02-08 13:48, Scott Bennett wrote:
> > On Wed, 07 Feb 2018 15:01:07 +0000 Frank Leonhardt <frank2 at fjl.co.uk>
> > wrote
> >> On 2018-02-05 18:53, Robert Huff wrote:
> >>> Frank Leonhardt writes:
> >>> 
> >>>>  FreeBSD doesn't actually swap these days; uses demand paging.
> >>> 
> >>> 	Possible evidence to the contrary:
> >>> 	On a system running:
> >>> 
> >>> FreeBSD 12.0-CURRENT #0 r326723: Sat Dec  9 12:30:04 EST 2017 amd64
> >>> 
> >>> 	top shows:
> >>> 
> >>> last pid: 57956;  load averages:  2.02,  2.01,  1.95   up 57+19:09:04
> >>> 13:49:29
> >>> 132 processes: 3 running, 129 sleeping
> >>> CPU: 38.7% user,  0.4% nice,  7.9% system,  0.0% interrupt, 53.0% 
> >>> idle
> >>> Mem: 2264M Active, 2303M Inact, 1478M Laundry, 1525M Wired, 761M Buf,
> >>> 115M Free
> >>> Swap: 17G Total, 996M Used, 16G Free, 5% Inuse
> >>> 
> >>> 	So ... is "Swap" an incorrect label, or is actual swapping
> >>> going on?
> >> 
> >> Yes, it's an incorrect label.
> >> 
> >      Well, yes and no.  The "swap" space can be used for both paging 
> > and
> > swapping in BSD UNIX.  Note that to swap a process out does *not* 
> > require
> > writing all of its in-memory pages' content to the swap area, but 
> > rather
> > enough of them to satisfy the system's need for available page frames 
> > at
> > the time, and it also requires marking the process as "swapped out", so
> > that the scheduler knows that the process has been temporarily 
> > deactivated.
> > The "swapped out" status also makes any of the process's pages still in
> > memory prime fodder for the pagedaemon to harvest to continue to fill 
> > the
> > system's needs.
> >      And on Wed, 07 Feb 2018 15:18:15 +0000 he also wrote:
> >> On 2018-02-05 20:08, John R. Levine wrote:
> >>> In article <24BAEBB4-FAA7-47C8-A6FC-32839063666F at kreme.com>, LuKreme
> >>> <kremels at kreme.com> wrote:
> >>>> On Feb 5, 2018, at 09:13, Frank Leonhardt <frank2 at fjl.co.uk> wrote:
> >>>>> FreeBSD doesn't actually swap these days; uses demand paging. This
> >>>>> means that blocks of RAM that are hardly ever used can get
> >>>> copied to disk. This may include some stuff that's only accessed a 
> >>>> few
> >>>> times a year, but would otherwise be occupying precious
> >>>> RAM that would be much more useful as a disk cache. That said, 
> >>>> FreeBSD
> >>>> tends not to page out except as a last resort - probably a
> >>>> mistake but I can't prove it.
> >>> 
> >> <snip>
> >> 
> >>> On one of my BSD cloud virtual machines I have a server process that
> >>> slurps in about a gigabyte of stuff into a very large perl table, 
> >>> then
> >>> sits there and answers queries from that table.  The system swaps 
> >>> like
> >>> crazy for a few seconds while it's loading up the table, then quiets
> >>> down and reads a few pages a second from the swap as the queries come
> >>> in. That's about the worst case, and only becasue I'm a cheapskate 
> >>> and
> >>> don't want to pay for a larger VM where everything would fit in RAM.
> >> 
> >> On a VM you have no idea whether anything is on disk or in RAM - 
> >> chances
> >> are in this case your swap partition is in the hypervisor's disk 
> >> cache.
> >> 
> >      Quite right.
> > 
> >> ---------------
> >> 
> >> There seems to be some confusion on this list about swapping and 
> >> paging.
> >> Swapping is old hat. Basically when doing a context swap you wrote a
> >> non-running process to a swap area to free up RAM space. We don't do
> > 
> >      Sort of right.  See what I wrote above in response to your other
> > message.
> > 
> >> that anymore - we use demand paged virtual memory. All processes
> > 
> >      Dead wrong.  BSD UNIX is still quite capable of doing both 
> > swapping
> > and paging.  Try loading your system to a load average of, say, at 
> > least
> > 15-20 times the number of CPU threads (a.k.a. logical CPUs) with 
> > processes
> > that need large working sets relative to the physical memory of the 
> > machine
> > and/or are very CPU-bound.  You don't typically see any of the BSDs 
> > actively
> > swapping, but they can, and they will when any number of pathological 
> > loads
> > are bogging the system down, so that the system can recover to get some 
> > work
> > done.  There is a hysteresis involved, so that the demands on the 
> > system's
> > various resources must have returned to much lower levels before 
> > swapped-out
> > processes may begin to be swapped back into memory and their execution
> > resumed.  Someone else (my apologies for having forgotten who) posted a 
> > brief
> > note to this effect in this discussion already, but perhaps you missed 
> > it.
> > 
> >> potentially remain resident, but some of their memory map may be paged
> >> out to disk to free up RAM. If the process tries to access such a page
> >> the MMU interrupts the kernel, which loads in the missing page and 
> >> uses
> >> the MMU to put it back in the process space at the right location 
> >> before
> >> returning control.
> >> 
> >> I'm not being pedantic here - the difference between swapped and paged
> >> systems is very significant if you're optimising disk/RAM usage.
> >> 
> >> Swap areas have been replaced by page areas on disk, but the name 
> >> stuck.
> > 
> >      No, they haven't, but they did become "dual-use" spaces back in 
> > 3.0BSD.
> > See above.
> > 
> >> A bit like core store - I haven't used core store since the 1980's but
> >> we still have "core dumps". Youngsters in the office look at me oddly
> >> when I use terms like core and DASD...
> >> 
> >      ...and disk packs, selector channels, cards, line printers, and... 
> > :-)
>
> Hi Scott,
>
> Thanks - interesting! I was looking at the FreeBSD VM code several years 
> ago, and it rings a bell but I wasn't sure whether what I was looking at 
> was actually in use. I was investigating what was happening in low 
> memory conditions, and basically concluded that it picked the largest 
> process and simply killed it.

     I have had swapping happen, from 4.3BSD to maybe FreeBSD 7.3, on a few
occasions, no more than once per release.  In all cases, the system was
horribly bogged down and nearly unresponsive interactively until enough
processes had been swapped out.  The swapping eventually did allow the system
to resume functioning well enough that I could then figure out what had gone
wrong and how to deal with it.  Usually when things get bad enough to trigger
swapping, they are really, really bad, so even with swapping doing its job,
system responsiveness may still be far less than desirable, and corrective
actions may be delayed in actually getting run, but at least they become
possible again because of swapping.  The main caveat is that your corrective
commands may also be swapped out before completion, so plan carefully, and
use only commands with very small resource requirements. :-)  But one also
quickly learns to avoid most of the ways such situations might develop lest
one suffer such pain again, so most sysadmins don't experience this class of
thrillers very many times.
>
> I like the idea of BSD still swapping on occasion, so I'm glad to hear 
> it does. Do you happen to know if Linux can?

     No, I don't.  I have next to zero experience with LINUX systems.
     However, LINUX was originally designed to be a SysV workalike, based
upon SysVR2.3 or SysVR2.4, with several BSDisms grafted on, including a
networking stack and Sun's NFS and NIS, and the BSD FFS (essentially all
UNIXes, except actual AT&T SysV UNIX, ad{o,a}pted the FFS).  IIRC, SysVR2.3+
implemented demand paging and kept its swapping mechanism, as modified to
accommodate demand paging.  Therefore I would expect LINUX to have followed
that model initially, but I have no knowledge of the matter one way or
another, much less of what may have transpired in LINUX development since
that era.  There are many others on this list who would know the answer to
your question, I'm quite sure.
     It may be worth noting here that swapping in UNIX predates virtual
memory implementations.  Swapping is how many mini-computer operating system,
including UNIX, managed multiple on-line users with very limited memories
(i.e., often much less than 64 KB).  Virtual memory support in hardware
at first merely enabled swapping in such systems* to be made less violent and
extreme.  BSD UNIX was exceptional because its first virtual memory
implementation included demand paging.  *VMS was, IIRC, another exception.
>
> As to disk packs etc - they don't really exist except in reminiscences, 
> and then they know I'm talking about the old days. I still use the term 
> Winchester (or even mini-Wini) without thinking, and confuse everyone.
>
     As long as you don't slip and say, "RAMAC", instead of "Winchester",
you'll probably skate. :-)  Otherwise they may search you and your dwelling
for scarabs or coffins, check your latest dental X-rays, see whether your
blood still flows or has dried up, and so forth.


                                  Scott Bennett, Comm. ASMELG, CFIAG
**********************************************************************
* Internet:   bennett at sdf.org   *xor*   bennett at freeshell.org  *
*--------------------------------------------------------------------*
* "A well regulated and disciplined militia, is at all times a good  *
* objection to the introduction of that bane of all free governments *
* -- a standing army."                                               *
*    -- Gov. John Hancock, New York Journal, 28 January 1790         *
**********************************************************************


More information about the freebsd-questions mailing list