Pcornel
Browse topics
Options
Recent
Favorites
Containers · Technical reference

Control Groups (cgroups v2)

Direct answer

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.

When to use this

Use it when containers are throttled, OOM-killed or limits seem not to apply.

First 30 seconds

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.

Operational verification

process in a cgroup → controllers enforce limits → events/stats recorded

Context & applicabilityCommon mistakes · platform/version boundaries
Platform / version applicability
Docker / containerd / Podman / Kubernetes / OCI-compatible platforms
applies
Structured applicability is explicit Topic metadata; it does not infer compatibility beyond the stored rows.
At a glance

Operational reference

Fast context before you go deeper.

PlatformDocker / containerd / Podman / Kubernetes / OCI-compatible platforms
Scope / prerequisiteUse it when containers are throttled, OOM-killed or limits seem not to apply.
What next?2 suggested next steps
Evidence0
On this pageJump to a specific section
Operational workflow

Verification & Troubleshooting

Start with the observed symptom, prove the nearest boundary, and move outward only when the current state is understood.

2 steps Observe → verify → isolate → change minimally → repeat the original test.
ObservedRecord what the original test actually shows

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.

Key points

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.

Key checks
  • cat /proc/<pid>/cgroup — cgroup path
  • docker ps -a — containers and exit codes
  • docker logs <c> — container output
  • docker 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.

FileMeaningTypical container mapping
memory.maxHard memory limit; above it the OOM killer runs inside the cgroup--memory, Kubernetes memory limit
memory.highThrottle and reclaim point below the hard limitNot set by default
memory.eventsCounters: high, max, oom, oom_killProof of OOM kills
cpu.maxquota period, for example 50000 100000 = 0.5 CPU--cpus, Kubernetes CPU limit
cpu.weightRelative share under contention (1–10000)Derived from Kubernetes CPU request
cpu.statnr_throttled, throttled_usecProof of CPU throttling
pids.maxMaximum 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_throttled with low average CPU use means bursts are being cut off by the quota; latency suffers even though dashboards show spare CPU.
  • oom_kill in memory.events means 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 approach memory.max without a leak, and the kernel reclaims cache before it kills.
Source basisSource attribution states what this section is based on; it is not independent proof that the current environment matches it.
Additional reference context Scope · expected state · examples · history · terminology Open only when you need the supporting context
Terminology layer

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.

Aliases that resolve here
control groups (cgroups v2)cgroups v2container resource limits
Confirmation

Confirm action

Continue?