Skip to content

fix: read cgroupv2 cpu usage from the cgroup that owns cpu.max - #43

Open
david-fraley wants to merge 1 commit into
mainfrom
dfraley/cgroupv2-cpu-usage-limit-owner
Open

david-fraley wants to merge 1 commit into
mainfrom
dfraley/cgroupv2-cpu-usage-limit-owner

Conversation

@david-fraley

Copy link
Copy Markdown

Fixes #41 (ENG-3480). CPU counterpart of #39.

cpuTotal() takes the quota from the nearest ancestor that sets cpu.max, but cpuUsed() read cpu.stat from the process's own cgroup. In docker-in-docker and devcontainer workspaces the agent sits in /init.scope while nested containers run in sibling /docker/<id>, so a busy container showed as idle (0.009/12 cores vs 4.3 actual in the issue's repro).

cpuUsed() now reads cpu.stat (and the period) from the cgroup that owns the quota. cpu.stat already rolls up all descendants, so this counts the siblings. When the process's own cgroup holds the quota, or there is no quota, behavior is unchanged. If the owner has no cpu.stat, it falls back to the old behavior. The structure mirrors the memory change in #39.

Added CPU/UsageFromLimitOwner with an /init.scope + /docker/<id> fixture. It reports 0.01 cores on main and 4.01 with this change. Multi-level limits (#40) are out of scope.


Generated by Coder Agents on behalf of @david-fraley.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

bug: CPU usage misses other processes that share the same CPU limit (cgroup v2)

1 participant