Linux 5.15 Adds New Syscall To More Quickly Free Memory Of Dying Processes
Earlier this summer I wrote about a proposed "process_reap" system call for more quickly reclaiming memory when under pressure. It's that work that evolved into "process_mrelease" and this new system call is now ready to go for Linux 5.15.
The aim in that using this system call can allow for reclaiming memory of a dying process quickly and more predictably than the status quo.
Linux -- particularly Linux on the desktop -- traditionally hasn't coped too well when under memory pressure but there has been steady progress in recent years with systemd-oomd, various kernel innovations, and now process_mrelease being the latest work in this area.
The patch merged to Linux 5.15 by way of Andrew Morton's patch series goes on to explain this process_mrelease system call:
For such system component it's important to be able to free memory quickly and efficiently. Unfortunately the time process takes to free up its memory after receiving a SIGKILL might vary based on the state of the process (uninterruptible sleep), size and OPP level of the core the process is running. A mechanism to free resources of the target process in a more predictable way would improve system's ability to control its memory pressure.
Introduce process_mrelease system call that releases memory of a dying process from the context of the caller. This way the memory is freed in a more controllable way with CPU affinity and priority of the caller. The workload of freeing the memory will also be charged to the caller. The operation is allowed only on a dying process.