What is the Out-of-Memory (OOM) Killer and how to tune it?
Jul 11, 2025 am 12:12 AMOOM Killer is a mechanism for Linux systems to terminate processes when memory is exhausted to prevent crashes. It can protect critical processes from being killed by adjusting the oom_score_adj value, and optimize system-level memory management through overcommit settings. It is scored based on factors such as process memory usage and importance. The higher the score, the easier it is to be killed; to prevent key processes from being killed, the oom_score_adj can be set to -1000; the overcommit_memory policy can be adjusted at the system level, limit memory and swap usage, and monitor OOM events through dmesg. In Kubernetes or Docker environments, you need to pay attention to the interaction effect of resource quotas and cgroups.
When the Linux system is insufficient, a mechanism called OOM Killer (Out-of-Memory Killer) will be enabled. Its role is to selectively terminate certain processes to free up memory resources and prevent the entire system from crashing. While this mechanism can serve as the "last line of defense", the default behavior is not always the most reasonable - sometimes it may kill processes you don't want to be killed.
If you are running a high-load service, a container environment, or have specific processes that need protection, it is necessary to understand and properly adjust the behavior of OOM Killer.
What is OOM Killer?
OOM Killer is part of the Linux kernel and is triggered when the system can no longer allocate memory (including swap space). It will score each process according to a set of scoring mechanisms. The higher the score, the easier it is to be selected and killed.
This set of ratings mainly consider several factors:
- The memory size used by the process
- The importance of the process (such as whether it is started by root)
- Is it running for a long time
- OOM score adj value (I'll talk about it later)
You can view and modify the adjustment value of a process in /proc/<pid>/oom_score_adj</pid>
, and control the overall memory allocation strategy in /proc/sys/vm/overcommit_memory
, etc.
How to prevent key processes from being killed by OOM Killer?
If you have a service that cannot be interrupted easily (such as the database main process), you can reduce the probability of being killed by adjusting its OOM score.
The method is as follows:
- Modify the
oom_score_adj
value of the process, the range is -1000 to 1000. The lower the value, the less likely it is to be killed. - For example, if you want to protect a process with PID 1234, you can execute:
echo -500 > /proc/1234/oom_score_adj
- If you want to completely ban OOM Killer from killing this process, you can set it to -1000:
echo -1000 > /proc/1234/oom_score_adj
?? Note: Only root permissions can modify these values. In addition, do not set all processes to -1000 casually, as this may cause the system to be killed without processes and get stuck.
How to tune system-level OOM behavior?
In addition to a single process, some adjustments can be made from the system level to affect the triggering timing and behavior of OOM Killer:
Adjust overcommit settings
/proc/sys/vm/overcommit_memory
controls memory allocation policy:- 0: Default mode, allowing moderate memory over-allocation.
- 1: Always allow excessive distribution, suitable for testing environments.
- 2: Excessive distribution is prohibited, it is more conservative and suitable for production environments.
Limit the maximum amount of available swaps
Setting/proc/sys/vm/overcommit_ratio
andswappiness
can indirectly affect the memory pressure performance of the system before OOM occurs.Monitoring system log
When OOM Killer is actually triggered, the system will record relevant information in dmesg or syslog. You can check whether any process has been killed by:dmesg | grep -i 'oom\|kill'
Practical application suggestions
- In Kubernetes or Docker environments, the behavior of OOM Killer may interact with the memory limit of cgroups. At this time, pay special attention to the setting of resource quota.
- For development environments, you can temporarily close OOM Killer for debugging (not recommended for long-term use):
echo 1 > /proc/sys/vm/panic_on_oom
The system will crash directly in OOM instead of killing the process, which is suitable for certain test scenarios.
- Regularly check the oom_score_adj values ??of critical services to make sure they have not returned to the default values ??due to restarts or other reasons.
Basically that's it. OOM Killer is a useful guarantee mechanism, but in actual deployment, it often requires certain adjustments based on business needs. Understanding its working principle and configuration will help improve the stability and controllability of the system.
The above is the detailed content of What is the Out-of-Memory (OOM) Killer and how to tune it?. For more information, please follow other related articles on the PHP Chinese website!

Hot AI Tools

Undress AI Tool
Undress images for free

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Clothoff.io
AI clothes remover

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics

There are three ways to create empty files in the command line: First, the simplest and safest use of the touch command, which is suitable for debugging scripts or placeholder files; Second, it is quickly created through > redirection but will clear existing content, which is suitable for initializing log files; Third, use echo"> file name to create a file with an empty string, or use echo-n""> file name to avoid line breaks. These three methods have their own applicable scenarios, and choosing the right method can help you complete the task more efficiently.

Are you looking for good software to write mathematical equations? If so, this article provides the top 5 equation editors that you can easily install on your favorite Linux distribution.In addition to being compatible with different types of mathema

Eclipse is a free integrated development environment (IDE) that programmers around the world use to write software, primarily in Java, but also in other major programming languages using Eclipse plugins.The latest release of Eclipse IDE 2023?06 does

Linux administrators should be familiar with the command-line environment. Since GUI (Graphical User Interface) mode in Linux servers is not commonly installed.SSH may be the most popular protocol to enable Linux administrators to manage the servers

Linux has a rich collection of commands, and while many of them are powerful and useful for various tasks, there are also some funny and whimsical commands that you can try out for amusement. 1. sl Command (Steam Locomotive) You might be aware of the

LXD is described as the next-generation container and virtual machine manager that offers an immersive for Linux systems running inside containers or as virtual machines. It provides images for an inordinate number of Linux distributions with support

PPA is an important tool for Ubuntu users to expand their software sources. 1. When searching for PPA, you should visit Launchpad.net, confirm the official PPA in the project official website or document, and read the description and user comments to ensure its security and maintenance status; 2. Add PPA to use the terminal command sudoadd-apt-repositoryppa:/, and then run sudoaptupdate to update the package list; 3. Manage PPAs to view the added list through the grep command, use the --remove parameter to remove or manually delete the .list file to avoid problems caused by incompatibility or stopping updates; 4. Use PPA to weigh the necessity and prioritize the situations that the official does not provide or require a new version of the software.

Gogo is a remarkable tool to bookmark directories inside your Linux shell. It helps you create shortcuts for long and complex paths in Linux. This way, you no longer need to type or memorize lengthy paths on Linux.For example, if there's a directory
