Skip to content

Conversation

@iholder101
Copy link
Contributor

Description

Add blog post: new cgroup v1 to v2 CPU weight conversion formula.

Document what was done in kubernetes/kubernetes#131216 with proposed quadratic formula for better CPU weight granularity and priority alignment.

Issue

Closes: #52639.

@k8s-ci-robot k8s-ci-robot added cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. area/blog Issues or PRs related to the Kubernetes Blog subproject labels Oct 19, 2025
@k8s-ci-robot k8s-ci-robot added language/en Issues or PRs related to English language sig/docs Categorizes an issue or PR as relevant to SIG Docs. size/L Denotes a PR that changes 100-499 lines, ignoring generated files. labels Oct 19, 2025
@iholder101 iholder101 marked this pull request as draft October 19, 2025 13:19
@k8s-ci-robot k8s-ci-robot added the do-not-merge/work-in-progress Indicates that a PR should not merge because it is a work in progress. label Oct 19, 2025
@netlify
Copy link

netlify bot commented Oct 19, 2025

Pull request preview available for checking

Built without sensitive environment variables

Name Link
🔨 Latest commit 40a6197
🔍 Latest deploy log https://app.netlify.com/projects/kubernetes-io-main-staging/deploys/69032c187c42df0008ccd6c4
😎 Deploy Preview https://deploy-preview-52793--kubernetes-io-main-staging.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify project configuration.

@iholder101 iholder101 force-pushed the blog/cgroup-share-to-weight-conversion branch 2 times, most recently from 5ad59ff to 9599c25 Compare October 19, 2025 13:32
@iholder101 iholder101 marked this pull request as ready for review October 19, 2025 13:32
@k8s-ci-robot k8s-ci-robot removed the do-not-merge/work-in-progress Indicates that a PR should not merge because it is a work in progress. label Oct 19, 2025
@iholder101 iholder101 force-pushed the blog/cgroup-share-to-weight-conversion branch from 9599c25 to d045e7d Compare October 19, 2025 13:32
@iholder101
Copy link
Contributor Author

@lmktfy I've tried to add a mathematical graph as an image. This is pretty inelegant. Do you have an idea for adding graphs in a more idiomatic way? Thanks!

@iholder101
Copy link
Contributor Author

/test all

@k8s-ci-robot
Copy link
Contributor

@iholder101: No presubmit jobs available for kubernetes/website@main

In response to this:

/test all

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes-sigs/prow repository.

