|
|
Log in / Subscribe / Register

Turn it sideways (Out-of-memory victim selection with BPF)

Turn it sideways (Out-of-memory victim selection with BPF)

Posted Sep 11, 2023 16:47 UTC (Mon) by fest3er (guest, #60379)
Parent article: Out-of-memory victim selection with BPF

It occurs to me that the problem could be turned on its side. Instead of killing a random process, implement per-process swap space that is in addition to standard swap.

The kernel has access to 'everything', so when there is memory pressure:

  1. Find the process to bully, preferably one that is growing the fastest or uses the most memory. If it has a process swap file, skip to step 4.
  2. Find a FS that has, mmm, 10x more free space than memory requested and at least 10% available.
  3. Create a contiguous swap file on that FS for the selected process, at 4x the requested space.
  4. Page out (2x requested memory) of the process to its swap file, then complete the memory request.
  5. Going forward, when that process wants more RAM, grow its swap space as needed and page more of it out.
  6. When memory pressure eases, page other processes back in from their swap files as needed.
  7. If a process' swap file hasn't been read from or written to for a minute or five and is (nearly) empty (basically use-once code/data and not much of anything else), migrate the contents to the system swap and remove the process' swap file.
  8. When the process exits, clear and delete all of the swap spaces attached to it.
Per-process swap space could solve several problems. The whole system wouldn't necessarily slow down because one process is using tremendous amounts of memory and disk caching would be less affected. Huge processes would largely affect only themselves.


to post comments


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