Skip to content

Conversation

@pegasas
Copy link
Contributor

@pegasas pegasas commented May 20, 2025

Description

I have added a new section titled "How CPU requests and limits work under the hood", which explains in detail:

  1. On Linux systems:
    How CPU requests are translated into cgroups v1 shares or cgroups v2 weight

How CPU limits are implemented using a quota system with a fixed 100ms period

An explanation of CPU limiting, including concrete examples

Explanation of how CPU throttling works

  1. On Windows systems:
    The different implementation of CPU requests and limits

Explanation of how CPU caps are used to enforce limits in Windows

Explanation of how it works on multi-core systems

Issue

fix: #50308

@k8s-ci-robot k8s-ci-robot requested review from salaxander and tengqm May 20, 2025 08:56
@k8s-ci-robot k8s-ci-robot added language/en Issues or PRs related to English language cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. labels May 20, 2025
@k8s-ci-robot
Copy link
Contributor

[APPROVALNOTIFIER] This PR is NOT APPROVED

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

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

Details 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

@k8s-ci-robot k8s-ci-robot added the size/M Denotes a PR that changes 30-99 lines, ignoring generated files. label May 20, 2025
@netlify
Copy link

netlify bot commented May 20, 2025

Pull request preview available for checking

Built without sensitive environment variables

Name Link
🔨 Latest commit 42b7320
🔍 Latest deploy log https://app.netlify.com/projects/kubernetes-io-main-staging/deploys/684d262aa2e5fe0009fc29e8
😎 Deploy Preview https://deploy-preview-50987--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.

## How CPU requests and limits work under the hood

### On Linux systems

Copy link
Contributor

Choose a reason for hiding this comment

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

Please wrap the long "lines" appropriately.
See https://sembr.org for the preferred line wrapping style.

@lmktfy
Copy link
Member

lmktfy commented May 21, 2025

I think this new section would be great as a page under https://kubernetes.io/docs/concepts/containers/

The existing task page can (should) link to that new concept page, and can also include a bit of a summary.

@salaxander
Copy link
Contributor

I think this new section would be great as a page under https://kubernetes.io/docs/concepts/containers/

The existing task page can (should) link to that new concept page, and can also include a bit of a summary.

Agree with @lmktfy here, I think this would be a great place for the content

@lmktfy
Copy link
Member

lmktfy commented May 22, 2025

@pegagas, would you be willing to adapt this per #50987 (comment) ?

You can, of course, keep all the words you've already written - it's just about where they go.


### On Linux systems

