The Linux OOM Killer: Why It Fired and How to Prevent It
The kernel killed your process to save the box, and the log looks like noise until you know exactly which fields to read.
Key takeaways
- The OOM killer fires when the kernel cannot reclaim memory and must SIGKILL a process to keep the system alive.
- Run dmesg -T | grep -i oom to see the victim. "Out of memory" means the host is exhausted; "Memory cgroup out of memory" means a container or systemd unit hit its own memory.max limit.
On this page
When a process vanishes with no shutdown log, run dmesg -T | grep -i -E 'out of memory|oom-kill'. A line reading Out of memory: Killed process means the whole host ran out of RAM; Memory cgroup out of memory means a container or systemd unit hit its own memory.max. Fix the leak or the limit, then protect critical daemons.
Verified against
Linux kernel 7.3 (cgroup v2 and overcommit-accounting docs), Linux man-pages 6.19 proc_pid_oom_score_adj(5), and systemd 262 systemd.resource-control(5) and systemd.exec(5). Checked October 2026.
Why the kernel kills instead of failing
Linux overcommits memory on purpose. Processes reserve far more than they touch, so the kernel hands out virtual mappings freely and backs them with physical pages only on first write. The default, vm.overcommit_memory=0, is a heuristic that refuses only obvious overcommits.
When real usage climbs and the kernel needs a page it does not have, it first reclaims: drop clean page cache, write back dirty pages, swap out anonymous memory. The OOM killer runs only when reclaim fails. At that point there is no allocation to refuse, because the memory was promised long ago, so the kernel picks a victim and sends SIGKILL. No signal handler runs, which is why the application logs nothing.
Read the evidence in under a minute
The record lands in the kernel ring buffer and the journal:
# Kernel messages with wall-clock timestamps
$ sudo dmesg -T | grep -i -E 'out of memory|oom-kill|killed process'
# Same from the journal, survives reboots if persistent journaling is on
$ journalctl -k --since "-2h" | grep -i -E 'out of memory|oom-kill'
# Which systemd units lost a process to it
$ journalctl --since "-2h" | grep -i "oom"
A trimmed global OOM event looks like this:
[Tue Jul 21 03:14:22 2026] node invoked oom-killer: gfp_mask=0x140cca(GFP_HIGHUSER_MOVABLE|__GFP_COMP), order=0, oom_score_adj=0
[Tue Jul 21 03:14:22 2026] Mem-Info:
[Tue Jul 21 03:14:22 2026] [ pid ] uid tgid total_vm rss ... oom_score_adj name
[Tue Jul 21 03:14:22 2026] [ 1187] 1000 1187 1284410 961242 ... 0 node
[Tue Jul 21 03:14:22 2026] [ 902] 0 902 214880 4102 ... 0 sshd
[Tue Jul 21 03:14:22 2026] oom-kill:constraint=CONSTRAINT_NONE,nodemask=(null),cpuset=/,mems_allowed=0,global_oom,task_memcg=/user.slice,task=node,pid=1187,uid=1000
[Tue Jul 21 03:14:22 2026] Out of memory: Killed process 1187 (node) total-vm:5137640kB, anon-rss:3844968kB, file-rss:0kB, shmem-rss:0kB
Read it top to bottom. The first line names who triggered reclaim, which is not always the victim. The task table lists every candidate with rss (resident pages, in 4 KiB pages) and oom_score_adj. The oom-kill: line gives the constraint: CONSTRAINT_NONE with global_oom is a host-wide shortage, CONSTRAINT_MEMCG is a cgroup limit. The last line names the victim and its anon-rss, here about 3.7 GiB. To catch the growth before the next kill, see find what's using your memory.
How the victim is chosen
The kernel scores every eligible task and kills the highest. Per proc_pid_oom_score_adj(5), the badness score runs from 0 to 1000 and is roughly the proportion of allowed memory a task uses: a process using half of RAM scores about 500. Resident memory and swap count, not virtual size, which is why total_vm is a red herring.
You bias the score with oom_score_adj, from -1000 to +1000:
$ cat /proc/1187/oom_score # current badness
$ cat /proc/1187/oom_score_adj # your adjustment, default 0
$ echo -500 | sudo tee /proc/1187/oom_score_adj # protect, but do not exempt
-1000 makes a task unkillable. Protect a database that way and the kernel may kill sshd instead, locking you out of a thrashing box. Bias, do not exempt. Writes to /proc vanish on restart, so set it persistently in the unit:
# /etc/systemd/system/postgresql.service.d/oom.conf
[Service]
OOMScoreAdjust=-500
MemoryHigh=6G
MemoryMax=7G
$ sudo systemctl daemon-reload && sudo systemctl restart postgresql
$ systemctl show postgresql -p OOMScoreAdjust -p MemoryMax
OOMScoreAdjust=-500
MemoryMax=7516192768
systemd's docs recommend MemoryHigh= as the main control (it throttles and forces reclaim) and MemoryMax= as the last line of defense, where the OOM killer is invoked inside the unit.
Global OOM versus cgroup OOM
This is the distinction that sends people down the wrong path.
Global OOM: the host is out of memory. Every process on the box is a candidate. Fixes live at the host level: more RAM, swap, fewer co-located workloads, or the leaking process.
Cgroup OOM: a single cgroup hit memory.max while the host has plenty free. The kernel docs say that when usage "reaches this limit and can't be reduced, the OOM killer is invoked in the cgroup." Only tasks in that cgroup are candidates:
[Tue Jul 21 09:41:08 2026] Memory cgroup out of memory: Killed process 44120 (python) total-vm:912344kB, anon-rss:519012kB, file-rss:0kB, shmem-rss:0kB
Confirm it from the cgroup itself, which keeps counters:
$ cat /sys/fs/cgroup/system.slice/myapp.service/memory.max
536870912
$ cat /sys/fs/cgroup/system.slice/myapp.service/memory.events
low 0
high 0
max 219
oom 3
oom_kill 3
oom_kill counts processes killed in that cgroup. This is the same mechanism behind Kubernetes OOMKilled and Docker exit 137: limits doing what you told them. Do not touch host swap for a cgroup OOM; raise the limit or fix the leak inside the unit.
Overcommit and swap: the host-level knobs
Mode 2 turns surprise kills into honest allocation failures. The commit limit becomes swap plus vm.overcommit_ratio percent of RAM (default 50):
$ sysctl vm.overcommit_memory vm.overcommit_ratio
vm.overcommit_memory = 0
vm.overcommit_ratio = 50
$ grep -E 'CommitLimit|Committed_AS' /proc/meminfo
$ sudo sysctl -w vm.overcommit_memory=2 vm.overcommit_ratio=80
Check Committed_AS against the new CommitLimit first. If committed memory already exceeds it, new allocations start failing immediately, including in sshd and your shell. Persist the change in /etc/sysctl.d/90-overcommit.conf only after a soak.
Swap gives reclaim somewhere to push cold anonymous pages. It trades kills for latency, so size it deliberately. For earlier, policy-driven kills, systemd-oomd watches pressure and kills a whole cgroup before the kernel has to; enable it per unit with ManagedOOMMemoryPressure=kill.
Failure modes and the exact strings
Killedprinted by your shell, exit code137(128 + SIGKILL 9): the OOM killer, or an externalkill -9. Checkdmesgto tell which.Out of memory: Killed process <pid> (<name>): global OOM. Look at the biggestrssin the task table.Memory cgroup out of memory: Killed process: cgroup limit. Read that cgroup'smemory.eventsandmemory.max.Failed with result 'oom-kill'insystemctl status: a unit lost a process to the OOM killer.OOMPolicy=decides whether systemd stops the unit, kills it, or continues.Cannot allocate memory(ENOMEM) fromforkormallocafter settingvm.overcommit_memory=2: the commit limit is too low. Raisevm.overcommit_ratioor add swap.dmesg: read kernel buffer failed: Operation not permitted:kernel.dmesg_restrictis on. Usesudo dmesgorjournalctl -k.
If dmesg has rotated past the event, the journal still has it when journaling is persistent; our guide to journald log management covers turning that on.
Where this breaks
None of this fixes a leak. A process whose RSS only climbs will find any limit you set, so the OOM kill is the symptom. oom_score_adj is ignored for a cgroup with memory.oom.group=1, which kills all its tasks together (except those at -1000). Kernel threads and init are never candidates. And on hosts running memory-heavy JVMs or databases with their own allocators, tune the application's heap or buffer settings first; kernel knobs only decide who dies.
Questions people ask
How do I check if the OOM killer killed my process?
Run sudo dmesg -T | grep -i -E 'out of memory|oom-kill' or journalctl -k | grep -i oom. A matching Killed process <pid> (<name>) line confirms it and names the victim. For systemd services, systemctl status <unit> shows oom-kill as the result. For containers, read memory.events in the cgroup directory; a nonzero oom_kill counter means the kernel killed processes there.
How do I stop the OOM killer from killing a specific process?
Lower its oom_score_adj, persistently through OOMScoreAdjust= in the systemd unit, for example -500. Values reach -1000, which makes the process unkillable, but that risks the kernel killing sshd or monitoring instead. Better still, cap the noisy neighbours with MemoryHigh= and MemoryMax= so the shortage lands on a workload that is safe to restart.
What is the difference between OOM killer and OOMKilled in Kubernetes?
They are the same kernel mechanism. Kubernetes sets each container's memory limit as a cgroup memory.max; when the container exceeds it, the kernel's cgroup OOM killer kills a process inside, and the kubelet reports OOMKilled with exit code 137. A node-wide shortage is a global OOM, which the kubelet tries to prevent earlier by evicting pods under memory pressure.
The call we'd make
When a process disappears without a trace, run dmesg -T | grep -i oom before anything else, and let the first word decide the path. Out of memory alone means the host is exhausted: find the biggest RSS, then look at swap and overcommit. Memory cgroup out of memory means a unit hit its own cap: read memory.events, then fix the limit or the leak. Then set MemoryHigh and MemoryMax from measured peaks and give sshd and your monitoring agent a modest negative OOMScoreAdjust, so the next shortage kills something restartable instead of your way in. For the wider playbook, keep the Linux troubleshooting guide handy.
Sources
Cite this article
Kiril Urbonas (2026). The Linux OOM Killer: Why It Fired and How to Prevent It. DevOpsNess. Updated 2026-10-31. https://www.devopsness.com/blog/fix-out-of-memory-linux
[The Linux OOM Killer: Why It Fired and How to Prevent It](https://www.devopsness.com/blog/fix-out-of-memory-linux) (Kiril Urbonas, DevOpsNess, updated 2026-10-31)
More from Linux
Explore more articles in this category
CVE-2026-98432: The CVSS 9.8 Linux TCP Bug Now Has an Exploit. Patched Node Images
A use-after-free in the IPv4 TCP handshake, present since Linux 4.4, now has a working exploit against MPTCP listeners, and every Go 1.24+ server is one by default. Which kernels are fixed and how to roll them through EKS, GKE and AKS.
CERN Left Red Hat for Debian: The CPU Baseline Lesson
CERN is moving accelerator control computers to Debian because RHEL raised its minimum CPU level. Check your own fleet's x86-64-vN support before the next OS upgrade does it for you.
ext4 vs XFS vs Btrfs: Choosing a Filesystem for a Server
The default filesystem your distro picks is not always the right one for your workload. Here is what actually differs and when each one wins.
You might have missed
Evergreen posts worth revisiting.