cgroup v2 Internals
cgroup v2 unified hierarchy, cpu/memory/io controllers, delegation for rootless containers, and Kubernetes integration.
Overview
cgroups v2 (control groups version 2) is the Linux mechanism for grouping processes and applying resource limits to CPU, memory, I/O, PIDs and CPU sets. It supersedes cgroups v1 with a unified hierarchy: one tree instead of a separate tree per controller.
Version 1 vs Version 2
The difference starts with the shape of the tree and runs through the controllers, the OOM handling and delegation.
- Hierarchy: v1 gives every controller its own separate tree, so a process can sit in different places in each. v2 has a single unified tree.
- CPU accounting: v1 needs the separate cpuacct controller. In v2 it is built into the cpu controller.
- I/O control: v1 uses the blkio controller. v2 replaces it with the io controller, which offers a weight plus BPS and IOPS limits.
- Memory OOM: v1 handles out-of-memory per cgroup, inconsistently. v2 has a unified OOM, and memory.oom.group can kill a whole cgroup together.
- Delegation: handing a subtree to someone else is complex and unsafe in v1. v2 supports safe subtree delegation.
Key concepts
- cpu.max
- memory.high
- memory.oom.group
- Delegation
Interview questions
- How does Kubernetes translate a pod resource request/limit into kernel cgroup settings?
Sign up free to read the full topic
More Linux topics
Start free on Cariara · Coding problems · System design studio