linuxlab.io
Tutorials▾
  • Linux & networking
    File system, processes, TCP/IP, BGP and OSPF
    →
  • Terraform & IaC
    HCL, state, plan/apply on a LocalStack sandbox
    →
  • Git & GitHub
    Object model, plumbing, branching, GitHub Actions
    →
All tutorials →
PricingAboutSign inCreate account
/
  • Introduction
  • Lessons
  • How it works
  • Simulator
  • Knowledge base
  • Interview prep
Index
Categories
All entries
Footer
linuxlab-TutorialsPricingAboutPrivacy & cookies
Copyright © 2026 LinuxLab. All rights reserved.
home/linux/kb/Processes & resources/oom-killer

kb/processes ── Processes & resources ── advanced

OOM killer

OOM killer is the kernel mechanism that picks and terminates a process when the system hits its memory limit. In containers it works per-cgroup.

view as markdownaka: oom, out-of-memory

When it fires

Linux usually overcommits memory. If every process asked for all the memory it claimed at once, there would not be enough physical pages. As long as nobody actively uses it, things work. Once you hit the wall:

  • on the host: the kernel runs the global OOM killer
  • in a container or a cgroup with memory.max: a cgroup OOM runs and kills only within that cgroup

The alternative is a full kernel panic, but that is the last resort.

How the victim is chosen

Each process gets an oom_score (0..1000) based on:

  • how much RAM it ate (the main factor)
  • oom_score_adj, a manual adjustment (-1000 = immune, +1000 = killed first)
  • root processes get a small penalty (a few percent off)

Files:

bash
cat /proc/<pid>/oom_score        # current final score
cat /proc/<pid>/oom_score_adj    # manual adjustment

How to protect a critical process

bash
echo -1000 | sudo tee /proc/$(pidof sshd)/oom_score_adj

▸now sshd will never be an OOM victim

In a systemd unit, the same thing through OOMScoreAdjust=-1000.

OOM in cgroups v2

In v2 the option memory.oom.group = 1 changes the behavior: on OOM it kills not the single "worst" process but the whole cgroup. This is critical for applications where losing one worker breaks the rest (the Kubernetes use case).

Signs that an OOM happened

bash
dmesg | grep -i 'killed process'
journalctl -k | grep -i oom
# Mar 14 12:34:56 host kernel: Out of memory: Killed process 1234 (chrome) ...

In a container, docker inspect shows:

bash
docker inspect <container> --format '{{.State.OOMKilled}}'
# true → the container was killed by OOM, it did not exit on its own

The main causes of OOM in production:

  1. Memory leak in the application (Java/Node with no heap limit, growing right up to the server's RAM)
  2. Too tight a limit in k8s. The application works but does not fit the limit at peaks; the fix is raising request/limit or vertical autoscaling
  3. A large ALLOCATION in one operation (reading a huge file whole)

§ команды

bash
cat /proc/$$/oom_score

OOM score of the current process (higher = more likely to be killed)

bash
echo -500 | sudo tee /proc/$$/oom_score_adj

Lower the chance that the current process becomes an OOM victim

bash
dmesg -T | grep -i 'killed process'

History of OOM kills with human-readable timestamps

bash
cat /sys/fs/cgroup/memory.events

low/high/max/oom counters for the current cgroup

bash
cat /sys/fs/cgroup/memory.oom.group

If 1, OOM kills the whole cgroup, not a single process

§ см. также

  • process-and-pidProcess and PIDA process is a running program with its own PID, memory, open descriptors, and UID. Every process forms a tree rooted at init (PID 1).
  • signalsSignals (SIGTERM, SIGKILL, SIGHUP)A signal is an asynchronous notification to a process from the kernel or another process. TERM asks it to quit, KILL kills it now, HUP reloads config.
  • cgroupscgroups (v2)cgroups v2 is a hierarchical virtual FS under `/sys/fs/cgroup` that the kernel uses to limit CPU, memory, and I/O for processes. Docker, k8s, and systemd write here.
  • cgroups-v2-deepcgroups v2: unified hierarchy, PSI, eBPF controlcgroups v2 uses one tree instead of separate per-controller hierarchies. Clean semantics, new fields (memory.high, io.cost). PSI shows resource pressure. eBPF can manage resources. Default in RHEL 9, Ubuntu 22+.
  • cmd-sysctlsysctl: kernel tunables`sysctl` reads and writes kernel parameters through the virtual filesystem `/proc/sys/`. Network, memory, and filesystem tuning all go through these knobs.
  • kubelet-internalskubelet: the Kubernetes node agent architecturekubelet is a daemon on every node. It receives the PodSpec through the API, starts containers through CRI, mounts volumes through CSI, and watches health. Under pressure it does eviction. Image GC and the cgroup tree are also its job.

§ упоминается в уроках

  • ›advanced-02-cgroups-v2
Footer
linuxlab-
Copyright © 2026 LinuxLab. All rights reserved.
Tutorials
Pricing
About
Privacy & cookies