Skip to content

oom_score_adj

Linux systems use the oom_score_adj parameter to influence which processes are selected for termination during an out-of-memory (OOM) condition. This value ranges from -1000 (highest priority, least likely to be killed) to 1000 (lowest priority, most likely to be killed). By strategically adjusting oom_score_adj for critical processes, administrators can reduce the risk of service disruptions during memory exhaustion. This section explains how to modify these values for process prioritization.


Understanding oom_score_adj Behavior

The OOM killer evaluates processes based on their oom_score_adj value, along with other factors like memory usage and runtime. Lower values (e.g., -500) indicate higher priority, while higher values (e.g., +500) signal lower priority. The default value is 0 for most processes.

Important:
- oom_score_adj is a temporary setting unless applied via persistent configuration (e.g., systemd or init scripts).
- Some services (e.g., Docker, systemd) may have predefined defaults that override manual adjustments.


Adjusting oom_score_adj for Specific Processes

1. Temporary Adjustment (Runtime Only)

Use echo to set the value for a specific process ID (PID):

sudo echo -n <value> > /proc/<PID>/oom_score_adj
- Replace <value> with a number between -1000 and 1000.
- Example: Prioritize a critical service with PID 1234:
sudo echo -n -500 > /proc/1234/oom_score_adj

2. Persistent Adjustment via Systemd

Edit the .service file for the target process to set OOMScoreAdj:

[Service]
OOMScoreAdj=-500
- Place the file in /etc/systemd/system/<service-name>.service and reload systemd:
sudo systemctl daemon-reload
sudo systemctl restart <service-name>


Best Practices for Prioritization

  • Avoid Over-Prioritization: Setting values too low (e.g., < -500) may prevent critical processes from being killed but could destabilize the system if memory is exhausted.
  • Use Systemd for Consistency: Prefer systemd configuration over ad-hoc echo commands for reliability.
  • Monitor and Test: After adjustments, use tools like htop or ps to verify oom_score_adj values and simulate OOM conditions in a safe environment.

Key Takeaways

  • oom_score_adj adjusts process priority during OOM events.
  • Temporary changes apply via /proc/<PID>/oom_score_adj; persistent changes require systemd or init scripts.
  • Prioritize critical services (e.g., databases, web servers) with negative values but balance this with system stability.
  • Always test adjustments in non-production environments to avoid unintended side effects.