What is OOM Killer?
Out-of-Memory (OOM) Killer is a utility that kills out-of-memory processes. It works by sending a SIGKILL signal to the offending process rather than killing it directly. Out-of-Memory is a kernel error message that occurs when the system runs out of memory, after which programs stop working.
When running a Linux server, you might want to run a service, such as Apache, MySQL, etc., on a single computer. But you may not always have enough memory to allocate to these services. Additionally, if you leave them idle, they consume more memory than you have allocated. In this case, the operating system kills processes to free up memory, and this is known as the Out-of-Memory (OOM) killer.
How does it work?
When the system runs low on memory, the kernel starts to kill out memory processes according to their priority level. The kernel's default behavior is to terminate only high-priority processes; however, if no free memory is found, the kernel begins to terminate the out-of-memory processes.
To avoid unnecessary thrashing, the OOM Killer checks every minute whether enough free memory has become available to accommodate the request. So, it kills off programs using too much memory until there is room left.
Why do we use OOM Killer?
Using OOM Killer reduces the possibility of crashing the Linux server due to resource exhaustion. It is especially beneficial for servers that perform critical tasks like web serving or database management. In addition, OOM Killer helps reduce the number of active processes running on the server at any given time.
How to enable/ disable OOM Killer?
You can disable the OOM Killer using the following command –
#sudo -s sysctl -w vm.oom-kill = 0
To reenable the OOM Killer, run the following command –
#sudo -s sysctl -w vm.oom-kill = 1
You need root permissions to edit this file.