Cgroups v2 — Hierarchical Resource Control
Cgroups v2 organize processes in a unified hierarchy and provide resource accounting and controls through controller files. Ordinary domain cgroups group a process and its threads; a threaded subtree permits individual threads to belong to different cgroups for supported threaded controllers while sharing a resource domain. Available controllers and enabled subtree controllers are distinct. CPU bandwidth can be expressed with quota and period in cpu.max; a quota divided by period represents aggregate bandwidth, not dedicated CPUs. Memory limits, I/O limits and process limits have controller-specific semantics. Ancestor constraints can restrict a child even when the child's local setting is unlimited. A cgroup namespace can change the visible cgroup path, so do not blindly join paths from proc with a presumed host mount. Inspect mount type, caller membership and controller availability; writes require delegated authority and can impact other workloads. The read-only example confirms a visible cgroup2 mount and unified membership, then reads controller names at the conventional mount root. It does not enforce limits or assert every controller is enabled. Example prerequisites: Linux, Bash and Python 3 standard library; run as a non-root user in a private temporary working directory. Example scope: native read-only observation. Expected output: cgroup v2 mount and unified membership inspected. No system configuration changes.
Formal Syntax & Structure
/proc/self/cgroup; /sys/fs/cgroup/cgroup.controllers; cpu.max; memory.maxParameters & Attributes
| Name | Type | Description |
|---|---|---|
| cgroup.controllers | list | Controllers available at this cgroup. |
| cgroup.subtree_control | list | Controllers enabled for children. |
| cpu.max | quota period | CPU bandwidth setting, max means no local cap. |
| memory.max | bytes or max | Local hard memory limit. |
Return Value
Files expose hierarchy and controller state; this example checks a conventional mounted environment.
Working Example
python3 - <<'PY'from pathlib import Pathimport subprocessfs=subprocess.check_output(['stat','-f','-c','%T','/sys/fs/cgroup'],text=True,timeout=5).strip()assert fs=='cgroup2fs'rows=Path('/proc/self/cgroup').read_text().splitlines()assert any(row.startswith('0::/') for row in rows)names=Path('/sys/fs/cgroup/cgroup.controllers').read_text().split()assert len(names)==len(set(names))print('cgroup v2 mount and unified membership inspected')PY