Linux — Out-of-Memory Killer (OOM killer)

Shlomi Boutnaru, Ph.D.
2 min readDec 3, 2022

--

The Linux kernel has a mechanism called “out-of-memory killer” (aka OOM killer) which is used to recover memory on a system. The OOM killer allows killing a single task (called also oom victim) while that task will terminate in a reasonable time and thus free up memory.

When OOM killer does its job we can find indications about that by searching the logs (like /var/log/messages and grepping for “Killed”). If you want to configure the “OOM killer” I suggest reading the following link https://www.oracle.com/technical-resources/articles/it-infrastructure/dev-oom-killer.html.

It is important to understand that the OOM killer chooses between processes based on the “oom_score”. If you want to see the value for a specific process we can just read “/proc/[PID]/oom_score” — as shown in the screenshot below. If we want to alter the score we can do it using “/proc/[PID]/oom_score_adj” — as shown also in the screenshot below. The valid range is from 0 (never kill) to 1000 (always kill), the lower the value is the lower is the probability the process will be killed. For more information please read https://man7.org/linux/man-pages/man5/proc.5.html.

In the next writeup I am going to elaborate about the kernel thread “oom_reaper”. See you in my next writeup ;-)

--

--