After a while, cgroup v1 was stared being replaced by its successor,
cgroup v2. In cgroup v2, the concept of CPU shares (which ranges from 2 to
262144, or from 2^1 to 2^18) was replaced with CPU weight (which ranges from
1 to 10000, or 10^10 to 10^4).
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
1 to 10000, or 10^10 to 10^4).
1 to 10000, or 10^1 to 10^4).

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You can use inline maths formulae BTW - see the pages about contributing to Kubernetes documentation.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@SergeyKanzhelev done! (it's actually 10^0 :) this is confusing).

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@lmktfy done.
Also, as asked in #52793 (comment), WDYT about the inlined pictures?

Copy link
Member

@lmktfy lmktfy left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks; here's some early feedback. We'll try to assign a blog writing buddy soon.

After a while, cgroup v1 was stared being replaced by its successor,
cgroup v2. In cgroup v2, the concept of CPU shares (which ranges from 2 to
262144, or from 2^1 to 2^18) was replaced with CPU weight (which ranges from
1 to 10000, or 10^10 to 10^4).
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You can use inline maths formulae BTW - see the pages about contributing to Kubernetes documentation.

@iholder101 iholder101 force-pushed the blog/cgroup-share-to-weight-conversion branch from d045e7d to 1db2891 Compare October 21, 2025 08:46
@iholder101
Copy link
Contributor Author

Thanks a lot everyone for your reviews!

Comment on lines 136 to 134
This change was implemented as an OCI-level implementation.
In other words, this is not implemented Kubernetes itself, therefore the
adoption of the new conversion formula depends solely on the OCI runtime
adoption.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

since we vendor the library in kubernetes I believe kubernetes is affected 1.35 and above as well for pod level cpu.weight, no? @SergeyKanzhelev

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, I think k8s is affected. But I didn't look deeper on what the effect will be and whether 1.35 will support both calculations.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wonder where this function is used in cadvisor: google/cadvisor#3737

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ok, it looks like that helper is not being used. @haircommander do you see any more issues here?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we do use a copy of the function here kubernetes/kubernetes@master/pkg/kubelet/cm/cgroup_v2_manager_linux.go#L174

Good point!
I can make a PR to change this conversion function.

@iholder101 iholder101 force-pushed the blog/cgroup-share-to-weight-conversion branch 2 times, most recently from fbfa379 to 83e49a4 Compare October 23, 2025 12:04
requesting 1 CPU has equal priority with system processes that live outside
of Kubernetes' scope.
However, in cgroup v2, the default CPU weight is `100`, but the current
formula converts 1 CPU (1024m) to only `~39` weight - less than 40% of the
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Did you mean the approximately equals symbol here? We can use the real symbol, .

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good point! Done

@iholder101 iholder101 force-pushed the blog/cgroup-share-to-weight-conversion branch 2 times, most recently from f2b314d to fa463f4 Compare October 29, 2025 09:02
@iholder101
Copy link
Contributor Author

@lmktfy I believe all is addressed. PTAL

Copy link
Contributor

@Serenity611 Serenity611 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewed for general proofreading and made some suggestions to align with the style guide, please let me know if you have any questions or concerns! :)

Copy link
Member

@SergeyKanzhelev SergeyKanzhelev left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

/lgtm

approving for sig node content.

@k8s-ci-robot k8s-ci-robot added the lgtm "Looks good to me", indicates that a PR is ready to be merged. label Oct 30, 2025
@k8s-ci-robot
Copy link
Contributor

LGTM label has been added.

Git tree hash: 33dbe84b0d2a91e51e2d10f1ffd72fcba40dca52

@k8s-ci-robot
Copy link
Contributor

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by: SergeyKanzhelev
Once this PR has been reviewed and has the lgtm label, please assign nate-double-u for approval. For more information see the Code Review Process.

The full list of commands accepted by this bot can be found here.

Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@iholder101 iholder101 force-pushed the blog/cgroup-share-to-weight-conversion branch from fa463f4 to 870b38d Compare October 30, 2025 09:12
Signed-off-by: Itamar Holder <iholder@redhat.com>
@k8s-ci-robot k8s-ci-robot removed the lgtm "Looks good to me", indicates that a PR is ready to be merged. label Oct 30, 2025
@iholder101 iholder101 force-pushed the blog/cgroup-share-to-weight-conversion branch from 870b38d to 40a6197 Compare October 30, 2025 09:12
@iholder101
Copy link
Contributor Author

@Serenity611 thanks for your review! I believe all is addressed.

@iholder101
Copy link
Contributor Author

I see that feature blog freeze is behind us. Does this have implications regarding this post?
I think it'd be valuable to make it publish in the v1.35 timeframe since the changes already apply.

@SergeyKanzhelev
Copy link
Member

/lgtm

@k8s-ci-robot k8s-ci-robot added the lgtm "Looks good to me", indicates that a PR is ready to be merged. label Nov 4, 2025
@k8s-ci-robot
Copy link
Contributor

LGTM label has been added.

Git tree hash: 3514edf1a3fe6b89cf0a4500497a01b712cdbe25

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area/blog Issues or PRs related to the Kubernetes Blog subproject cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. language/en Issues or PRs related to English language lgtm "Looks good to me", indicates that a PR is ready to be merged. sig/docs Categorizes an issue or PR as relevant to SIG Docs. size/L Denotes a PR that changes 100-499 lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Describe the migration from systemd's cgroup v1 CPU shares to v2 CPU weight formula

9 participants