Skip to main content

read_service_cgroup

Function read_service_cgroup 

Source
pub async fn read_service_cgroup(
    fs_root: &str,
    cgroup_path: &str,
    extra_pids: &[u32],
    host_memory: Option<HostMemory>,
) -> CgroupStats
Expand description

Read every cgroup accounting file for one service in a single parallel batch.

cgroup_path is the unit’s cgroup relative to the mount, e.g. /system.slice/chrony.service (the ControlGroup D-Bus property or runtime.CGroup.Path from Unit.List). extra_pids folds the main and control PIDs in the way systemd’s GetProcesses does, since both can sit outside the cgroup (e.g. during ExecStartPre/ExecReload/ExecStop). host_memory is the cycle-shared read_host_memory() result; None (unreadable /proc/meminfo) leaves memory_available at None.

An empty cgroup_path (inactive unit with no cgroup) short-circuits to CgroupStats::default() without touching the filesystem: without this guard the walk would start at the mount root itself and count every PID on the box. Every field but processes (which is 0) comes back None so the caller’s IPC fallback takes over, like any other unreadable cgroup.

The unit-level file reads run concurrently via tokio::join!, and callers join this future with their in-flight D-Bus/varlink calls, so filesystem IO never serializes behind IPC.