Expedited memory reclaim from killed processes
Expedited memory reclaim from killed processes
Posted Apr 14, 2019 7:21 UTC (Sun) by k3ninho (subscriber, #50375)In reply to: Expedited memory reclaim from killed processes by mjthayer
Parent article: Expedited memory reclaim from killed processes
The Linux kernel exists in a perpetual low-available-memory state. Inherently it's a caching strategy responsible for a lot of the speed in Linux. I don't know the statistics but several multiples of your machine's physical memory are allocated in the virtual memory addressing space by a design choice called memory over-commit.
But which bits are meaningful over-commit that you'd count towards a system low memory state and which are merely 'maybe useful'? This question is a cache invalidation problem for those 'maybe useful' bits -- a problem already solved elsewhere in the kernel, which provides a pattern we can follow. That pattern is the least-recently-used list so, while you can't predict what user or network interaction comes next, you keep track of access times and then have the bottom end of the list for old and unused items. Pick a level of granularity for parts of a process's memory space and track the least-recently-used bits, hoping to find a ratio of maybe-useful vs definitely-useful memory commit that you'd use to set the line at which the oom-killer gets invoked.
This isn't the whole picture -- the fork()+exec() paradigm can leave child processes sharing over-committed memory with their parents, which is only moved into dedicated address space for the child when it's changed -- a pattern called copy-on-write. We'd need to do more work to be certain that this memory is definitely-useful, for example it might be read-only state that each child needs from the parent, reading it often.
There's excellent write-up in lwn's history:
Taming the OOM killer -- https://lwn.net/Articles/317814/
Improving the OOM killer -- https://lwn.net/Articles/684945/
K3n.
Posted Apr 14, 2019 12:45 UTC (Sun)
by nix (subscriber, #2304)
[Link] (1 responses)
Posted Apr 15, 2019 12:20 UTC (Mon)
by k3ninho (subscriber, #50375)
[Link]
K3n.
Expedited memory reclaim from killed processes
which is only moved into dedicated address space for the child when it's changed
The address space is always dedicated to the child after fork(), even before CoW. The *physical memory* is not.
Expedited memory reclaim from killed processes
