Repository navigation
Add procfs processor for cgroup, shm and child process resources - #32
prabhkodes wants to merge 3 commits into
Conversation
|
How to use Nothing to configure. On Linux, any run that already logs resources gets the five core metrics: from traceml import tracking
tracking.init(collect_resources=True) # same as todayThe metrics land next to To log all 22 metrics, set one env var before the run starts: POLYAXON_COLLECT_RESOURCES_DETAILED=true python train.pyOn Polyaxon, polyaxon/cli#58 lets you set this from the component spec instead. |
psutil reports the node's cpu and memory, so inside a pod a job at 68% of its memory limit and throttled by its cpu quota is logged as 20% memory and 0% cpu. Read the container-aware counters the kernel exposes under /proc and /sys/fs/cgroup (v2 and v1) and log them through the existing resource writer: - cgroup memory usage, limit, shmem and oom_kill count - cgroup cpu quota and throttling counters - /dev/shm usage - current process rss split, threads and file descriptors - direct children count, rss and D-state count Linux only; skipped when /proc/self is missing and every read is
324c983 to
90363bd
Compare
The processor read memory.max and cpu.max on the process's own cgroup only. Kubernetes sets the pod limit on the parent cgroup and Slurm nests job and step, so the leaf said "max" and the cgroup metrics were dropped. Walk from the process's cgroup up to the root, take the smallest limit, and read usage where that limit is enforced, so percent is what the OOM killer sees. Same for the cpu quota and throttling counters.
|
Update in 0cfe446: the limit is now read along the cgroup hierarchy, not only on the process's own cgroup. Kubernetes sets the pod limit on the parent cgroup and Slurm nests job and step. The leaf then says Checked in a container with |
…m is least The hierarchy walk joined the path from /proc/self/cgroup onto /sys/fs/cgroup and kept the directories that exist. That path is relative to the hierarchy root, but a mount can start below it: Docker with the host cgroup namespace on cgroup v1 mounts /docker/<id> while /proc/self/cgroup says /docker/<id>/pod/app, so nothing below the mount point was found and a nested limit was missed. Read (mount point, mount root) from /proc/self/mountinfo, strip the mount root from the path and join the rest onto the mount point. When several mounts contain the process, take the one with the shortest root, which shows the most ancestors. Without a matching mount the old join onto cgroup_root is kept, so tests can point at a fake tree. Memory was read on the level with the smallest limit. A parent limit also counts the siblings' usage, so a parent with a larger limit can be closer to it, and that is where the OOM killer fires first. Report current, max and percent of the limited level with the least headroom. The cpu quota stays the smallest one. cgroup v1 is tried when v2 reports no limit, so a systemd hybrid host, where v2 is mounted without controllers, still reads its v1 limits.
|
@md-mq could you review this? It adds a procfs processor that logs memory against the limit of the run's own cgroup and its parents, so a pod or nested limit shows instead of host RAM. polyaxon/cli#58 adds the plugin flag and depends on this PR. |
|
@prabhkodes I will review it next week, since we are also going to introduce tracking for TPU as well. thank you for the PR. |
Closes #31
Summary
This PR adds a
procfsresource processor. It reads container metrics from/procand/sys/fs/cgroupon Linux. It writes them with the same resource writer as the psutil and GPU metrics.psutil shows the node, not the pod. A job at 68% of its pod memory limit logs
memory = 20%. This PR makes the pod limits visible.Metrics
Five metrics are on by default. Each one shows one failure mode.
cgroup_memory_percentcgroup_oom_killcgroup_cpu_throttled_usecshm_percent/dev/shmuseproc_children_state_dSet
POLYAXON_COLLECT_RESOURCES_DETAILED=trueto log 17 more metrics. SeeCORE_METRICSin the processor for the split.Notes
/proc/self/cgroupand/proc/self/mountinfo, so a bind-mounted subtree (Docker with the host cgroup namespace on cgroup v1) does not hide a parent limit. Memory current, max and percent come from the limited level with the least headroom, which is the one the OOM killer reaches first: a pod limit on the parent also counts the siblings' usage. The CPU quota is the smallest one on the path, each level with its own period./proc/selfdoes not exist. All reads are best-effort. A failure cannot stop a run.Tests
/proctree. They cover cgroup v1, cgroup v2, limits on a parent cgroup, unlimited cgroups, both detail levels, mount roots and subtree aliases from a fakemountinfo, a hybrid v1/v2 host, and a parent with less headroom than the child. The last four fail on the previous commit.Precedent. The same walk is already in production elsewhere. Rust's
std::thread::available_parallelismtakes the smallestcpu.maxfrom the process cgroup up to the mount (quota_v2). The JDK fixed limits on parent nested cgroups in JDK-8322420 (2024) and the hierarchical memory limit in JDK-8370572 (2025). Go 1.25 finds the process cgroup through/proc/self/cgroupand/proc/self/mountinfo(cgroup_linux.go), reading the leaf only. vLLM's CPU-quota reader walks the hierarchy (_cgroup_cpu_limit); vllm-project/vllm#64104 adds the same for memory. The same fix for OpenObserve merged on 2026-10-28 (openobserve/openobserve#15906).