Use it when containers are throttled, OOM-killed or limits seem not to apply.
Control Groups (cgroups v2)
cgroups v2 is the unified Linux control-group hierarchy that limits and accounts CPU, memory, I/O and pids for groups of processes. Container runtimes and systemd use it for resource limits.
1. stat -fc %T /sys/fs/cgroup — cgroup2fs?
2. Container's cgroup: cat /proc/<pid>/cgroup.
3. Memory: cat /sys/fs/cgroup/<path>/memory.max and memory.events (oom_kill).
4. CPU throttling: cpu.stat nr_throttled.
5. Adjust limits.
process in a cgroup → controllers enforce limits → events/stats recorded
Context & applicabilityCommon mistakes · platform/version boundaries
Operational reference
Fast context before you go deeper.
Verification & Troubleshooting
Start with the observed symptom, prove the nearest boundary, and move outward only when the current state is understood.
Use the operational verification above to establish the expected state.
Capture the concrete output, symptom, packet, log or counter before changing anything.
Step 1 How to verify Verify boundary
Find the path with cat /proc/<pid>/cgroup. Read memory.events for oom_kill, and cpu.stat for throttling. Compare memory.current with memory.max during load. In Kubernetes, kubectl describe pod shows the last state OOMKilled.
Step 2 Common failures Narrow the fault
Mixing cgroup drivers (cgroupfs versus systemd) between kubelet and runtime causes unstable nodes. A low CPU limit causes latency spikes through throttling even when the node is idle. Page cache counts toward memory usage, so file-heavy workloads can hit memory.max unexpectedly.
Check that host, runtime and kubelet agree on cgroup v2 and the systemd driver. Memory limits are hard (OOM kill); CPU limits throttle. Read memory.events and cpu.stat for evidence.
cat /proc/<pid>/cgroup— cgroup pathdocker ps -a— containers and exit codesdocker logs <c>— container outputdocker inspect <c>— config, mounts, network, state
ReferenceWhat it is1 section · depth on demand
How it works
The runtime creates a cgroup per container, usually under system.slice or kubepods.slice when the systemd driver is used. Limits are files: memory.max, cpu.max, io.max and pids.max. The kernel enforces them continuously; usage and event counters show what happened. Kubernetes requests map to cpu.weight and limits map to cpu.max and memory.max.
ReferenceImportant terms & boundaries2 sections · depth on demand
Common mistakes
- No memory limits, so one container triggers the host OOM killer.
In depth
cgroup v2 is a single tree mounted at /sys/fs/cgroup. A container gets one directory in that tree, and its limits and counters are plain files.
| File | Meaning | Typical container mapping |
|---|---|---|
memory.max | Hard memory limit; above it the OOM killer runs inside the cgroup | --memory, Kubernetes memory limit |
memory.high | Throttle and reclaim point below the hard limit | Not set by default |
memory.events | Counters: high, max, oom, oom_kill | Proof of OOM kills |
cpu.max | quota period, for example 50000 100000 = 0.5 CPU | --cpus, Kubernetes CPU limit |
cpu.weight | Relative share under contention (1–10000) | Derived from Kubernetes CPU request |
cpu.stat | nr_throttled, throttled_usec | Proof of CPU throttling |
pids.max | Maximum number of processes | --pids-limit |
Worked check — is the container being throttled or OOM-killed?
CG=/sys/fs/cgroup$(cut -d: -f3 /proc/$PID/cgroup)
cat $CG/cpu.max # 50000 100000 → 0.5 CPU limit
grep throttled $CG/cpu.stat # nr_throttled rising during load → limit is the bottleneck
cat $CG/memory.events # oom_kill 3 → three kills by the memory limit
Reading the result
- A rising
nr_throttledwith low average CPU use means bursts are being cut off by the quota; latency suffers even though dashboards show spare CPU. oom_killinmemory.eventsmeans the container's own limit was hit. A kill with no counter in the container's cgroup points at the host OOM killer instead.- Page cache counts towards
memory.current; a file-heavy workload can approachmemory.maxwithout a leak, and the kernel reclaims cache before it kills.
Additional reference context Scope · expected state · examples · history · terminology Open only when you need the supporting context
Terms & aliases
Hover a linked term for a quick definition; click it to open its glossary entry. Aliases are other names that find this Topic in search.