Skip to content

cgroup2: expose CPU quota and period inspection - #404

Open
linrl3 wants to merge 2 commits into
containerd:mainfrom
linrl3:fix/cgroup2-cpu-quota
Open

linrl3 wants to merge 2 commits into
containerd:mainfrom
linrl3:fix/cgroup2-cpu-quota

Conversation

@linrl3

@linrl3 linrl3 commented Oct 22, 2026 •

Copy link
Copy Markdown
Contributor

Add Manager.CPUQuota() to inspect the current cgroup's cpu.max. It returns the quota and period in microseconds, with math.MaxInt64 representing an unlimited quota. The reader preserves file/parse errors and does not combine ancestor limits. Includes README usage, filesystem tests, and kernel readback before and after switching to an unlimited quota.

Fixes #377. Replaces #401 after renaming the source branch.

A separate CI commit pins fog-json to 1.2.0 so Vagrant can install vagrant-libvirt with its bundled json gem. This follows the fix already used by containerd/containerd. Previously both v1 jobs failed during environment setup, before running tests.

Validation

  • Linux arm64, Go 1.22.12: full go test -exec sudo -race -count=1 -timeout=5m ./... passed, including real-kernel quota readback. Existing environment-dependent tests were skipped; permission-denied handling passed in a separate non-root run.
  • Fork CI: all eight checks passed, including cgroup v1 and v2 tests and cgctl builds on Go 1.22 and 1.23, both lint jobs, project checks, and generated-file checks.
  • Linux amd64 cross-build and go vet ./..., README example compilation, actionlint, shell syntax, and formatting/diff checks passed.

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>
The cgroup v1 jobs fail while installing vagrant-libvirt because
fog-json 1.5.0 requires json >= 2.19, but Vagrant has already activated
its bundled json 2.7.2. The VM never starts and no tests run.

Pin fog-json to 1.2.0 before installing vagrant-libvirt, replacing any
previously registered version restored from the Vagrant cache. This
follows the fix used in containerd/containerd commit
b84460e50769d336bf62dca976eb23f984f7d10b.

Assisted-by: Codex
Signed-off-by: linrunlong <linrunlong@bytedance.com>
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