Module cgroup

Module cgroup 

Source
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::setup walks every ancestor’s cgroup.subtree_control from walk_root down to parent;
  • CgroupManager::drain_tasks / cleanup_recursive drain 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:

Controllersetup writesMethods that touch the controller’s files
cpusetwhen 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
cpuwhen Controller::Cpu in the set passed to setup (runtime adds it when a CgroupDef declares cpu)Self::set_cpu_max, Self::set_cpu_weight
memorywhen 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
pidswhen Controller::Pids in the set passed to setup (runtime adds it when a CgroupDef declares pids)Self::set_pids_max
iowhen Controller::Io in the set passed to setup (runtime adds it when a CgroupDef declares io)Self::set_io_weight
(cgroup-core)not gatedSelf::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§

CgroupManager
RAII manager for cgroup v2 filesystem operations.

Enums§

Controller
Cgroup v2 controllers that CgroupManager::setup can enable in cgroup.subtree_control.

Traits§

CgroupOps
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.