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 cannot 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 can’t 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.
Determining and Configuring Likelihood of Process being Killed in an out-of-memory Situation
It is possible to adjust the oom-score for each process on the system. In the ‘/proc’ file system, there are 2 files for each system enlisted task that provide control over the likelihood that a proccess should be terminated. These files are:
For backwards compatibility with previous kernels, /proc/[pid]/oom_adj may also be used to tune the badness score. Its acceptable values range from -16 (OOM_ADJUST_MIN) to +15 (OOM_ADJUST_MAX) and a special value of -17 (OOM_DISABLE) to disable oom killing entirely for that task. Its value is scaled linearly with /proc/
/oom_score_adj. The value of /proc/[pid]/oom_score_adj is added to the badness score before it is used to determine which task to kill. Acceptable values range from -1000 (OOM_SCORE_ADJ_MIN) to +1000 (OOM_SCORE_ADJ_MAX). This allows userspace to polarize the preference for oom killing either by always preferring a certain task or completely disabling it. The lowest possible value, -1000, is equivalent to disabling oom killing entirely for that task since it will always report a badness score of 0.
/proc/[pid]/oom_adj is used to adjust the “OOM score”, which determines the likelihood of a process being killed in an out-of-memory situation. A higher OOM score means a higher likelihood that the process will be killed by oomkill. Valid values are -17 to 15; note that an OOM score of -17 means [pid] will never be killed.
To specify an OOM score, simply echo the score to /proc/[pid]/oom_adj. For example, to set an OOM score of 15 to [pid] 1111, run:
# echo 15 > /proc/1111/oom_adj
/proc/[pid]/oom_score displays the current OOM score for a given process. Use cat to display the current OOM score for [pid]. For example, to view the current OOM score for [pid] 1111, run:
# cat /proc/1111/oom_score