← All benchmarksLinux

systemd MemoryMax: OOM-kill a runaway process without taking down the host

How do I stop a memory leak from taking down a Linux server?

Running a script that allocated 50 MB per loop with systemd-run -p MemoryMax=300M -p MemorySwapMax=0 got the process OOM-killed at the cap while the host still had about 7 GB available.

Results

resultoom-kill of the limited process only
host memory after~7,031 MB available

How it was measured

A Python allocator loop under a transient unit.

systemd-run -p MemoryMax=300M -p MemorySwapMax=0 python3 hog.py

Why

cgroup v2 memory limits are enforced per unit.

When this does not apply

Set the limit above normal usage and test it.

Environment

GitHub-hosted Ubuntu 24.04 runner (2 vCPU, ~8 GB RAM), systemd 255. Measured 2026-10-12.

Source: linux-lab/05-cgroup-memory-limit.sh in my content-engine repository. Treat any single run as a direction; re-run it on your hardware.

By Josué Barros, senior software engineer (full-stack, data and AI).