[talk] Does swap still matter?

Brian Cully bcully at gmail.com
Wed Mar 16 15:37:11 EDT 2022

On Wed, Mar 16, 2022 at 2:50 PM James K. Lowden
<jklowden at schemamania.org> wrote:
> On Wed, 16 Mar 2022 11:03:26 -0400
> George Rosamond <george at ceetonetechnology.com> wrote:
> > Do certain applications/OS functions still use swap as opposed to RAM
> > for some reason?
> 1.  Where does mmap MAP_ANON go?

Nowhere. It waits for a page fault.

> 2.  I assume swap is necessary because Linux defaults to overcommitted
> memory.  Because of that default, now a decade old at least, C
> libraries are being written to allocate gobs of memory that they'll
> never use. On systems without swap, that means real memory.

Nope. Linux overcommits because it doesn't actually allocate anything
until a page fault occurs on the allocated memory region. I've even
just tested this by allocating 64GiB on my swap-less Linux system. No
extra memory was taken up because I never attempted to access that RAM
region, so it never faulted, so it was never allocated.

> Of course, you need *enough* swap.  On the NetBSD system I was using, I
> think it was ndm that was the culprit. I don't remember anymore what I
> was doing, some webbish thing, ISTR.  Died repeatedly in the middle of
> the night until I tracked it down.

Enough swap is 0 swap for a lot of us a lot of the time.

> In case it's not obvious, swap that provides memory that is never used
> doesn't slow the system down, because it's never paged in.

The problems occur when swap does start to get used, and you can end
up in disk thrashing loops as things have to constantly page in and
out in order to make room for whatever RAM is necessary for the
current working set. It definitely hurts a lot less to be constantly
paging with NVMe drives than it did with spinning rust. But it still
hurts, and I have more than enough scars from the spinning rust days
that I turn swap off whenever I can.


More information about the talk mailing list