By the time the kernel OOM killer runs, the machine has already been unusable for a while — reclaim has been thrashing, latency has collapsed, and the kernel finally picks a victim by oom_score, which is frequently the largest process rather than the one causing the problem. systemd-oomd sits above that: it watches Pressure Stall Information (PSI) per cgroup, and when a slice stays above a memory-pressure threshold for a configured duration, it kills the worst descendant cgroup outright. The important detail is that it is strictly opt-in — a cgroup is only monitored if ManagedOOMMemoryPressure=kill or ManagedOOMSwap=kill is set on it — so on most servers systemd-oomd is running and doing precisely nothing. This guide covers the mechanism, the settings that matter, how to prove the policy fires, and where it does not help at all.
What you’ll accomplish
- Confirm PSI, cgroup v2, and swap accounting are actually available on the host instead of assuming they are.
- Opt a slice into pressure-based eviction and set a threshold that fires before the machine becomes unresponsive.
- Protect the services that must never be the victim with
ManagedOOMPreference=avoidandomit. - Read an oomd kill decision out of the journal and correlate it with
oomctlstate. - Tell the difference between a policy problem oomd can fix and a memory leak it cannot.
Prerequisites
- cgroup v2, unified hierarchy.
systemd-oomdrefuses to work on cgroup v1 or hybrid. Every current distribution defaults to unified, but hosts that were pinned withsystemd.unified_cgroup_hierarchy=0for an old container runtime are still out there. - PSI enabled in the running kernel.
CONFIG_PSI=yis not enough. Debian and Red Hat family kernels commonly shipCONFIG_PSI_DEFAULT_DISABLED=y, which means PSI is compiled in but inert until you addpsi=1to the kernel command line. Ubuntu and Fedora enable it by default. The only reliable check is reading/proc/pressure/memory. - systemd 247 or newer for
systemd-oomdat all, 249 or newer forManagedOOMPreference=. Treat 250 as the practical floor; the earliest releases had rough edges in candidate selection. - Swap, if you want the swap policy.
ManagedOOMSwap=killandSwapUsedLimit=are evaluated against system-wide swap usage. On a swapless server that path is permanently inert — not misconfigured, just never triggered. - Distribution differences are real. Fedora enables
systemd-oomdand ships drop-ins that setManagedOOMMemoryPressure=killonuser.slicewith a tightened limit onuser@.service. Ubuntu 22.04 and later do something similar for the desktop session. Debian ships the binary but does not enable the service or set any opt-in. RHEL 9 ships it disabled. Read your own config rather than trusting a blog post about a different distribution.
How it works
PSI exposes, per cgroup and system-wide, how much wall-clock time tasks spent stalled waiting on memory. /proc/pressure/memory and each cgroup’s memory.pressure file give some and full lines with avg10, avg60, and avg300 percentages. some means at least one task was stalled; full means every runnable task was stalled, which is the number that correlates with a machine that has stopped answering.
systemd-oomd polls the memory.pressure of every cgroup that opted in. When a cgroup’s pressure stays above its limit for longer than the configured duration — and the kernel shows actual reclaim activity, so it does not fire on pressure caused by something other than memory reclaim — oomd selects a descendant cgroup and kills it.
Three consequences follow from that design and each one surprises somebody:
It kills a whole cgroup, not a PID. Every process in the selected unit or scope gets SIGKILL. For a service that is usually what you want — a half-killed service is worse than a stopped one. For a user session it means the login shell and everything under it can go together.
It only sees cgroups that opted in. Setting ManagedOOMMemoryPressure=kill on a slice tells oomd to watch that slice’s pressure and, when it fires, to choose among that slice’s children. Nothing outside the opted-in subtree is ever a candidate.
It is a policy layer, not a limit. MemoryMax= is a hard ceiling enforced by the kernel inside the cgroup; exceeding it triggers cgroup-local OOM. MemoryHigh= is a throttling threshold that forces reclaim. Those bound a single unit’s consumption. oomd does something different: it decides, across a set of units, which one to sacrifice when the aggregate is in trouble. The three compose well — MemoryHigh= to make a greedy unit generate pressure inside its own cgroup, MemoryMax= as the hard stop, oomd as the arbiter when the slice as a whole degrades. For the underlying controls see cgroup v2 resource control, and for what the kernel does when nothing above it intervened, Linux OOM killer behaviour.
Step-by-step
1. Verify PSI is live. No output here means everything else in this guide is decorative.
cat /proc/pressure/memory
some avg10=0.00 avg60=0.00 avg300=0.00 total=1043528
full avg10=0.00 avg60=0.00 avg300=0.00 total=612104
If the file does not exist, add psi=1 to the kernel command line and reboot.
2. Confirm the unified hierarchy.
stat -fc %T /sys/fs/cgroup
cgroup2fs
Anything else (tmpfs, cgroupfs) means cgroup v1 or hybrid, and oomd will not start.
3. Check the service and its effective configuration. Do not read /etc/systemd/oomd.conf alone; drop-ins from the distribution package usually override it.
systemctl status systemd-oomd --no-pager
systemd-analyze cat-config systemd/oomd.conf
● systemd-oomd.service - Userspace Out-Of-Memory (OOM) Killer
Loaded: loaded (/usr/lib/systemd/system/systemd-oomd.service; enabled)
Active: active (running) since Wed 2026-07-22 09:14:03 EDT
[OOM]
#SwapUsedLimit=90%
#DefaultMemoryPressureLimit=60%
#DefaultMemoryPressureDurationSec=30s
Commented lines are the compiled-in defaults. If your distribution ships an uncommented value in a drop-in, cat-config shows it after the main file.
4. Set the global defaults you want. These apply to any monitored cgroup that does not override them.
sudo mkdir -p /etc/systemd/oomd.conf.d
sudo tee /etc/systemd/oomd.conf.d/50-limits.conf >/dev/null <<'EOF'
[OOM]
DefaultMemoryPressureLimit=55%
DefaultMemoryPressureDurationSec=20s
SwapUsedLimit=90%
EOF
sudo systemctl restart systemd-oomd
systemctl is-active systemd-oomd
active
DefaultMemoryPressureDurationSec= is what keeps a short allocation burst from being treated as an emergency — lowering it below about 10 seconds makes oomd twitchy on any host with bursty batch work.
5. Opt a slice in. This is the step everyone forgets. Nothing is monitored until you do it.
sudo systemctl set-property system.slice ManagedOOMMemoryPressure=kill
systemctl show system.slice -p ManagedOOMMemoryPressure
ManagedOOMMemoryPressure=kill
set-property writes a drop-in under /etc/systemd/system.control/ and applies it immediately. To make it a reviewable file instead, write the drop-in yourself:
# /etc/systemd/system/system.slice.d/10-oomd.conf
[Slice]
ManagedOOMMemoryPressure=kill
ManagedOOMMemoryPressureLimit=50%
ManagedOOMMemoryPressureLimit= overrides DefaultMemoryPressureLimit= for this cgroup only. Reload after editing a file by hand:
sudo systemctl daemon-reload
oomctl | grep -A2 'system.slice'
/system.slice
Memory Pressure Limit: 50.00%
Pressure: Avg10: 0.00 Avg60: 0.00 Avg300: 0.00 Total: 3s
If the slice does not appear in that output at all, oomd has not picked up the opt-in and nothing below will fire.
6. Rank the candidates. Within a monitored slice, mark what must survive and what must never be touched.
sudo systemctl set-property postgresql.service ManagedOOMPreference=avoid
sudo systemctl set-property telemetry.service ManagedOOMPreference=omit
systemctl show postgresql.service telemetry.service -p ManagedOOMPreference
ManagedOOMPreference=avoid
ManagedOOMPreference=omit
avoid moves a unit to the back of the candidate list; oomd only picks it if nothing else qualifies. omit removes it from consideration entirely. Use omit sparingly — a unit that can never be killed is a unit that can hold the whole slice hostage. Note also that MemoryMin= and MemoryLow= on a unit reduce the memory oomd counts against it, so a heavily protected unit is naturally a weaker candidate.
7. Enable the swap policy only if you have swap.
sudo systemctl set-property -.slice ManagedOOMSwap=kill
swapon --show
NAME TYPE SIZE USED PRIO
/swapfile file 8G 1.2G -2
Empty output from swapon --show means no swap, and ManagedOOMSwap=kill will sit there doing nothing forever. That is not a bug to chase.
Validate it works
Start with oomd’s own view of the world. oomctl dumps the live state, which is the fastest way to confirm your opt-in actually registered:
oomctl
Dry Run: no
Swap Used Limit: 90.00%
Default Memory Pressure Limit: 55.00%
Default Memory Pressure Duration: 20s
System Context:
Memory: Used: 21.4G Total: 62.7G
Swap: Used: 1.2G Total: 8.0G
Swap Monitored CGroups:
/
Memory Pressure Monitored CGroups:
/system.slice
Memory Pressure Limit: 50.00%
Pressure: Avg10: 0.00 Avg60: 0.00 Avg300: 0.00 Total: 3s
Current Memory Usage: 9.8G
Memory Min: 0B
Memory Low: 0B
Swap Usage: 0B
An empty “Memory Pressure Monitored CGroups” section means the opt-in did not take. Now force a decision with a disposable slice. Install stress-ng first if it is not present:
sudo systemctl set-property canary.slice ManagedOOMMemoryPressure=kill ManagedOOMMemoryPressureLimit=20%
sudo systemd-run --slice=canary.slice --unit=canary-hog -p MemoryHigh=200M \
stress-ng --vm 4 --vm-bytes 512M --timeout 180
Running as unit: canary-hog.service
MemoryHigh=200M forces continuous reclaim inside the hog’s cgroup, which drives canary.slice pressure up without endangering the rest of the host. Watch the decision arrive:
journalctl -u systemd-oomd -f
systemd-oomd[812]: Killed /canary.slice/canary-hog.service due to memory pressure for /canary.slice being 34.21% > 20.00% for > 20s with reclaim activity
That single line contains everything: which cgroup died, which monitored cgroup’s pressure triggered it, the measured value against the limit, the duration, and the reclaim-activity confirmation. Clean up when you are done:
sudo systemctl revert canary.slice
Removed "/etc/systemd/system.control/canary.slice.d/50-ManagedOOMMemoryPressure.conf".
For live observation while a test runs, systemd-cgtop -m --order=memory sorts cgroups by memory so you can watch the candidate emerge before oomd acts on it.
Troubleshooting
oomd never fires, even under obvious pressure. In order of likelihood: no cgroup opted in (check oomctl for an empty monitored list); PSI is compiled out or disabled at boot (/proc/pressure/memory missing); the pressure spikes but does not stay above the limit for the full DurationSec; or the pressure is not accompanied by reclaim activity, which oomd requires before it will act. The last one is common on hosts with a large page cache — the cache absorbs the pressure and reclaim stays cheap, so the full average never climbs.
oomd kills the wrong cgroup. Candidate selection is mechanical: the descendant with the most reclaim activity, or the most swap usage for the swap policy. A unit that behaves correctly but simply touches a lot of memory will out-score a leaking unit that has already exhausted its own cgroup limit. Fix it with ManagedOOMPreference=avoid on the units you want spared, and by putting a MemoryHigh= on the suspect so its own cgroup generates the pressure rather than the shared slice. Setting ManagedOOMMemoryPressure=kill on a narrower slice also helps — the smaller the monitored subtree, the fewer wrong answers are reachable.
Swap policy is configured and never triggers. On a swapless host it never will. SwapUsedLimit= is evaluated against total system swap; with zero swap the ratio is undefined and the check is skipped. Either accept that pressure monitoring is your only lever, or add swap so that reclaim has somewhere to go before it becomes a stall.
/proc/pressure/memory exists but per-cgroup memory.pressure does not. That is cgroup v1, or a cgroup created before memory accounting was enabled. Confirm with stat -fc %T /sys/fs/cgroup, and check that MemoryAccounting=yes is in effect — it is the default under systemd on cgroup v2, but an explicit MemoryAccounting=no in a unit file disables it.
A user’s whole session disappears. With ManagedOOMMemoryPressure=kill on user.slice, the candidate is a child of user.slice — which is user-1000.slice, the entire session. Push the opt-in one level down onto user@1000.service instead, so the candidates are individual app scopes rather than the whole login.
oomd starts, then exits. Check the journal for a cgroup v2 complaint. systemd-oomd has ConditionControlGroupController=v2 and simply skips on a hybrid hierarchy, which looks like a silent failure if you only glance at systemctl is-active.
When this is the wrong approach
- You have a memory leak. oomd shortens the outage and makes it land on the right process; it does not stop the leak from recurring every few hours. Treat a repeating oomd kill as a bug report, not a resolution.
- A single service owns the box. With one workload on the host, there is no candidate selection to make.
MemoryMax=plus a restart policy is a more direct answer than a pressure watcher that can only ever choose the one thing running. - The workload cannot tolerate a hard kill. oomd sends
SIGKILLto the whole cgroup with no graceful stop. Databases and queue consumers that need an orderly shutdown are better served byMemoryHigh=back-pressure and their own health checks. - Kubernetes nodes. The kubelet has its own eviction manager with its own thresholds, and it expects to be the component deciding which pod dies. Running oomd on top of pod cgroups produces two authorities disagreeing about the same memory.
- You need a per-process decision. If the right answer is truly “kill this one PID and leave its siblings alone,” oomd is the wrong tool — it has no per-PID mode. Tune
oom_score_adjand let the kernel path handle it.
The authoritative references are the systemd-oomd.service manual page and the kernel’s PSI documentation, which defines exactly what some and full measure.
If this is the kind of work you’d rather never own again, it’s the daily job of Managed Cloud Ops — book an infrastructure review.