In Linux, Kubernetes uses cgroups (control groups) to enforce CPU requests and limits. See the [RedHat documentation on cgroups](https://access.redhat.com/documentation/en-us/red_hat_enterprise_linux/8/html/managing_monitoring_and_updating_the_kernel/managing-cpu-resources-with-control-groups_managing-monitoring-and-updating-the-kernel) for more details.
Copy link

@nprokopic nprokopic May 28, 2025

Choose a reason for hiding this comment

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

This access.redhat.com link redirects to https://docs.redhat.com/en/documentation/red_hat_enterprise_linux/8/html/managing_monitoring_and_updating_the_kernel/managing-cpu-resources-with-control-groups_managing-monitoring-and-updating-the-kernel, which then returns 404: Page not found.

Linking to https://docs.kernel.org/admin-guide/cgroup-v2.html would be more future-proof (although maybe not very beginner-friendly), as the above link is specific to RHEL v8.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

great suggestion. I will raise another commit for these changes.

Choose a reason for hiding this comment

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

Nice, thanks 🙂

Choose a reason for hiding this comment

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

And thanks for adding this to docs, very useful 🙏

@pegasas
Copy link
Contributor Author

pegasas commented May 29, 2025

@pegagas, would you be willing to adapt this per #50987 (comment) ?

You can, of course, keep all the words you've already written - it's just about where they go.

yes, I think it is good idea. will modify like that one.

@pegasas pegasas force-pushed the issues/50308 branch 2 times, most recently from d83abb9 to 648dc7b Compare May 29, 2025 05:20
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.

I have concerns about the technical accuracy of this PR. We shouldn't assume that container runtime rely on cgroups for CPU restrictions, even on Linux.

Overall, I think these new details belong in a separate page and not the overview concept page for containers.

Consider moving them to a leaf of the container concept.

We should not remove the existing useful content, such as explaining that containers are based on images.


### On Linux systems

In Linux, Kubernetes uses cgroups (control groups) to enforce CPU requests and limits. See the [RedHat documentation on cgroups](https://docs.kernel.org/admin-guide/cgroup-v2.html ) for more details.
Copy link
Member

Choose a reason for hiding this comment

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

This isn't RedHat documentation.


#### CPU Limits
- Windows implements CPU limits using CPU caps.
- The limit is expressed as a percentage of total CPU cycles across all processors.
Copy link
Member

Choose a reason for hiding this comment

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

All processors, or all online processors?

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 catch!
I will modified this one.

- For example, a limit of 0.5 CPU on a 2-core system means the container can use up to 25% of the total CPU cycles.
- Windows measures CPU usage over a longer time window compared to Linux, which can result in different throttling behavior.

{{< note >}}
Copy link
Member

Choose a reason for hiding this comment

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

I would not use a note here.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

sure. Done.


#### CPU Limits
- CPU limits are implemented using CPU quota and period.
- The period is hardcoded to 100ms (100,000 microseconds).
Copy link
Member

Choose a reason for hiding this comment

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

Is this true across all Linux nodes? Ideally, provide a citation.

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 should be more careful about this one. deleted.

Update content/en/docs/concepts/containers/_index.md

Co-authored-by: Tim Bannister <193443691+lmktfy@users.noreply.github.com>

Update content/en/docs/concepts/containers/_index.md

Co-authored-by: Tim Bannister <193443691+lmktfy@users.noreply.github.com>

Update content/en/docs/concepts/containers/_index.md

Co-authored-by: Tim Bannister <193443691+lmktfy@users.noreply.github.com>

Update content/en/docs/concepts/containers/_index.md

Co-authored-by: Tim Bannister <193443691+lmktfy@users.noreply.github.com>

modify according latest comments
@k8s-triage-robot
Copy link

The Kubernetes project currently lacks enough contributors to adequately respond to all PRs.

This bot triages PRs according to the following rules:

  • After 90d of inactivity, lifecycle/stale is applied
  • After 30d of inactivity since lifecycle/stale was applied, lifecycle/rotten is applied
  • After 30d of inactivity since lifecycle/rotten was applied, the PR is closed

You can:

  • Mark this PR as fresh with /remove-lifecycle stale
  • Close this PR with /close
  • Offer to help out with Issue Triage

Please send feedback to sig-contributor-experience at kubernetes/community.

/lifecycle stale

@k8s-ci-robot k8s-ci-robot added the lifecycle/stale Denotes an issue or PR has remained open with no activity and has become stale. label Sep 12, 2025
@k8s-triage-robot
Copy link

The Kubernetes project currently lacks enough active contributors to adequately respond to all PRs.

This bot triages PRs according to the following rules:

  • After 90d of inactivity, lifecycle/stale is applied
  • After 30d of inactivity since lifecycle/stale was applied, lifecycle/rotten is applied
  • After 30d of inactivity since lifecycle/rotten was applied, the PR is closed

You can:

  • Mark this PR as fresh with /remove-lifecycle rotten
  • Close this PR with /close
  • Offer to help out with Issue Triage

Please send feedback to sig-contributor-experience at kubernetes/community.

/lifecycle rotten

@k8s-ci-robot k8s-ci-robot added lifecycle/rotten Denotes an issue or PR that has aged beyond stale and will be auto-closed. and removed lifecycle/stale Denotes an issue or PR has remained open with no activity and has become stale. labels Oct 12, 2025
@k8s-triage-robot
Copy link

The Kubernetes project currently lacks enough active contributors to adequately respond to all issues and PRs.

This bot triages PRs according to the following rules:

  • After 90d of inactivity, lifecycle/stale is applied
  • After 30d of inactivity since lifecycle/stale was applied, lifecycle/rotten is applied
  • After 30d of inactivity since lifecycle/rotten was applied, the PR is closed

You can:

  • Reopen this PR with /reopen
  • Mark this PR as fresh with /remove-lifecycle rotten
  • Offer to help out with Issue Triage

Please send feedback to sig-contributor-experience at kubernetes/community.

/close

@k8s-ci-robot
Copy link
Contributor

@k8s-triage-robot: Closed this PR.

Details

In response to this:

The Kubernetes project currently lacks enough active contributors to adequately respond to all issues and PRs.

This bot triages PRs according to the following rules:

  • After 90d of inactivity, lifecycle/stale is applied
  • After 30d of inactivity since lifecycle/stale was applied, lifecycle/rotten is applied
  • After 30d of inactivity since lifecycle/rotten was applied, the PR is closed

You can:

  • Reopen this PR with /reopen
  • Mark this PR as fresh with /remove-lifecycle rotten
  • Offer to help out with Issue Triage

Please send feedback to sig-contributor-experience at kubernetes/community.

/close

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.

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

Labels

cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. language/en Issues or PRs related to English language lifecycle/rotten Denotes an issue or PR that has aged beyond stale and will be auto-closed. size/M Denotes a PR that changes 30-99 lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Document the meaning of CPU requests & limits

7 participants