Lesson 2.50: Memory limits and the OOM killer
When a Linux machine runs out of memory, the kernel's OOM killer ends a process to save the rest, and it picks by size, not by guilt. Control groups (cgroups v2) let you give every service its own memory and CPU budget, so a leak hurts only the leaker. In the lab Northwind's image resizer leaked memory overnight and the kernel killed the database instead. You read the kernel's report, see the service's cgroup, cap the resizer with systemctl set-property, and make the database the last thing the OOM killer chooses.
18 min
You will learn to
- Read OOM killer messages in the kernel log
- Explain how cgroups v2 limit a service
- Read memory.current, memory.max and memory.events
- Set MemoryHigh and MemoryMax with systemctl set-property
- Protect a critical service with OOMScoreAdjust
Key terms
- cgroup (control group)
- A kernel group of processes that shares limits and accounting for memory, CPU, I/O and process count.
- memory.high
- Soft limit: above it the kernel reclaims memory hard and slows the group down.
- memory.max
- Hard limit: the group can't go above it; if it can't reclaim, the OOM killer acts inside the group.
- OOM killer
- The kernel routine that ends a process when memory runs out, choosing by a badness score.
- oom_score_adj
- A per-process adjustment from -1000 (never kill) to +1000 (kill first).
- systemctl set-property
- Changes a unit's resource settings at runtime and saves them as drop-ins.
← logrotate: keeping logs from filling the disk · All lessons · Auditing every program a person runs →