deps: bump cgroups to v0.0.3, fix a few regressions#4785
Merged
thaJeztah merged 2 commits intoopencontainers:mainfrom Jun 19, 2025
Merged
deps: bump cgroups to v0.0.3, fix a few regressions#4785thaJeztah merged 2 commits intoopencontainers:mainfrom
thaJeztah merged 2 commits intoopencontainers:mainfrom
Conversation
11b933a to
f1abb32
Compare
There was a problem hiding this comment.
Pull Request Overview
This PR bumps the cgroups dependency to v0.0.3 to address JSON incompatibility and CPU shares conversion issues. The changes include updating dependency versions in go.mod, revising the CPU shares to CPU weight conversion logic in the test helper, and adjusting corresponding tests accordingly.
Reviewed Changes
Copilot reviewed 4 out of 8 changed files in this pull request and generated no comments.
| File | Description |
|---|---|
| tests/integration/update.bats | Updated test comments and assertion functions to reflect revised conversion logic. |
| tests/integration/helpers.bash | Modified CPU shares conversion, using a multi-line awk script to compute weight. |
| libcontainer/factory_linux.go | Added a safeguard to initialize Resources when nil for cgroup v1 compatibility. |
| go.mod | Bumped the dependency version for github.com/opencontainers/cgroups to v0.0.3. |
AkihiroSuda
approved these changes
Jun 19, 2025
Since opencontainers/cgroups v0.0.2 (commit b206a01), all stuct Resources fields are annotated with "omitempty" attribute. As a result, the loaded configuration may have Resources == nil. It is totally OK (rootless containers may have no resources configured) except since commit 6c5441e, cgroup v1 fs manager requires Resources to be set in the call to NewManager (this is a cgroup v1 deficiency, or maybe our implementation deficiency, or both). To work around this, let's add code to ensure Resources is never nil after loading from state.json. Signed-off-by: Kir Kolyshkin <[email protected]>
For changelog, see https://github.com/opencontainers/cgroups/releases/tag/v0.0.3 This fixes two runc issues: 1. JSON incompatibility introduced in cgroups v0.0.2 (see opencontainers/cgroups#22). 2. Bad CPU shares to CPU weight conversion (see opencontainers#4772). Due to item 2, modify some tests accordingly. Signed-off-by: Kir Kolyshkin <[email protected]>
jaredledvina
added a commit
to DataDog/runc
that referenced
this pull request
Sep 23, 2025
Signed-off-by: Jared Ledvina <[email protected]>
jaredledvina
added a commit
to DataDog/runc
that referenced
this pull request
Sep 23, 2025
Signed-off-by: Jared Ledvina <[email protected]>
jaredledvina
added a commit
to DataDog/runc
that referenced
this pull request
Sep 23, 2025
Signed-off-by: Jared Ledvina <[email protected]>
This was referenced Sep 23, 2025
Merged
1 task
dd-mergequeue Bot
pushed a commit
to DataDog/datadog-agent
that referenced
this pull request
Dec 15, 2025
… >= 1.3.2 (#43760) ### What does this PR do? - Auto-detect which conversion formula the runtime uses by comparing the actual cgroup weight with expected values from Docker Inspect - Support both old (linear) and new (quadratic) formulas for backward compatibility - Use the geometric mean approach for the inverse formula to handle ceil() rounding New formula for shares to weight: ``` exponent = (l² + 125l) / 612 - 7/34; weight = ceil(10^exponent) ``` We are doing inverse formula to get shares from weight in this PR: See **cpuWeightToSharesNonLinear**(cpuWeight float64) function, same logic can be found in other reference: https://github.com/cloudfoundry/guardian/blob/main/rundmc/utils.go ### Motivation On cgroups v2 systems running runc >= 1.3.2 (or crun >= 1.23), the docker.cpu.shares metric reported incorrect values. For example, containers configured with the default --cpu-shares 1024 would show 2597 instead of 1024. Root cause: The container runtime changed its CPU shares-to-weight conversion formula from linear to quadratic (opencontainers/runc#4785), but the Agent was still using the old linear inverse formula. Old formula (linear): - weight = 1 + ((shares - 2) * 9999) / 262142 - 1024 shares → weight 39 (incorrect default mapping) New formula (quadratic): - Uses logarithmic function to ensure min, max, and default values align - 1024 shares → weight 100 (correct default mapping) The Datadog Agent was using the old formula's inverse to convert weight back to shares, causing: - With new runc: weight 100 → 2597 shares (should be 1024) ### Describe how you validated your changes unit test ### Additional Notes Co-authored-by: minyi.zhu <[email protected]>
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.
For changelog, see https://github.com/opencontainers/cgroups/releases/tag/v0.0.3
This fixes three runc issues:
Since cgroups v0.0.2, Cgroups.Resources may be nil after loading, but cgroup v1 fs manager is not expecting it.
JSON incompatibility introduced in cgroups v0.0.2 (see Remove annotations from Resources cgroups#22).
Bad CPU shares to CPU weight conversion (see Conversion of cgroup v1 CPU shares to v2 CPU weight causes workloads to have low CPU priority #4772).
Due to item 3, modify some tests accordingly (see #4772).
Fixes: #4772