Operations 5 min read

How Linux’s OOM Killer Works and How to Protect Critical Processes

Linux’s OOM Killer activates when memory is exhausted, scoring processes based on usage, priority, and kernel settings, then terminating the highest‑scoring one; the article explains its background, scoring algorithm, influencing parameters, and practical steps such as adjusting oom_score_adj, optimizing memory use, and using cgroups to safeguard essential services.

Ops Development & AI Practice
Ops Development & AI Practice
Ops Development & AI Practice
How Linux’s OOM Killer Works and How to Protect Critical Processes

Background of the OOM Killer

Linux uses an overcommit memory policy, allowing the total requested memory by processes to exceed the physical RAM because allocations are often not used immediately. When many processes start using their allocated memory simultaneously, the system can run out of RAM, triggering the OOM Killer.

How the OOM Killer Operates

When memory is insufficient and other recovery methods (cache reclaim, swap) fail, the kernel calls the out_of_memory() function, which starts the OOM Killer. The killer scans all processes, calculates an oom_score for each based on memory consumption, priority, and other factors, and selects the process with the highest score for termination.

Factors Influencing OOM Killer Decisions

Memory usage : The more physical memory a process consumes, the higher its oom_score and the greater the chance it will be killed.

Process priority : Adjusting the value in /proc/[PID]/oom_score_adj changes the oom_score . The range is -1000 to 1000; higher values increase kill probability, while -1000 protects the process from termination.

System parameters : Kernel settings such as /proc/sys/vm/overcommit_memory and /proc/sys/vm/panic_on_oom affect OOM Killer behavior. overcommit_memory controls the overcommit strategy, and panic_on_oom decides whether the system panics or invokes the OOM Killer when memory is exhausted.

Preventing Critical Processes from Being Killed

To keep essential services (e.g., sshd) alive, you can take the following actions:

Adjust oom_score_adj : Set the value to -1000 for the critical process. echo -1000 > /proc/[PID]/oom_score_adj Optimize memory usage : Ensure applications use memory efficiently, avoid leaks, and reduce unnecessary consumption.

Configure memory limits : Use mechanisms like cgroups to impose memory caps on processes, preventing any single process from monopolizing RAM.

Conclusion

The OOM Killer safeguards Linux systems by selectively terminating processes when memory runs out. Understanding its scoring algorithm and tuning related kernel parameters, along with good application memory practices and cgroup limits, are essential for maintaining the stability of critical services.

Original Source

Signed-in readers can open the original source through BestHub's protected redirect.

Sign in to view source
Republication Notice

This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactadmin@besthub.devand we will review it promptly.

Memory ManagementLinuxSystem AdministrationOOM killercgroups
Ops Development & AI Practice
Written by

Ops Development & AI Practice

DevSecOps engineer sharing experiences and insights on AI, Web3, and Claude code development. Aims to help solve technical challenges, improve development efficiency, and grow through community interaction. Feel free to comment and discuss.

0 followers
Reader feedback

How this landed with the community

Sign in to like

Rate this article

Was this worth your time?

Sign in to rate
Discussion

0 Comments

Thoughtful readers leave field notes, pushback, and hard-won operational detail here.