|
|
Log in / Subscribe / Register

Dynamic allocation

Dynamic allocation

Posted Feb 3, 2026 14:12 UTC (Tue) by MKesper (subscriber, #38539)
Parent article: Modernizing swapping: introducing the swap table

The new table array, which is designed to occupy exactly one page on most architectures, is allocated dynamically, reducing the swap subsystem's memory use when the swap files are not full.

Could there be a situation where the array needs to be resized and there's no place left in RAM for that?


to post comments

Dynamic allocation

Posted Feb 3, 2026 14:21 UTC (Tue) by daroc (editor, #160859) [Link] (2 responses)

I had that same thought while reviewing the article! Jon's take was that if the system has already ended up in a state where it can't free even a single page of memory in order to make several more available, the situation is already probably pretty dire.

In practice, if the system has swap configured, it's going to want to swap out some pages of memory before it tries unloading file-backed pages that are currently in use; therefore, if this mechanism does need another page urgently, it can bump a file-backed page, finish swapping out the anonymous pages, and then let the file-backed page get faulted back in.

Where is the decision to allocate a swap table made?

Posted Feb 3, 2026 16:04 UTC (Tue) by farnz (subscriber, #17727) [Link] (1 responses)

Do you know where the decision to allocate the table is made?

I'm wondering if the kernel is able to promise that it starts swapping (if there's swap configured) before it's down to its last clean or free page - so that it never actually gets into the situation where it can't allocate a page of physical memory to allow it to free up more by swapping, because in the worst case, it can do the file-backed page dance you describe.

Where is the decision to allocate a swap table made?

Posted Feb 3, 2026 17:13 UTC (Tue) by corbet (editor, #1) [Link]

The kernel will start reclaim long before it gets to that last free page. There are watermark levels that it tries to never go below.

Dynamic allocation

Posted Feb 3, 2026 23:24 UTC (Tue) by iabervon (subscriber, #722) [Link]

The kernel generally needs some memory available in order to tell a storage device to write something (even if the something to write is already in place and it's just writing out a dirty file-backed page in cache so that it can free it), so it's got memory reserved for that sort of thing. Presumably, resizing the array gets access to this reserved memory as well, so that it can expand some and swap out more than that so that the memory reservation is restored.


Copyright © 2026, Eklektix, Inc.
Comments and public postings are copyrighted by their creators.
Linux is a registered trademark of Linus Torvalds