Out of Memory Killer
The Out of Memory (OOM) Killer is the Linux kernel's out of memory
management handling mechanism.
OOM is a condition that occurs in Linux when the system starts running
out of memory (RAM) because the system is under a heavy load, or some
processes are using too much memory. In cases like this, the kernel could
panic, or a program could crash - it is during these moments that the OOM
Killer comes into play.
The OOM Killer is a mechanism in the Linux kernel that handles
situations when a system is critically low on memory (physical or swap).
The OOM Killer verifies that the system is truly out of memory, and
once that is verified, the OOM Killer selects a process to kill, and free
the memory that was being used by that process.
If it ever becomes necessary for the OOM Killer to kill processes, the
decision of which processes to kill will be made based on something
called the OOM score. Each process has an OOM score associated with
it.
Every running process in Linux has an OOM score. The operating system
calculates the OOM score for a process, based on several criteria - the
criteria are mainly influenced by the amount of memory the process is
using. Typically, the OOM score varies between -1000 and 1000. When
the OOM Killer needs to kill a process, again, due to the system running
low on memory, the process with the highest OOM score will be killed
first!
The OOM score of a running process can be viewed by executing
the following command:
$ cat /proc/<process_ID>/oom_score
Note: You may recall that the proc filesystem acts as an interface to
internal data structures in the kernel. It can be used to obtain information
about the system, some of which are the Linux processes.
In addition to being able to view the OOM score through the /proc
filesystem, the OOM score of a process can be also be modified.
The OOM score can be modified using the following command:
$ echo <new_OOM_score> /proc/<process_ID>/oom_score_adj
Finally, if you ever want to see if a process was killed due to an
out of memory condition, you can always check the logs. An example
to do so would be:
$ grep -i kill /var/log/messages*
That's all I got! I just wanted to gossip a little bit about the
Out of Memory Killer for a moment. There's much more to
say about this mechanism, but this is enough for openers.
Red Hat
Learning Community
A collaborative learning environment, enabling open source skill development.