[talk] Does swap still matter?

Miles Nordin carton at Ivy.NET
Wed Mar 16 12:25:35 EDT 2022


> When RAM never seemed adequate for a system in the past, the utility of 
> swap was obvious.

idea #1:

The measure of used RAM isn't obvious.  RAM allocated by sbrk or mmap is
not used until it's written to for the first time.  (or maybe read, I am
not sure)

what's more interesting wrt swap is, on some mallocs, like at least older
GNU malloc, freed RAM is never returned to the OS.  tcmalloc does return 
RAM to the OS, but on some kind of lazy background thread or something.  so
if a C program uses a whole bunch of RAM at startup then frees it, the physical
RAM can only actually be freed by writing it to swap (then never reading it),
or by the process exiting.

The best measure of memory a program is actually using is thus often based
on a presumption of swap.  It's the "working set," or the RSS under memory
pressure, the set of pages that would lead to a catastrophic drop in 
performance if they were swapped.  

I have seen some systems that claim to measure working set without memory 
pressure or swap, but seems rare and untrustworthy.

This definition is sort of unavoidable if you read files with mmap, though.  
Once the file is mapepd, you could scan it, like you would with read(), which
should not use RAM for the whole file.  Or you could treat it as if it were 
in RAM and read single bytes all over the place, which would cause thrashing 
if it weren't backed by RAM.  There is no difference to the API that could
easily be seen with static analysis.  It's all about how the program runs.
And even tools like 'cp' use mmap to read files, so you can't easily pretend
this is some esoteric scientific computing question that us ordinary peasant
sysadmins can ignore.

so it's sort of awkward to define how much RAM an algorithm uses without
running it under swap pressure.  That doesn't convince me we need to use
swap.  I don't think it's well productionized because programs were never
killed for OOM when they started thrashing.  Thrashing is really a sharp
line, different from "swap is making it slower," but I never used an
integrated system that surfaced this line to the sysadmin, respected user-
and process-isolation wrt this line, while with containers and VMs and
balloon drivers we can sort of do those things now so long as there's no
swap.  I just want to point out that the modern world isn't actually 
cleaner than the old swapful world.  It was really a pathetic admission of 
defeat that we didn't finish the work to characterize how much RAM an 
algorithm uses and isolate it under time sharing.


idea #2:

as an unmotivated datapoint, "these people seem to know what they're doing 
and have healthy irreverence," two modern systems I know about swap to zram 
(Chrome OS and one other), ie. they compress memory like "RAM Doubler" in 
the 80s.  My guess is that's probably the right thing to be doing even though
it sounds goofy to me.




More information about the talk mailing list