Virtualization

Docker container receives SIGKILL/exit 137 under sustained CPU load on cgroup v2 host despite ample host free memory

Environment

Environment

Ubuntu 22.04 host, kernel 5.15 with cgroup v2 enabled (systemd managing cgroups), Docker Engine 24.0, containers run with --cpus=2 --memory=4g. Processes inside container performing heavy CPU-bound tasks and allocating ephemeral memory buffers. Swap is disabled on host. Observed on multiple containers across two hosts.

Symptoms

Symptoms

Occasional abrupt container termination with exit code 137 / kernel OOM killer SIGKILL. Host shows available memory free and cached; dmesg occasionally shows 'memory cgroup out of memory' messages referencing the container's cgroup path. Container had memory limit set but host had unused physical RAM.

Observations

Observations

dmesg logs: 'memory cgroup out of memory: Kill process 12345 (node) score 1000 or sacrifice child' followed by 'oom_kill_process'. cat /sys/fs/cgroup/<container>/memory.current shows spikes exceeding memory.high but under memory.max for short periods. systemd-cgroup settings show memory.high configured by Docker to a value lower than memory.max. No host-wide OOM events apart from those container-specific kills.

Already attempted

Already attempted

Increased container --memory to 8g on a test instance and observed fewer kills but still occasional OOM events under prolonged load. Set --oom-kill-disable=false (default) and monitored: same behavior. Monitored memory.current and memory.swap.current under stress. Tried enabling swap on host (temporary small swapfile) — reduced frequency of kills. Upgraded kernel to latest 5.15 patch release (no change).

Question

Question

Is the likely cause cgroup v2 memory controller enforcing memory.high vs memory.max semantics under CPU/memory pressure, or an actual kernel OOM due to host fragmentation? What safe diagnostic steps can I run to confirm controller enforcement and mitigate without disabling crucial protections?

COMMUNITY RESPONSES

Verified community troubleshooting

0 replies

No answers yet..

Showing 0 of 0 community responses
AI DIAGNOSTICS

Incident analysis

Updated 1mo ago• Trouble ID

Most likely causes

cgroup v2 memory controller enforcement (memory.high/memory.max) triggering local OOM kills inside the container during bursty allocations despite host free RAM 85%
No swap configured on host causing memory reclaim failure for cgroup bursts, resulting in OOM despite overall host memory availability 60%
Application performs a transient large anonymous mmap or faulty allocation pattern that exceeds container limits before kernel can enforce soft limits 40%

Summary

Exit 137 and 'memory cgroup out of memory' indicate the kernel's memory controller (cgroup v2) is enforcing limits and invoking the OOM killer inside the cgroup when pressure crosses thresholds. Even with host RAM available, memory.high and memory.max settings combined with no swap and aggressive growth can cause cgroup-local OOM. The difference between memory.high (soft limit) and memory.max (hard limit) and how Docker maps --memory affects these is key. Enabling some swap or adjusting memory.high may mitigate.

Suggested Fixes

Diagnostic step 1
Inspect cgroup metrics during reproduction: watch memory.current, memory.max, memory.high, memory.stat in the container's cgroup directory (e.g., sudo cat /sys/fs/cgroup/<cgroup>/memory.current) to correlate spikes with kills.
Diagnostic step 2
Temporarily enable a small swapfile on the host (reversible): fallocate -l 4G /swapfile; chmod 600 /swapfile; mkswap /swapfile; sudo swapon /swapfile — then rerun workload to see if kills stop. If swap reduces kills, kernel reclaim was the limiting factor.
Diagnostic step 3
Experiment with raising container --memory and also set memory.swapiness and memory.high via Docker/cgroup settings to allow controlled burstable memory. For example, increase --memory and set --memory-reservation to allow soft bursts.

Continue troubleshooting

Matched from the title, description and tags