Senior
How does the OOM Killer choose a process to kill? How is oom_score calculated?
sobes.tech AI
Answer from AI
The OOM Killer in Linux selects a process to kill based on an assessment of how 'guilty' the process is of causing memory shortage. It uses the oom_score parameter, which is calculated by the kernel.
oom_score depends on several factors:
- Memory used by the process (RSS, swap).
- The lifetime of the process (the longer, the lower the priority for killing).
- The process priority (for example, processes with higher priority or with the
oom_score_adjflag lower are less likely to be killed).
The higher the oom_score, the more likely the process will be chosen for termination.
The oom_score_adj parameter allows manual adjustment of the score, setting a value from -1000 (never kill) to +1000 (most likely to kill).
Thus, the OOM Killer selects the process with the highest score, considering memory, priority, and settings, to minimize system damage when freeing memory.