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:
- 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.
- Find a FS that has, mmm, 10x more free space than memory requested and at least 10% available.
- Create a contiguous swap file on that FS for the selected process, at 4x the requested space.
- Page out (2x requested memory) of the process to its swap file, then complete the memory request.
- Going forward, when that process wants more RAM, grow its swap space as needed and page more of it out.
- When memory pressure eases, page other processes back in from their swap files as needed.
- 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.
- When the process exits, clear and delete all of the swap spaces attached to it.
