Skip to content

cgroup2: expose CPU quota and period inspection - #401

Closed
linrl3 wants to merge 1 commit into
containerd:mainfrom
linrl3:codex/cgroup2-cpu-quota-inspection
Closed

linrl3 wants to merge 1 commit into
containerd:mainfrom
linrl3:codex/cgroup2-cpu-quota-inspection

Conversation

@linrl3

@linrl3 linrl3 commented Oct 22, 2026 •

Copy link
Copy Markdown
Contributor

Superseded by #404 after renaming the source branch to fix/cgroup2-cpu-quota. The replacement includes the CI dependency fix.

Applications can configure cgroup v2 CPU limits but cannot inspect the quota and period through the public API. Add Manager.CPUQuota() to read the current cgroup's cpu.max, returning both values in microseconds and math.MaxInt64 for an unlimited quota.

The reader requires both fields, preserves file and parsing errors, and reuses the existing parser without changing its write behavior. Ancestor limits are not combined. Includes README usage, filesystem tests, and kernel readback before and after switching to an unlimited quota.

Fixes #377.

Validation

On Linux arm64 (Ubuntu 26.04, cgroup v2, Go 1.22.12):

  • go test -exec sudo -race -count=1 -timeout=5m -json ./... passed, including the extended TestCgroupv2CpuStats against the kernel.
  • go test -race ./cgroup2 -run '^TestCPUQuota($|Whitespace$|InvalidContent$|ReadErrors$)' -v passed as non-root, including permission-denied handling.
  • golangci-lint run --verbose -D errcheck passed with v2.6.2 (0 issues).

The full run skipped existing environment-dependent tests (TestBlkioStat, TestSelfPath, TestPidPath, TestSystemd240, and TestCgroupv2IOController) and the permission-denied subtest when running as root; the latter passed in the separate non-root run.

Linux amd64 cross-build and go vet ./... also passed. The README example compiled for Linux arm64, and formatting/diff checks passed.

Upstream CI: cgroup v2 tests and lint passed on Go 1.22 and 1.23, as did the project and generated-file checks. Both cgroup v1 jobs failed before running tests, during Vagrant plugin setup: fog-json-1.5.0 requires json >= 2.19, but Vagrant bundles json-2.7.2. See the CI run.

AI assistance: Codex assisted with implementation, tests, documentation, and review.

Add Manager.CPUQuota to read the current cgroup's cpu.max through the
public API. Return the quota and period in microseconds, using the
existing parser's math.MaxInt64 representation for an unlimited quota.

Require both fields on reads and preserve file and parsing errors without
changing the shared parser's write behavior. Document that ancestor
limits are not combined.

Cover finite and unlimited quotas, configuration updates, malformed
content, read errors, and kernel readback. Add a README usage example.

Fixes containerd#377
Assisted-by: Codex

Signed-off-by: linrunlong <linrunlong@bytedance.com>
@linrl3

linrl3 commented Oct 22, 2026 •

Copy link
Copy Markdown
Contributor Author

Hi @fuweid, could you review this PR? Thanks!

@linrl3 linrl3 closed this Oct 22, 2026
@linrl3
linrl3 deleted the codex/cgroup2-cpu-quota-inspection branch October 22, 2026 17:02
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.

Add inspection for cgroup v2 CPU quota and period

1 participant