Cgroups v2 and effective enforcement
Control groups (cgroups) organize Linux tasks into a hierarchy for accounting and resource control. Namespaces primarily shape visibility; cgroups shape resource accounting and limits. With cgroup v2, controllers use a unified hierarchy and parent constraints can restrict descendants.
Worked example
This is an offline lesson. Scenarios are fictional and Docker commands are unexecuted. Any optional execution requires an approved disposable VM, a reviewed preloaded image with verified digest, blocked external access and appropriate resource limits. No resource exhaustion or host-policy change is required. Before any authorized optional observation, verify the effective daemon endpoint including overrides, exact object ID and observation window. Bound collection time and output bytes; do not generate resource pressure or export private telemetry. Mark unavailable measurements NOT RUN.
Illustrative cgroup v2 file contentscpu.max: 50000 100000memory.max: 134217728memory.current: 33554432pids.max: 64pids.current: 9memory.events: oom_kill 0 (excerpt)Parent CPU budget: 0.25 CPU equivalentcpu.max contains quota and period (or max and period), memory.max is a byte ceiling or max, and pids.max limits task creation. memory.events contains counters, including OOM-related events. The sample child requests 0.5 CPU but a 0.25 CPU parent limits its aggregate available budget further; siblings can reduce actual availability. Do not infer the effective limit only from HostConfig. Rootless support depends on controller delegation (Docker documents cgroup v2 with systemd for resource flags); Desktop Linux containers run under a VM budget. Confirm version, enabled controllers, delegation and correct cgroup path; read authorized metrics only, do not write controller files. The nominal remaining task capacity is 55, subject to ancestors. The memory ceiling is 128 MiB. The parent CPU cap is shared by its descendants. Distinguish hierarchical memory.events from memory.events.local when present; never attribute a parent event automatically to one child.
Common mistake
Do not hard-code a host cgroup path across distributions, runtimes or rootless setups.
Manual practice
Decode the sample memory ceiling in MiB, calculate remaining task capacity and explain the parent CPU constraint.
Worksheet: lab-fixtures/docker-resource-management/07-cgroups-v2/scenario.txt.
Check Your Understanding
Solidify your learning with the interactive assessment directly below this lesson.
Concept Quiz & Questions
Cgroups v2 and effective enforcement — Knowledge check
Apply resource management reasoning in a fictional scenario.
What is 134217728 bytes in MiB?
Can a parent cgroup constrain a child further?
What does cpu.max 50000 100000 represent?