Part of the accepted-design index.
Cgroup directories are shared kernel objects, often managed by a service manager. An owned directory reference provides stable identity without claiming ownership of the hierarchy. Closing a local reference therefore never removes a cgroup or changes membership, controllers, or limits. Explicit child removal prevents an error path or deferred close from unexpectedly destroying a workload. Creation owns rollback when acquisition fails; concurrent external modifications can prevent removal and their cleanup error remains visible.
Directory-relative operations keep the acquired parent identity across rename, use atomic close-on-exec descriptors, and reject child symlinks and path traversal. They avoid exposing control-file streams or raw descriptors as a substitute for typed operations. The package validates v2 filesystem identity rather than treating ordinary temporary directories as real cgroups. Public native text codecs permit captured-format fixtures without introducing a fake live backend. This does not claim confinement against a privileged hierarchy/mount owner.
The first controller surface uses individual operations instead of a combined resource configuration object. Separate files do not provide a transaction: a bulk API would need a partial-application contract or misleading rollback. The kernel’s actual atomic subtree-control command remains one operation. Unknown inspection values survive, while mutation accepts the selected controller vocabulary and rejects ambiguous requests before writing.
CPU intervals use durations with exact microsecond conversion; memory and task limits retain the decimal/max distinction, with zero a real limit. CPU quota is scoped to fair-class scheduling, avoiding a process-wide reservation claim. Memory boundaries use Linux 7.0’s documented O_NONBLOCK behavior so reducing a workload’s limit does not require synchronous reclaim/OOM in the management caller. This deliberately allows delayed enforcement until new charges. No controller availability, ancestor setting, migration permission, or systemd ownership is inferred from an open handle.
Membership changes for existing tasks are whole-process operations through
cgroup.procs. A numeric PID can race with exit and reuse. Group.Start uses
Go’s clone-into-cgroup startup for new commands, so initial placement and task
admission happen before the child can execute. A startup handshake with later
migration leaves startup work and initial charges in the source group.
Temporarily copying the command’s startup attributes and pinning the captured
directory through startup preserve caller configuration and group identity
across concurrent close. Go retains responsibility for prepared I/O, failed
startup cleanup, and waiting. Go Linux startup,
Linux 7.0 cgroup fork path.
Freezer and kill commands reuse owned, directory-relative file operations. containerd/cgroups v3.1.3 operates through paths, couples freeze requests to an unbounded polling loop, and falls back to signaling enumerated PIDs if the native kill write fails. Direct writes retain the captured group identity and Linux’s native kill semantics and errors. The existing event watcher lets callers bound their own reconciliation. Local freeze intent and observed completion remain separate because a group may be frozen by an ancestor or still transitioning.
I/O updates belong to the existing owned group. Each io.max update sends the fields for one device together. The kernel preserves omitted fields, so concurrent updates to distinct fields require no library read-modify-write cycle. Weight reset has a named value and device overrides remain separate from the group default. Statistics retain native policy extensions as text because some values are fractional. The containerd/cgroups I/O adapter emits individual rate writes and targets the BFQ-specific weight file. Reusing the directory-relative operations preserves the grouped update and supports the generic io.weight file with fewer ownership and error-translation layers.
Cpuset lists use inclusive ranges to retain sparse IDs with memory proportional to the ranges. The API exposes requests and effective lists separately because Linux can grant a different mask as topology and hierarchy constraints change. Partition reads preserve invalid state because a mode write can succeed while Linux degrades the partition. The caller owns coordination of separate CPU, node, and partition writes.
CPU burst remains a separate operation from bandwidth because the kernel exposes two control files. A preflight quota read would race with other writers. Utilization clamps use hundredths of one percent, matching the native request without floating-point conversion. Linux determines the reported value and effective clamp. CPU and pressure reads keep each native snapshot’s scope and preserve missing counters or classes. The containerd/cgroups statistics adapter reopens files by group path and projects selected statistics into a fixed metrics schema. Reading through the existing directory handle retains group identity across rename and preserves newer fields. PSI snapshots share the native record parser and require no trigger lifetime or background reads.
Memory protection, limits, and observations follow the same independent file operations. The existing counter parser retains the optional memory accounting keys that a fixed statistics schema would turn into zero values. Peak reads expose the lifetime watermark because a reset affects only future reads on the descriptor that performed it. A stateful resettable peak would need its own owner.
Proactive reclaim submits one native write. Linux can return EAGAIN or EINTR after reclaiming some pages, so a repeated write could reclaim beyond the caller’s budget. Keeping this operation on the owned group preserves directory identity while using the native write directly to report partial failure. A separate typed swappiness selector distinguishes the kernel policy, numeric zero, and anonymous-only mode. Linux 7.0 reclaim implementation.
PIDs observations read each native file through the owned group. Independent reads preserve file availability and the mount’s event attribution without caching counters or inferring scope from a group path. The containerd/cgroups statistics adapter reads current tasks and the limit into a fixed record. Keeping the existing directory-relative readers also preserves the lifetime peak and the counters supplied by each event file. containerd/cgroups statistics adapter, Linux 7.0 PIDs accounting.
HugeTLB discovery enumerates the current files in the captured group. This keeps the result scoped to visible controls even when system pools are empty or the host exposes more page sizes than the delegation. A delegate can create many child groups, so discovery reads the entire directory in fixed-size batches and retains only matching page sizes. Separate native limit writes preserve fault and reservation accounting, which can charge the same mapping at different times. containerd/cgroups HugeTLB configuration builds a path-based request for the fault limit from a caller-supplied string. The directory-relative implementation retains ownership and supplies reservation control, per-size discovery, and native event and NUMA field passthrough. Linux 7.0 HugeTLB accounting.
RDMA control uses the complete device key from the native files. Retaining the optional device index in that key distinguishes same-name devices across network namespaces while preserving the Linux 7.0 name-only format. The kernel applies supplied limits to one device under its controller lock and preserves omitted limits. The existing group-relative write can use this guarantee without preflight discovery, which would race with device registration. The containerd/cgroups configuration always emits both HCA fields as unsigned numbers. Direct file operations support independent updates, the native unlimited value, and additional observation keys while retaining the captured group identity. containerd/cgroups RDMA configuration, Linux 7.0 RDMA accounting, Linux 7.3 RDMA device keys.
Misc uses the existing directory-relative operations and flat-keyed record parser. A dedicated unsigned limit preserves the kernel’s full finite range and reserves the same value as Linux for unlimited. Looking up capacity or delegation before a write would introduce a race and could require a hierarchy-root handle the caller cannot access. A single write lets Linux enforce capacity registration and permissions, while event snapshots retain their native keys and attribution. The containerd/cgroups v2 manager supplies no equivalent operations. Linux 7.0 misc implementation, containerd/cgroups v2 manager.
Device-memory controls use the existing directory-relative file operations because the containerd/cgroups manager has no equivalent. Each write sends one complete region key and value. The slashes in a key carry driver identity, so a caller can reuse a discovered key without a device path lookup. The same key can disappear after discovery, leaving the kernel as the authority on registration and permission. Current and peak retain the native max saturation marker while capacity keeps the full unsigned byte count. Limit and protection reads stay independent of writes because Linux 7.0 can acknowledge a reduction without applying it and another writer can change the setting at any time. Linux 7.0 device-memory controller, containerd/cgroups v2 manager.
An event watcher owns a separate event file and inotify instance. It survives closure of the source group and integrates with the established Go poller/deadline behavior without a permanent goroutine. Registration uses /proc/self/fd while the file is pinned, so an old group path cannot select a replacement inode. This adds an explicit procfs prerequisite instead of a racy path-based fallback. Snapshots preserve the kernel’s coalescing semantics rather than claiming every transition was delivered; overflow and removal remain errors requiring reconciliation. Memory/PID event counters are independent snapshots and are not multiplexed into the membership watcher.
Kernfs can remove a pinned control file without notifying its inode. Directory deletion watches can also be delayed by open handles, and parent watches cannot observe the hidden parent of a namespace or bind-mount root. A waiting read therefore uses private 100-millisecond poller deadlines to check the pinned file’s active state with a seek. Inotify still supplies state-change notifications; an internal timeout yields no snapshot or caller deadline error. Caller deadline changes wake the read and are synchronized with its next bounded wait. This costs periodic wakeups only while a caller is reading and avoids a background goroutine, additional descriptors, and parent-path prerequisites. Linux’s removal error is normalized to os.ErrNotExist.
The Linux 7.0 cgroup v2 specification defines controller distribution, delegation containment, resource formats, memory nonblocking writes, and file notification semantics. The Linux 7.0 membership implementation emits namespace-relative PIDs, including zero when the task is invisible. Runtime runner evidence belongs to the verification guide, and missing execution evidence is recorded in verification limits.