Skip to content

Troubleshooting guide

Linux OOM killer: why it killed your process

When Linux runs out of memory it picks a process and kills it. The kernel log records exactly what happened, and the victim is not always the culprit.

3 min read10 sectionsUpdated

On this page

Key points

  • The kernel log names the victim and prints a memory table.
  • The victim may be innocent; it is merely the biggest target.
  • Page cache in free is reclaimable, so read available.
  • oom_score_adj protects important processes.

What happens

Linux overcommits memory: programs may allocate more than exists. When memory is truly needed and cannot be reclaimed, the OOM killer scores processes, chiefly by memory use, and sends SIGKILL to the top one. Your app just vanishes, with no stack trace and no error of its own.

Common causes

  • A memory leak that grows until the host is exhausted.
  • A traffic spike multiplying workers, each with its own memory.
  • Cgroup limits, where an OOM kill occurs although the host has plenty free.
  • Large database caches configured too high for the host.
  • No swap at all on a host with sharp spikes.

Diagnose it

The kernel log tells you whether the kill was global or in a cgroup, and what was using memory.

bash
# What was killed, and why
journalctl -k --since "2 hours ago" | grep -iE 'out of memory|oom-kill|killed process'

# Memory right now: "available" is the useful column
free -m

# Biggest consumers
ps -eo pid,rss,cmd --sort=-rss | head -10

# Score the kernel would use for a process
cat /proc/$(pgrep -o nginx)/oom_score

Fixes

Fix the source: profile leaks, cap worker counts by available memory, and size caches to leave headroom. Protect essential services in systemd using OOMScoreAdjust=-500, though nothing should run at -1000 unless you are sure. Set MemoryMax= on less important services so they fail first. A small amount of swap can absorb short spikes. On a large fleet, systemd-oomd can act earlier.

Reading the log

The oom-kill line includes the constraint: CONSTRAINT_MEMCG means a cgroup limit, and CONSTRAINT_NONE means the host ran out.

Catch it automatically

Alert on any OOM kill: these are always worth seeing. Track "available" memory per host, and restarts per service in infrastructure monitoring. A slow upward line in the days before a kill means a leak, and APM connects it to a release.

Frequently asked questions

Why was my database killed when another app leaked?

The OOM killer prefers large processes, and databases are often the largest.

Is free memory near zero a problem?

No. Linux uses spare memory as cache. Look at the available column instead.

Should I disable overcommit?

Usually not. It can make allocations fail in programs that do not expect it.

Watch your own site and services with VitalRix

Uptime checks, APM, logs, real-user monitoring, alerts and status pages in one place. Every product has a free tier and no credit card is needed.