Repository navigation
metadata: add cpu_quota (Linux cgroup CPU bandwidth limit) - #265
Open
manunicholasjacob wants to merge 1 commit into
Open
manunicholasjacob wants to merge 1 commit into
manunicholasjacob wants to merge 1 commit into
Conversation
cpu_count and cpu_affinity do not show a cgroup CPU bandwidth limit (docker run --cpus, Kubernetes CPU limits, systemd CPUQuota=), so a benchmark run under such a limit records cpu_count=20 even when the process only gets 2 CPUs worth of time per period. Record the limit as cpu_quota, read from the process cgroup (cgroup v2, including parent cgroups, or cgroup v1). The key is only set when a limit is set. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
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.
A benchmark run inside a container or a systemd unit with a CPU limit (
docker run --cpus=2, a Kubernetes CPU limit, systemdCPUQuota=) gets throttled by the kernel once it uses its quota in a period, but nothing in the metadata shows it:cpu_countis still the host count andcpu_affinityis not set, because a bandwidth limit does not change the affinity mask. Two results from the same machine can then differ for a reasoncompare_tocannot show.This PR adds a
cpu_quotametadata entry on Linux, read from the process's own cgroup:cpu.maxof the process cgroup (from/proc/self/cgroup) and of each parent, keeping the smallest limit, since a parent limit also applies.cpu.cfs_quota_us/cpu.cfs_period_us, falling back to the mount root because the cgroup path is not visible inside a container.The value is formatted like the other CPU entries, e.g.
2 CPUsor1.5 CPUs, and the key is only set when a limit is set, likecpu_affinity. The new entry is documented indoc/api.rst.Tests: three unit tests with mocked
/procand/sysfiles (v2 leaf, tighter parent and container root, v1 in a container and-1for no limit, no limit at all).ruff check(0.15.22 as pinned in pre-commit) passes. The rest of the suite gives the same result with and without this change on my machine.Checked on Linux (WSL2, 20 logical CPUs, cgroup v2), Python 3.14 and 3.11:
systemd-run --user --scope -p CPUQuota=150%docker run --cpus=2I used an AI assistant (Claude) to help write this change. I ran the checks above myself.