dmesg, saw the familiar "Out of memory: Killed process" line, maybe restarted the service, and moved on. Then it happened again. And again. You look at total RAM on the box — plenty free. So why does the kernel keep killing things?
The answer, more often than not, is a cgroup memory limit sitting well below your actual available RAM. The OOM killer did its job. But the problem it responded to was never system-wide memory exhaustion. It was a per-cgroup ceiling that nobody adjusted — or nobody knew existed.
Initial impact: repeated kills with free RAM
free -h shows the host still has gigabytes available. Restarting the service buys time, but the cycle repeats.
The instinct is to add more RAM or throw swap at it. Sometimes that works if the host genuinely runs tight. But when the host has headroom and processes still die, something else is capping memory for that specific process group.
That something is a cgroup memory limit.
Investigation: where the limit actually lives
nginx.service, your mysql.service, your PHP-FPM pool — each one lives inside a cgroup, and each one can have a memory ceiling enforced by the kernel, independent of total host RAM.
To find out whether a cgroup memory limit is in play, check the cgroup of the killed process. On a system using cgroups v2 (most modern distros), you can inspect the limit directly:
BASH
# Find the cgroup of a running process (replace PID)
cat /proc/<PID>/cgroup
# Then check its memory limit (path depends on your cgroup mount)
cat /sys/fs/cgroup/<slice>/<service>/memory.maxmemory.max shows a number (in bytes) rather than max (which means unlimited), that process group has a hard ceiling. When total memory consumption of all processes in that cgroup hits this number, the kernel's OOM killer activates — scoped to that cgroup, not the whole system.
For systemd-managed services, you can also check with:
BASH
systemctl show <service-name> --property=MemoryMax --property=MemoryHighMemoryMax is set, that is your hard limit. MemoryHigh is a softer throttle — the kernel slows down allocations and tries to reclaim memory before resorting to kills. Both matter.
The critical discovery: system OOM vs. cgroup OOM
oom_score across the entire system. Adding RAM or swap directly helps here.
Cgroup-scoped OOM. A specific cgroup hits its memory.max ceiling. The kernel kills a process inside that cgroup only. The rest of the system might have gigabytes free. Adding RAM to the host does nothing — the cgroup limit stays the same.
The kernel log for a cgroup OOM typically includes the cgroup path. Look for lines like:
TEXT
# Illustrative log format from dmesg/journalctl
memory cgroup out of memory: Killed process 4821 (php-fpm) total-vm:524288kB ...
Task in /system.slice/php-fpm.service killed as a result of limit of /system.slice/php-fpm.service/system.slice/php-fpm.service path is the giveaway. The kill was scoped to that cgroup, not triggered by host-level exhaustion.
If you've been through the situation where the OOM killer picked the wrong process system-wide, the oom_score_adj article covers that angle. But when the kill is cgroup-scoped, oom_score_adj tuning on other processes won't help — the kernel is already only looking inside that one cgroup.
Temporary mitigation: raise the limit or remove it
BASH
systemctl edit <service-name>INI
[Service]
MemoryMax=2G
MemoryHigh=1800MBASH
systemctl daemon-reload
systemctl restart <service-name>MemoryMax is the hard ceiling — cross it and the OOM killer fires. MemoryHigh is the soft ceiling — cross it and the kernel throttles allocations, applying back-pressure through direct reclaim. Setting MemoryHigh somewhat below MemoryMax gives the kernel room to slow things down before resorting to kills.
For containers, the limit is typically set at container creation time (e.g., --memory flag in Docker, resource limits in Kubernetes pod specs, or Proxmox container config). Where you change it depends on your runtime.
Removing the limit entirely (MemoryMax=infinity) stops the cgroup OOM kills but also removes isolation. On a shared host or multi-tenant server, that is a bad trade-off — one runaway process can now consume everything and trigger system-wide OOM instead.
The architectural fix: right-size limits with throttling
memory.current in the cgroup filesystem to see real-time consumption, or use systemd-cgtop for a live view of all cgroups. Collect this over a representative period — peak hours, batch job windows, whatever drives load.
Second, set limits that give the workload room to breathe while still protecting the rest of the system:
memory.high(orMemoryHighin systemd): Set this to the upper range of normal usage. When the workload crosses this line, the kernel applies memory reclaim pressure — slowing allocations rather than killing. This is your early warning and throttle.memory.max(orMemoryMax): Set this abovememory.high, as the absolute ceiling. Crossing this triggers OOM kills. It should be high enough that normal operation never touches it, but low enough that a genuine leak or runaway doesn't eat the whole host.memory.low(available in cgroups v2): This is a memory reservation — the kernel tries to protect this amount from reclaim. Useful for critical services like databases that need a guaranteed working set. For more on howmemory.lowworks in multi-tenant hosting, the cgroups v2 isolation article covers it in depth.
memory.low as a floor, memory.high as a throttle, memory.max as a hard stop — turns cgroup memory management from a binary kill/no-kill into a spectrum. The workload gets slowed down before it gets killed, and critical services get protected memory that other cgroups cannot easily steal.
Where limits come from when you didn't set them
- Container runtimes often set default memory limits. Docker, for example, may inherit limits from orchestration configs or compose files written months ago.
- Hosting control panels (cPanel, Plesk, CloudLinux, etc.) frequently set per-user or per-service cgroup limits as part of their resource management. These limits may not be visible in the panel UI but exist in the cgroup filesystem.
- systemd slice defaults can propagate limits. If a parent slice (like
user.sliceor a custom slice) has aMemoryMax, all services under it inherit that ceiling. - Proxmox and other virtualization platforms set cgroup limits for containers (LXC) based on the container configuration.
Practical takeaway
memory.max and memory.current for that specific service or container. If the limit is the bottleneck, adjust it — but do it with a graduated setup: memory.high for throttling, memory.max for the hard stop, and memory.low to protect critical services. Killing a process is the kernel doing exactly what it was told. The fix is changing what you told it.