Repository navigation
fix: read cgroupv2 cpu usage from the cgroup that owns cpu.max - #43
Open
david-fraley wants to merge 1 commit into
Open
david-fraley wants to merge 1 commit into
david-fraley wants to merge 1 commit into
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #41 (ENG-3480). CPU counterpart of #39.
cpuTotal()takes the quota from the nearest ancestor that setscpu.max, butcpuUsed()readcpu.statfrom the process's own cgroup. In docker-in-docker and devcontainer workspaces the agent sits in/init.scopewhile nested containers run in sibling/docker/<id>, so a busy container showed as idle (0.009/12 coresvs 4.3 actual in the issue's repro).cpuUsed()now readscpu.stat(and the period) from the cgroup that owns the quota.cpu.statalready 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 nocpu.stat, it falls back to the old behavior. The structure mirrors the memory change in #39.Added
CPU/UsageFromLimitOwnerwith an/init.scope+/docker/<id>fixture. It reports 0.01 cores onmainand 4.01 with this change. Multi-level limits (#40) are out of scope.Generated by Coder Agents on behalf of @david-fraley.