Intermediate LevelLinux Commands & SysAdmin
How does the Linux OOM Killer select processes to terminate when RAM is exhausted?
❓ Interview Prompt: Explain Out-Of-Memory (OOM) Killer, memory exhaustion, oom_score calculation, oom_score_adj adjustment, and dmesg debugging.
When physical RAM and swap space are completely exhausted, the Linux kernel invokes the OOM Killer (Out-Of-Memory Killer) to avoid a full kernel panic:
Selection Algorithm ('oom_score'):
Calculates an 'oom_score' (0-1000) for every process based on RAM consumption percentage. The process with the highest score is terminated!
Adjusting Score ('oom_score_adj'):
Protect critical processes (e.g. database daemons) by setting 'echo -1000 > /proc/<PID>/oom_score_adj' to prevent OOM termination.
Code Implementation Example
bash
# Protect MySQL daemon (PID 1234) from being terminated by OOM Killer
echo -1000 | sudo tee /proc/1234/oom_score_adj
# Check system log for past OOM Killer termination events
sudo dmesg -T | grep -i oom💡Protecting critical processes from OOM Killer and checking kernel crash logs.
🎯 Interview Key Takeaway
Set oom_score_adj=-1000 on critical database processes to prevent the OOM Killer from terminating them during memory pressure.
#OOM Killer#oom_score#Memory Exhaustion#Intermediate
Back to all Linux Commands & SysAdmin Questions→