Khi Linux kernel không còn free memory (và không thể swap), OOM (Out-of-Memory) Killer được kích hoạt để kill một process và giải phóng memory. Cách OOM Killer chọn victim: tính điểm oom_score cho mỗi process (0-1000) — dựa trên: RSS (physical memory dùng), swap usage, thời gian chạy (lâu hơn → điểm thấp hơn, less likely to kill), nice value.
Process có oom_score cao nhất bị kill. Bảo vệ process quan trọng:
# Giảm oom_score_adj → khó bị kill hơn
echo -1000 > /proc/$(pgrep redis-server)/oom_score_adj
# -1000 = không bao giờ bị kill (chỉ root)
# Xem score hiện tại
cat /proc/$(pgrep nginx)/oom_scoreKubernetes: oom_score_adj được set tự động theo QoS class: Guaranteed pods (-997), Burstable (2-999), BestEffort (1000 = bị kill đầu tiên). Best practices: set memory limits hợp lý trong K8s; monitor /proc/meminfo, MemAvailable; dùng cgroups memory.limit_in_bytes để limit per-container thay vì để OOM Killer action ở system level.
When the Linux kernel runs out of free memory (and cannot swap), the OOM (Out-of-Memory) Killer is triggered to kill a process and free memory. How the OOM Killer selects a victim: it calculates an oom_score (0–1000) for each process based on: RSS (physical memory in use), swap usage, runtime (longer-running processes get a lower score and are less likely to be killed), and the nice value.
The process with the highest oom_score is killed. Protecting important processes:
# Lower oom_score_adj → harder to kill
echo -1000 > /proc/$(pgrep redis-server)/oom_score_adj
# -1000 = never kill (root only)
# Check current score
cat /proc/$(pgrep nginx)/oom_scoreKubernetes: oom_score_adj is set automatically based on QoS class: Guaranteed pods (-997), Burstable (2–999), BestEffort (1000 = killed first). Best practices: set appropriate memory limits in K8s; monitor /proc/meminfo and MemAvailable; use cgroups memory.limit_in_bytes to limit per-container memory rather than letting the system-level OOM Killer act.