This answer explains the actions taken by the kernel when an OOM situation is encountered based on the value of sysctl vm.overcommit_memory
.
When overcommit_memory
is set to 0 or 1, overcommit
is enabled, and programs are allowed to allocate more memory than is really available.
Now what happens when we run out of memory in this situation? How does the OOM killer decide which process to kill first?
Best Answer
If memory is exhaustively used up by processes, to the extent which can possibly threaten the stability of the system, then the OOM killer comes into the picture.
NOTE: It is the task of the OOM Killer to continue killing processes until enough memory is freed for the smooth functioning of the rest of the process that the Kernel is attempting to run.
The OOM Killer has to select the best process(es) to kill. Best here refers to that process which will free up the maximum memory upon killing and is also the least important to the system.
The primary goal is to kill the least number of processes that minimizes the damage done and at the same time maximizing the amount of memory freed.
To facilitate this, the kernel maintains an
oom_score
for each of the processes. You can see theoom_score
of each of the processes in the/proc
filesystem under thepid
directory.The higher the value of
oom_score
of any process, the higher is its likelihood of getting killed by the OOM Killer in an out-of-memory situation.How is the
OOM_Score
calculated?References
http://www.queryhome.com/15491/whats-happening-kernel-starting-killer-choose-which-process https://serverfault.com/a/571326