stat -fc %T /sys/fs/cgroup
stat -fc %T /sys/fs/cgroup
stat -fc %T /sys/fs/cgroup
ls /proc/pressure
ls /proc/pressure
ls /proc/pressure
cpu
io
memory
cpu
io
memory
cpu
io
memory
cat /proc/pressure/memory
cat /proc/pressure/memory
cat /proc/pressure/memory
some avg10=0.00 avg60=0.12 avg300=0.08 total=1234567
full avg10=0.00 avg60=0.05 avg300=0.02 total=345678
some avg10=0.00 avg60=0.12 avg300=0.08 total=1234567
full avg10=0.00 avg60=0.05 avg300=0.02 total=345678
some avg10=0.00 avg60=0.12 avg300=0.08 total=1234567
full avg10=0.00 avg60=0.05 avg300=0.02 total=345678
systemctl list-unit-files 'systemd-oomd*'
systemctl list-unit-files 'systemd-oomd*'
systemctl list-unit-files 'systemd-oomd*'
apt-cache policy systemd-oomd
apt-cache policy systemd-oomd
apt-cache policy systemd-oomd
sudo apt install systemd-oomd
sudo apt install systemd-oomd
sudo apt install systemd-oomd
sudo systemctl enable --now systemd-oomd.service
sudo systemctl enable --now systemd-oomd.service
sudo systemctl enable --now systemd-oomd.service
systemctl status systemd-oomd.service --no-pager
systemctl status systemd-oomd.service --no-pager
systemctl status systemd-oomd.service --no-pager
systemctl show --property=DefaultMemoryAccounting
systemctl show --property=DefaultMemoryAccounting
systemctl show --property=DefaultMemoryAccounting
sudo mkdir -p /etc/systemd/system.conf.d
sudo tee /etc/systemd/system.conf.d/60-memory-accounting.conf >/dev/null <<'EOF'
[Manager]
DefaultMemoryAccounting=yes
EOF
sudo mkdir -p /etc/systemd/system.conf.d
sudo tee /etc/systemd/system.conf.d/60-memory-accounting.conf >/dev/null <<'EOF'
[Manager]
DefaultMemoryAccounting=yes
EOF
sudo mkdir -p /etc/systemd/system.conf.d
sudo tee /etc/systemd/system.conf.d/60-memory-accounting.conf >/dev/null <<'EOF'
[Manager]
DefaultMemoryAccounting=yes
EOF
sudo systemctl daemon-reexec
sudo systemctl daemon-reexec
sudo systemctl daemon-reexec
systemctl show --property=DefaultMemoryAccounting
systemctl show --property=DefaultMemoryAccounting
systemctl show --property=DefaultMemoryAccounting
sudo systemctl edit system.slice
sudo systemctl edit system.slice
sudo systemctl edit system.slice
[Slice]
ManagedOOMMemoryPressure=kill
ManagedOOMMemoryPressureLimit=50%
ManagedOOMMemoryPressureDurationSec=20s
[Slice]
ManagedOOMMemoryPressure=kill
ManagedOOMMemoryPressureLimit=50%
ManagedOOMMemoryPressureDurationSec=20s
[Slice]
ManagedOOMMemoryPressure=kill
ManagedOOMMemoryPressureLimit=50%
ManagedOOMMemoryPressureDurationSec=20s
sudo mkdir -p /etc/systemd/system/system.slice.d
sudo tee /etc/systemd/system/system.slice.d/60-oomd.conf >/dev/null <<'EOF'
[Slice]
ManagedOOMMemoryPressure=kill
ManagedOOMMemoryPressureLimit=50%
ManagedOOMMemoryPressureDurationSec=20s
EOF
sudo mkdir -p /etc/systemd/system/system.slice.d
sudo tee /etc/systemd/system/system.slice.d/60-oomd.conf >/dev/null <<'EOF'
[Slice]
ManagedOOMMemoryPressure=kill
ManagedOOMMemoryPressureLimit=50%
ManagedOOMMemoryPressureDurationSec=20s
EOF
sudo mkdir -p /etc/systemd/system/system.slice.d
sudo tee /etc/systemd/system/system.slice.d/60-oomd.conf >/dev/null <<'EOF'
[Slice]
ManagedOOMMemoryPressure=kill
ManagedOOMMemoryPressureLimit=50%
ManagedOOMMemoryPressureDurationSec=20s
EOF
sudo systemctl daemon-reload
sudo systemctl daemon-reload
sudo systemctl daemon-reload
[Slice]
ManagedOOMSwap=kill
[Slice]
ManagedOOMSwap=kill
[Slice]
ManagedOOMSwap=kill
[Slice]
ManagedOOMMemoryPressure=kill
ManagedOOMMemoryPressureLimit=50%
ManagedOOMMemoryPressureDurationSec=20s
ManagedOOMSwap=kill
[Slice]
ManagedOOMMemoryPressure=kill
ManagedOOMMemoryPressureLimit=50%
ManagedOOMMemoryPressureDurationSec=20s
ManagedOOMSwap=kill
[Slice]
ManagedOOMMemoryPressure=kill
ManagedOOMMemoryPressureLimit=50%
ManagedOOMMemoryPressureDurationSec=20s
ManagedOOMSwap=kill
sudo systemctl edit nginx.service
sudo systemctl edit nginx.service
sudo systemctl edit nginx.service
[Service]
ManagedOOMPreference=omit
[Service]
ManagedOOMPreference=omit
[Service]
ManagedOOMPreference=omit
sudo systemctl edit ollama.service
sudo systemctl edit ollama.service
sudo systemctl edit ollama.service
[Service]
ManagedOOMPreference=avoid
[Service]
ManagedOOMPreference=avoid
[Service]
ManagedOOMPreference=avoid
man systemd.resource-control
man systemd.resource-control
man systemd.resource-control
oomctl dump
oomctl dump
oomctl dump
systemctl show system.slice \ --property=ManagedOOMMemoryPressure \ --property=ManagedOOMMemoryPressureLimit \ --property=ManagedOOMMemoryPressureDurationSec \ --property=ManagedOOMSwap
systemctl show system.slice \ --property=ManagedOOMMemoryPressure \ --property=ManagedOOMMemoryPressureLimit \ --property=ManagedOOMMemoryPressureDurationSec \ --property=ManagedOOMSwap
systemctl show system.slice \ --property=ManagedOOMMemoryPressure \ --property=ManagedOOMMemoryPressureLimit \ --property=ManagedOOMMemoryPressureDurationSec \ --property=ManagedOOMSwap
systemctl show ollama.service \ --property=ManagedOOMPreference \ --property=MemoryCurrent \ --property=MemoryPeak
systemctl show ollama.service \ --property=ManagedOOMPreference \ --property=MemoryCurrent \ --property=MemoryPeak
systemctl show ollama.service \ --property=ManagedOOMPreference \ --property=MemoryCurrent \ --property=MemoryPeak
journalctl -u systemd-oomd -f
journalctl -u systemd-oomd -f
journalctl -u systemd-oomd -f
watch -n 1 'cat /proc/pressure/memory'
watch -n 1 'cat /proc/pressure/memory'
watch -n 1 'cat /proc/pressure/memory'
sudo apt install stress-ng
sudo apt install stress-ng
sudo apt install stress-ng
systemd-run --unit=oomd-test --slice=system.slice \ stress-ng --vm 1 --vm-bytes 85% --vm-keep --timeout 2m
systemd-run --unit=oomd-test --slice=system.slice \ stress-ng --vm 1 --vm-bytes 85% --vm-keep --timeout 2m
systemd-run --unit=oomd-test --slice=system.slice \ stress-ng --vm 1 --vm-bytes 85% --vm-keep --timeout 2m
journalctl -u systemd-oomd -f
journalctl -u systemd-oomd -f
journalctl -u systemd-oomd -f
[Slice]
ManagedOOMMemoryPressure=kill
ManagedOOMMemoryPressureLimit=50%
ManagedOOMMemoryPressureDurationSec=20s
ManagedOOMSwap=kill
[Slice]
ManagedOOMMemoryPressure=kill
ManagedOOMMemoryPressureLimit=50%
ManagedOOMMemoryPressureDurationSec=20s
ManagedOOMSwap=kill
[Slice]
ManagedOOMMemoryPressure=kill
ManagedOOMMemoryPressureLimit=50%
ManagedOOMMemoryPressureDurationSec=20s
ManagedOOMSwap=kill
[Service]
ManagedOOMPreference=omit
[Service]
ManagedOOMPreference=omit
[Service]
ManagedOOMPreference=omit - what systemd-oomd actually does
- how to confirm your system can use it
- how to enable it safely
- how to apply policy at the right cgroup level
- how to inspect what it is monitoring
- how to test without guessing - you want a full unified cgroup hierarchy (cgroup v2)
- memory accounting should be enabled for monitored units
- the kernel needs PSI support
- having swap enabled is strongly recommended, because it gives systemd-oomd time to react before the system collapses into a livelock - SwapUsedLimit=90%
- DefaultMemoryPressureLimit=60%
- DefaultMemoryPressureDurationSec=30s - some means at least some tasks are stalled
- full means all non-idle tasks are stalled simultaneously - apply policy to a non-critical slice or lab machine
- watch PSI and oomctl
- create controlled memory pressure
- confirm the right descendant cgroup becomes the target
- tune the thresholds - enable systemd-oomd
- turn on default memory accounting
- apply pressure-based policy to system.slice
- reserve stricter preferences for clearly critical services
- leave room to tune thresholds after observing real pressure patterns - Do not treat systemd-oomd as a substitute for capacity planning.
- Do not skip swap and expect equally graceful behavior.
- Do not set one ultra-aggressive threshold globally without testing.
- Do not forget that cgroup structure matters. If everything lives in one giant bucket, targeting gets worse.
- Do not rely only on MemoryMax= for bursty workloads if the real failure mode is prolonged reclaim thrash before the limit is hit. - systemd-oomd.service(8): https://www.man7.org/linux/man-pages/man8/systemd-oomd.8.html
- oomd.conf(5): https://www.man7.org/linux/man-pages/man5/oomd.conf.5.html
- systemd.resource-control(5): https://man7.org/linux/man-pages/man5/systemd.resource-control.5.html
- Linux kernel PSI documentation: https://docs.kernel.org/accounting/psi.html
- oomctl(1) reference index: https://www.freedesktop.org/software/systemd/man/latest/oomctl.html