In order to speed up the discovery of what the memory-hogging process is at crunch time (when the OOM killer is invoked), the kernel assigns and maintains an OOM score on a per-process basis (you can always look up the value in the /proc/<pid>/oom_score pseudo-file).
The OOM score range is 0 to 1000:
- An OOM score of 0 implies that the process is not using any memory available to it
- An OOM score of 1000 implies the process is using 100 percent of the memory available to it
Obviously, the process with the highest OOM score wins. Its reward – it is instantly killed by the OOM killer (talk about dry humor). Not so fast though: the kernel has heuristics to protect important tasks. For example, the baked-in heuristics imply that the OOM killer will not select as its victim any root-owned process, a kernel thread, or a task that has a hardware device open.
What if we would like to ensure...