What is OOM Killer and how to manage it?
sobes.tech AI
Answer from AI
OOM Killer (Out-Of-Memory Killer) is a Linux kernel mechanism that activates when the system runs out of RAM. When available memory and swap are exhausted, the OOM Killer selects and terminates processes to free up memory and prevent the entire system from crashing.
Managing the OOM Killer:
-
Adjusting oom_score_adj: you can set priorities for processes to indicate which should be protected from termination and which can be terminated preferentially.
-
Monitoring memory usage: to prevent OOM activation, it is important to monitor memory consumption and optimize applications.
-
Using cgroups: allows limiting memory consumption for groups of processes, helping to avoid global OOM.
Example of changing oom_score_adj for a process:
# Get the process PID
pid=$(pidof my_process)
# Set oom_score_adj to -1000 (maximum protection)
echo -1000 | sudo tee /proc/$pid/oom_score_adj
Thus, the OOM Killer is a protective mechanism, but it is better to avoid situations where it activates.