Skip to main content
KBY Technologies Logo
Lexicon
Lexicon

cgroup v2 (Unified Hierarchy)

Difficulty: Advanced
3 min read

In plain English

Plain definition

cgroup v2 is the modern Linux kernel resource-control subsystem that unifies CPU, memory, I/O, and PID accounting into one consistent hierarchy instead of cgroup v1's independently mounted controllers.

Under cgroup v1, each controller (cpu, memory, blkio, devices) could be mounted on a separate hierarchy, letting a process belong to different cgroup trees for different resources. That made it very hard to correlate controllers and led to bugs where a container’s CPU cgroup and memory cgroup disagreed about its parentage. cgroup v2 collapses this into a single unified hierarchy: one directory tree under /sys/fs/cgroup, where every controller that is enabled applies uniformly to every node in that tree. A process can only exist in one cgroup at a time. Kubernetes’ QoS classes (Guaranteed, Burstable, BestEffort) and systemd’s slice/scope model both rely on that rule to work correctly.

The interface files changed meaning as well as name. memory.limit_in_bytes became memory.max (hard limit, triggers OOM kill) alongside a new memory.high (throttle limit that puts the cgroup under heavy reclaim pressure and never invokes the OOM killer itself). With two tiers, an orchestrator can back off gradually as memory pressure builds instead of going straight to an OOM kill. Similarly, cpu.max replaces the v1 cpu.cfs_quota_us/cpu.cfs_period_us pair with a single quota period line, and the io controller unifies what was split across blkio.throttle.* files. cgroup v2 also exposes PSI (Pressure Stall Information) via cpu.pressure, memory.pressure, and io.pressure, giving a time-weighted measure of tasks stalled waiting on a resource. This is what tools like oomd/systemd-oomd use to preempt failure before the global OOM killer fires indiscriminately.

The biggest hazard when migrating is the cgroup driver mismatch: kubelet and the container runtime (containerd, CRI-O) must agree on whether they manage cgroups directly (cgroupfs driver) or delegate to systemd (systemd driver), and a mismatch between the kubelet and runtime cgroup drivers can cause instability and pod failures, so both must be configured to use the same driver. Because v2 uses a single hierarchy and enables controllers per subtree through cgroup.subtree_control, they cannot be mounted on separate hierarchies as in v1, which breaks older monitoring agents that assumed independent controller hierarchies. Swap is handled differently as well. Its usage is controlled separately by memory.swap.max, which defaults to max, so a cgroup that reaches memory.max can swap during reclaim before the OOM kill unless memory.swap.max is set, distorting node memory pressure signals if swap is enabled inconsistently across a fleet.

In practice, node bootstrapping, kubelet cgroup-driver configuration, and container runtime version pinning are no longer independent decisions. Together they form one compatibility contract that has to be checked for each kernel version, since cgroup v2 adoption depends on distro defaults (Kubernetes requires Linux kernel 5.8 or later, a cgroup v2-capable runtime and the systemd cgroup driver) and older software that reads v1 paths directly can misbehave without an obvious error, for example by sizing a heap from host memory instead of the pod limit.

About this page

Credited to

Dates

Published

Corrections

  • : Corrected during a review of published articles. Details
  • : Corrected during a review of published articles. Details

Was this useful?

Reports go to the site owner and are used to correct pages. Corrections are listed at /corrections.

Found this useful? Follow KBY for more like it.

More from KBY that goes with this term.