Expand description
Cgroup v2 filesystem operations for test cgroup management.
Creates, configures, and removes cgroups under a parent path
(default /sys/fs/cgroup/ktstr). Provides cpuset assignment,
task migration, and cleanup.
§Walk root (cgroup-v2 delegation)
CgroupManager carries a walk_root that bounds two operations:
CgroupManager::setupwalks every ancestor’scgroup.subtree_controlfromwalk_rootdown toparent;CgroupManager::drain_tasks/cleanup_recursivedrain pids into{walk_root}/cgroup.procs(a writable root that is exempt from the kernel’s no-internal-process constraint).
walk_root defaults to /sys/fs/cgroup (Mode A: root-owned cgroup
tree). CgroupManager::with_walk_root retargets it for Mode B/C
delegation (systemd Delegate=yes, container nsdelegate) where
the operator owns subtree_control writes only inside a delegated
subtree. The constructor enforces that parent is at or below
walk_root so the strip-prefix walk cannot escape.
§Controller surface
CgroupManager enables a fixed controller set in
cgroup.subtree_control at Self::setup time so every method
that writes a controller knob succeeds without per-call lazy
enablement (which would race against concurrent sibling cgroup
creation). The enabled controllers and the knobs each one exposes
map to:
| Controller | setup writes | Methods that touch the controller’s files |
|---|---|---|
cpuset | when Controller::Cpuset in the set passed to setup (runtime adds it when a CgroupDef declares cpuset/cpuset_mems) | Self::set_cpuset, Self::set_cpuset_mems, Self::clear_cpuset, Self::clear_cpuset_mems |
cpu | when Controller::Cpu in the set passed to setup (runtime adds it when a CgroupDef declares cpu) | Self::set_cpu_max, Self::set_cpu_weight |
memory | when Controller::Memory in the set passed to setup (runtime adds it when a CgroupDef declares memory) | Self::set_memory_max, Self::set_memory_high, Self::set_memory_low, Self::set_memory_swap_max |
pids | when Controller::Pids in the set passed to setup (runtime adds it when a CgroupDef declares pids) | Self::set_pids_max |
io | when Controller::Io in the set passed to setup (runtime adds it when a CgroupDef declares io) | Self::set_io_weight |
| (cgroup-core) | not gated | Self::set_freeze, Self::move_task, Self::move_tasks |
cgroup.freeze and cgroup.procs are cgroup-core files exposed on
every non-root cgroup automatically; they do not require a
controller in subtree_control. memory.swap.max only exists when
the kernel was built with CONFIG_SWAP=y — the file is absent on
swap-disabled kernels and a write returns ENOENT (callers route
through the wire-time error chain).
§Untrusted-name validation
Cgroup names flow into Path::join under parent to address
files inside cgroupfs. validate_cgroup_name rejects shapes that
would escape that parent (.., absolute leading /, NUL) or
that produce invisible cgroupfs entries (leading .); other ASCII
is passed through to the kernel which is the final authority on
per-component validity. Every public method that takes a name
validates it before any filesystem write.
Structs§
- Cgroup
Manager - RAII manager for cgroup v2 filesystem operations.
Enums§
- Controller
- Cgroup v2 controllers that
CgroupManager::setupcan enable incgroup.subtree_control.
Traits§
- Cgroup
Ops - Abstraction over the cgroup v2 filesystem surface used by the
scenario runtime. The production implementation is
CgroupManager, which translates each method into real writes under/sys/fs/cgroup.