Understanding and Configuring the Linux OOM Killer

Linux is well known for its strong memory management capabilities, but even the most optimized systems can encounter low-memory conditions. When this happens, the kernel uses a safeguard called the Out-Of-Memory (OOM) Killer to prevent the system from freezing or crashing.

The OOM Killer is triggered when available memory and swap space are exhausted. Its job is to identify and terminate processes that are consuming excessive memory, freeing resources so the system remains operational.

In this guide, we’ll look at how the OOM Killer operates, how it decides which processes to kill, and how you can fine-tune its behavior using sysctl parameters.


How the OOM Killer Works

When the system runs out of memory, the Linux kernel looks at all the running processes to decide which one to stop. This decision is based on a "badness score" assigned to each process. The higher the score, the more likely the process will be stopped.

Key factors influencing the OOM Killer’s decision:

  • Memory usage - Processes consuming large amounts of RAM receive higher scores.
  • Importance of the Process - Essential system processes are less likely to be stopped.
  • Resource release potential - Processes that can quickly free up significant memory are preferred targets.
  • CPU usage - High CPU consumption can also raise a process’s score.


Viewing and Adjusting OOM Scores

Every process has two files that indicate and adjust its OOM priority:

  • /proc/<pid>/oom_score - Shows the current score for the process.
  • /proc/<pid>/oom_score_adj - Lets you increase or decrease the likelihood of termination.

Example:

cat /proc/1234/oom_score

The higher the number, the greater the chance that process will be terminated when the system runs out of memory.


Configuring the OOM Killer with sysctl

You can control aspects of the OOM Killer’s behavior through kernel parameters. Most are located under /proc/sys/vm/ for system-wide settings or under /proc/<pid>/ for per-process adjustments.

The Linux OOM (Out-Of-Memory) Killer can be tuned using several sysctl parameters, mostly found under /proc/sys/vm/ and /proc/<pid>/.

Here is a list of sysctl options that help configure the OOM Killer:

  1. vm.panic_on_oom
Path: /proc/sys/vm/panic_on_oom

Description: Controls whether the kernel should panic when it encounters an out-of-memory situation instead of invoking the OOM killer.

Values:

  • 0 → Use OOM killer (default)
  • 1 → Panic on OOM (useful in high-availability systems where you want to force failover)
  • 2 → Panic only if sysrq is set to 1
  1. vm.oom_kill_allocating_task
Path: /proc/sys/vm/oom_kill_allocating_task

Description: If this is enabled, the OOM Killer will kill the task that caused the memory shortage, rather than choosing another process.

Values:

  • 0 → Let the OOM killer choose the process
  • 1 → Kill the process that requested the memory allocation
  1. vm.oom_dump_tasks
Path: /proc/sys/vm/oom_dump_tasks

Description: Controls whether to log information about all tasks before killing one.

Values:

  • 0 → Do not dump task info
  • 1 → Dump task info to kernel logs (default)
  1. per-process tunable: oom_score_adj
Path: /proc/<pid>/oom_score_adj

Description: This adjusts how likely a process is to be selected by the OOM Killer.

Range:

  • -1000 → Never kill this process
  • 0 → Default
  • +1000 → Kill this process first
  1. per-process tunable: oom_adj (deprecated)
Path: /proc/<pid>/oom_adj

Description: Older interface for adjusting OOM scoring (replaced by oom_score_adj).

 

Example of checking current OOM killer sysctl settings:

sysctl vm.panic_on_oom
sysctl vm.oom_kill_allocating_task
sysctl vm.oom_dump_tasks


Example of changing a tunable:

sysctl -w vm.panic_on_oom=1


Conclusion

The OOM Killer is an essential safeguard in Linux that ensures system stability during memory exhaustion events. By understanding how it calculates process priority and by tuning its sysctl parameters, administrators can better protect critical services and reduce downtime.

Combining proper OOM Killer configuration with proactive monitoring can help keep both small systems and large-scale hosting environments responsive under heavy memory pressure. 

If managing low-memory events and fine-tuning OOM Killer settings sounds complex, our Server Management Services can help. At Ucartz, our expert Linux administrators specialize in performance optimization, proactive monitoring, and advanced kernel tuning to ensure your servers remain stable even under heavy load. Whether you run high-traffic websites, mission-critical applications, or large-scale hosting infrastructure, we can configure, monitor, and maintain your environment so you can focus on your core business while we handle the technical challenges.

Was this answer helpful? 0 Users Found This Useful (6 Votes)