Cgroups v2 and resource accounting
Quick answer
Control groups (cgroups) organize processes into a hierarchy for resource accounting and control. In cgroup v2, a unified tree exposes controller files such as cpu.max, memory.current and memory.max. A child remains subject to limits imposed by ancestors.
In a fictional group, a CPU quota of 50000 microseconds per 100000-microsecond period gives half a CPU of average bandwidth, not a dedicated half-core. Check parent limits as well as local settings, and distinguish observed consumption from configured maximums.
Prepare the practice environment
Run python3 lab-fixtures/containers-virtualization/setup.py from the extracted root as an ordinary user. Enter the printed private path and check pwd. Use fresh fixtures, Bash with set -e -o pipefail, LC_ALL=C and umask 077. The Python helper parses fictional examples or inspects its own child. No runtime daemon, external network or root access is needed. Do not apply the fictional JSON to any runtime. Version checks need the named tools.
Prerequisites
Review: Linux namespaces.
How it works
cpu.max contains quota and period in microseconds, or max for no local bandwidth cap. For example 50000 100000 is half a CPU of sustained aggregate bandwidth, not a dedicated half-core; bursts and scheduling details affect observations. cpu.weight distributes CPU proportionally among competing siblings. memory.current reports current charged usage, memory.high initiates reclaim/throttling pressure and memory.max is a hard limit that can lead to cgroup OOM when reclaim cannot satisfy allocations. memory.events records events such as high, max and oom_kill. pids.max limits task creation; io.max can cap per-device I/O. Ancestor limits and competing siblings matter; summing local headroom does not establish capacity. Controllers must be enabled and delegated appropriately; use the service manager or runtime rather than manually rewriting their managed tree. This chapter reads the mounted filesystem type and parses synthetic snapshots without writing any controller file.
Try the examples
The tested environment uses v2 here; hybrid or v1 environments differ.
Expected stdout:
cgroup2fsSynthetic quota 50000 and period 100000 describe a bandwidth cap.
Expected stdout:
0.50 CPU equivalentsSynthetic child and parent usage are compared. The bound is a snapshot, not an allocation guarantee; reclaim, siblings and accounting can change it.
Expected stdout:
child headroom 128 MiB; parent headroom 64 MiB; modeled bound 64 MiBCommon mistakes
Do not confuse CPU weight with quota or memory.high with memory.max. Never trigger a real OOM or write cgroup limits on a shared host for this exercise.
Practice
Change a private copy of resources.json to use a quota of 200000 and period 100000, then predict the new CPU bandwidth. Explain why the parent may constrain a child even if its own limit is not reached.
Related references
Study: stat. These are reference names, not deployed links.
Check Your Understanding
Solidify your learning with the interactive assessment directly below this lesson.
Concept Quiz & Questions
Cgroups v2 and resource accounting — Knowledge Check
Apply container and virtualization concepts to concrete local examples.
What does cpu.max 50000 100000 model?
What does memory.current represent?
Which can constrain a child with local headroom?
What is memory.high primarily for?