What is OOM Killer?
The OOM killer, a feature enabled by default, is a self protection mechanism employed the Linux kernel when under severe memory pressure.
If the kernel can not find memory to allocate when it’s needed, it puts in-use user data pages on the swap-out queue, to be swapped out. If the Virtual Memory (VM) cannot allocate memory and cannot swap out in-use memory, the Out-of-memory killer may begin killing current userspace processes. it will sacrifice one or more processes in order to free up memory for the system when all else fails.
If you have a line like below in /var/log/messages
Apr 1 00:01:02 srv01 kernel: Out of Memory: Killed process 2592 (oracle).
this means that the OOM killer has killed the oracle dedicated server process 2592.
Disabling OOM-KILLER in CentOS/RHEL 5,6
Red Hat Enterprise Linux 5 and 6 do not have the ability to completely disable OOM-KILLER. Please see the following section for tuning OOM-KILLER operation within RHEL 5 and RHEL 6.
It is possible to prioritize which processes get killed by adjusting the oom_killer score. In /proc/PID/ there are two tools labelled oom_adj and oom_score. Valid scores for oom_adj are in the range -16 to +15. This value is used to calculate the ‘badness‘ of the process using an algorithm that also takes into account how long the process has been running, amongst other factors. To see the current oom_killer score, view the oom_score for the process. oom_killer will kill processes with the highest scores first.
This example adjusts the oom_score of a process with a PID of 12465 to make it less likely that oom_killer will kill it.
# cat /proc/12465/oom_score 79872 # echo -5 > /proc/12465/oom_adj # cat /proc/12465/oom_score 78
There is also a special value of -17, which disables oom_killer for that process. In the example below, oom_score returns a value of 0,indicating that this process would not be killed.
# cat /proc/12465/oom_score 78 # echo -17 > /proc/12465/oom_adj # cat /proc/12465/oom_score 0
Setting “overcommit_memory” to 2, allows you to be precise about memory overcommitting. This instructs the kernel never to commit address space larger than swap space plus a fraction “overcommit_ratio” of the physical memory.
Commit = swap + (overcommit_ratio/100) * physical memory
When memory usage hits this number no more allocations should be possible. Committed_AS in /proc/meminfo shows the currently committed amount of memory on the system.
Out of Memory (OOM) refers to a computing state where all available memory, including swap space, has been allocated. Normally this will cause the system to panic and stop. Although OOM cannot be completely disabled in CentOS/RHEL 5,6; it can be tuned to prioritize which processes get killed by adjusting the oom_killer score.