[go] runtime: use floor instead of ceil for cgroup CPU limits in adjustCgroupGOMAXPROCS

0 views
Skip to first unread message

Gerrit Bot (Gerrit)

unread,
Dec 16, 2025, 9:37:45 PM (5 hours ago) Dec 16
to goph...@pubsubhelper.golang.org, golang-co...@googlegroups.com

Gerrit Bot has uploaded the change for review

Commit message

runtime: use floor instead of ceil for cgroup CPU limits in adjustCgroupGOMAXPROCS

## Summary

Change the computation to use floor instead of ceil, ensuring GOMAXPROCS never exceeds the available cgroup CPU quota under fractional values. Fractional CPU limits now round down, except values less than 2 still round up to 2 to preserve minimum parallelism.

This reduces contention and CPU throttling observed in production deployments with fractional CPU quotas.

Proposal: https://github.com/golang/go/issues/76835

Closes #76835

## Evidences

### Before change
<img width="475" height="800" alt="before" src="https://github.com/user-attachments/assets/51e6f332-4d59-479f-a0d4-3108bfe8db90" />

### After change
<img width="475" height="800" alt="after" src="https://github.com/user-attachments/assets/4d96b2f0-ef0b-4293-a430-d673fa9da852" />
Change-Id: I7603afabd78f21f67aa236ee57e7a1fc7332c7ef
GitHub-Last-Rev: 85d1142a82556fa0f2bffcf745b791bf3891606d
GitHub-Pull-Request: golang/go#76863

Change diff

diff --git a/src/runtime/cgroup_linux.go b/src/runtime/cgroup_linux.go
index 73e7363..2695e63 100644
--- a/src/runtime/cgroup_linux.go
+++ b/src/runtime/cgroup_linux.go
@@ -89,7 +89,10 @@
//
// 2. The average CPU cgroup throughput limit (average throughput =
// quota/period). A limit less than 2 is rounded up to 2, and any
- // fractional component is rounded up.
+ // fractional component is rounded down. The reason for rounding down is
+ // to avoid oversubscribing the cgroup when fractional quotas are used. Using
+ // floor keeps GOMAXPROCS within the effective quota, reducing the risk of
+ // throttling under sustained load.
//
// TODO: add rationale.

@@ -109,7 +112,7 @@
func adjustCgroupGOMAXPROCS(procs int32, cpu cgroup.CPU) int32 {
limit, ok, err := cgroup.ReadCPULimit(cpu)
if err == nil && ok {
- limit = ceil(limit)
+ limit = floor(limit)
limit = max(limit, 2)
if int32(limit) < procs {
procs = int32(limit)

Change information

Files:
  • M src/runtime/cgroup_linux.go
Change size: XS
Delta: 1 file changed, 5 insertions(+), 2 deletions(-)
Open in Gerrit

Related details

Attention set is empty
Submit Requirements:
  • requirement is not satisfiedCode-Review
  • requirement satisfiedNo-Unresolved-Comments
  • requirement is not satisfiedReview-Enforcement
  • requirement is not satisfiedTryBots-Pass
Inspect html for hidden footers to help with email filtering. To unsubscribe visit settings. DiffyGerrit
Gerrit-MessageType: newchange
Gerrit-Project: go
Gerrit-Branch: master
Gerrit-Change-Id: I7603afabd78f21f67aa236ee57e7a1fc7332c7ef
Gerrit-Change-Number: 730601
Gerrit-PatchSet: 1
Gerrit-Owner: Gerrit Bot <letsus...@gmail.com>
unsatisfied_requirement
satisfied_requirement
open
diffy

Gopher Robot (Gerrit)

unread,
Dec 16, 2025, 9:37:49 PM (5 hours ago) Dec 16
to Gerrit Bot, goph...@pubsubhelper.golang.org, golang-co...@googlegroups.com

Gopher Robot added 1 comment

Patchset-level comments
File-level comment, Patchset 1 (Latest):
Gopher Robot . unresolved

I spotted some possible problems with your PR:

  1. You have a long 259 character line in the commit message body. Please add line breaks to long lines that should be wrapped. Lines in the commit message body should be wrapped at ~76 characters unless needed for things like URLs or tables. (Note: GitHub might render long lines as soft-wrapped, so double-check in the Gerrit commit message shown above.)
2. It looks like you have a properly formated bug reference, but the convention is to put bug references at the bottom of the commit message, even if a bug is also mentioned in the body of the message.

Please address any problems by updating the GitHub PR.

When complete, mark this comment as 'Done' and click the [blue 'Reply' button](https://go.dev/wiki/GerritBot#i-left-a-reply-to-a-comment-in-gerrit-but-no-one-but-me-can-see-it) above. These findings are based on heuristics; if a finding does not apply, briefly reply here saying so.

To update the commit title or commit message body shown here in Gerrit, you must edit the GitHub PR title and PR description (the first comment) in the GitHub web interface using the 'Edit' button or 'Edit' menu entry there. Note: pushing a new commit to the PR will not automatically update the commit message used by Gerrit.

For more details, see:

(In general for Gerrit code reviews, the change author is expected to [log in to Gerrit](https://go-review.googlesource.com/login/) with a Gmail or other Google account and then close out each piece of feedback by marking it as 'Done' if implemented as suggested or otherwise reply to each review comment. See the [Review](https://go.dev/doc/contribute#review) section of the Contributing Guide for details.)

Open in Gerrit

Related details

Attention set is empty
Submit Requirements:
    • requirement is not satisfiedCode-Review
    • requirement is not satisfiedNo-Unresolved-Comments
    • requirement is not satisfiedReview-Enforcement
    • requirement is not satisfiedTryBots-Pass
    Inspect html for hidden footers to help with email filtering. To unsubscribe visit settings. DiffyGerrit
    Gerrit-MessageType: comment
    Gerrit-Project: go
    Gerrit-Branch: master
    Gerrit-Change-Id: I7603afabd78f21f67aa236ee57e7a1fc7332c7ef
    Gerrit-Change-Number: 730601
    Gerrit-PatchSet: 1
    Gerrit-Owner: Gerrit Bot <letsus...@gmail.com>
    Gerrit-CC: Gopher Robot <go...@golang.org>
    Gerrit-Comment-Date: Wed, 17 Dec 2025 02:37:43 +0000
    Gerrit-HasComments: Yes
    Gerrit-Has-Labels: No
    unsatisfied_requirement
    open
    diffy

    Gopher Robot (Gerrit)

    unread,
    Dec 16, 2025, 9:40:07 PM (5 hours ago) Dec 16
    to Gerrit Bot, goph...@pubsubhelper.golang.org, golang-co...@googlegroups.com

    Message from Gopher Robot

    Congratulations on opening your first change. Thank you for your contribution!

    Next steps:
    A maintainer will review your change and provide feedback. See
    https://go.dev/doc/contribute#review for more info and tips to get your
    patch through code review.

    Most changes in the Go project go through a few rounds of revision. This can be
    surprising to people new to the project. The careful, iterative review process
    is our way of helping mentor contributors and ensuring that their contributions
    have a lasting impact.

    During May-July and Nov-Jan the Go project is in a code freeze, during which
    little code gets reviewed or merged. If a reviewer responds with a comment like
    R=go1.11 or adds a tag like "wait-release", it means that this CL will be
    reviewed as part of the next development cycle. See https://go.dev/s/release
    for more details.

    Open in Gerrit

    Related details

    Attention set is empty
    Submit Requirements:
    • requirement is not satisfiedCode-Review
    • requirement is not satisfiedNo-Unresolved-Comments
    • requirement is not satisfiedReview-Enforcement
    • requirement is not satisfiedTryBots-Pass
    Inspect html for hidden footers to help with email filtering. To unsubscribe visit settings. DiffyGerrit
    Gerrit-MessageType: comment
    Gerrit-Project: go
    Gerrit-Branch: master
    Gerrit-Change-Id: I7603afabd78f21f67aa236ee57e7a1fc7332c7ef
    Gerrit-Change-Number: 730601
    Gerrit-PatchSet: 1
    Gerrit-Owner: Gerrit Bot <letsus...@gmail.com>
    Gerrit-CC: Gopher Robot <go...@golang.org>
    Gerrit-Comment-Date: Wed, 17 Dec 2025 02:40:00 +0000
    Gerrit-HasComments: No
    Gerrit-Has-Labels: No
    unsatisfied_requirement
    open
    diffy

    Gerrit Bot (Gerrit)

    unread,
    Dec 16, 2025, 9:54:01 PM (4 hours ago) Dec 16
    to goph...@pubsubhelper.golang.org, golang-co...@googlegroups.com
    Attention needed from Austin Clements, Keith Randall and Martin Möhrmann

    Gerrit Bot uploaded new patchset

    Gerrit Bot uploaded patch set #2 to this change.
    Open in Gerrit

    Related details

    Attention is currently required from:
    • Austin Clements
    • Keith Randall
    • Martin Möhrmann
    Submit Requirements:
    • requirement is not satisfiedCode-Review
    • requirement is not satisfiedNo-Unresolved-Comments
    • requirement is not satisfiedReview-Enforcement
    • requirement is not satisfiedTryBots-Pass
    Inspect html for hidden footers to help with email filtering. To unsubscribe visit settings. DiffyGerrit
    Gerrit-MessageType: newpatchset
    Gerrit-Project: go
    Gerrit-Branch: master
    Gerrit-Change-Id: I7603afabd78f21f67aa236ee57e7a1fc7332c7ef
    Gerrit-Change-Number: 730601
    Gerrit-PatchSet: 2
    Gerrit-Owner: Gerrit Bot <letsus...@gmail.com>
    Gerrit-Reviewer: Austin Clements <aus...@google.com>
    Gerrit-Reviewer: Keith Randall <k...@golang.org>
    Gerrit-Reviewer: Martin Möhrmann <moeh...@google.com>
    Gerrit-CC: Gopher Robot <go...@golang.org>
    Gerrit-Attention: Keith Randall <k...@golang.org>
    Gerrit-Attention: Martin Möhrmann <moeh...@google.com>
    Gerrit-Attention: Austin Clements <aus...@google.com>
    unsatisfied_requirement
    open
    diffy

    Marcos P. Sánchez (Gerrit)

    unread,
    Dec 16, 2025, 9:55:29 PM (4 hours ago) Dec 16
    to Gerrit Bot, goph...@pubsubhelper.golang.org, Austin Clements, Keith Randall, Martin Möhrmann, Gopher Robot, golang-co...@googlegroups.com
    Attention needed from Austin Clements, Keith Randall and Martin Möhrmann

    Marcos P. Sánchez added 1 comment

    Patchset-level comments
    File-level comment, Patchset 1:
    Gopher Robot . resolved

    I spotted some possible problems with your PR:

      1. You have a long 259 character line in the commit message body. Please add line breaks to long lines that should be wrapped. Lines in the commit message body should be wrapped at ~76 characters unless needed for things like URLs or tables. (Note: GitHub might render long lines as soft-wrapped, so double-check in the Gerrit commit message shown above.)
    2. It looks like you have a properly formated bug reference, but the convention is to put bug references at the bottom of the commit message, even if a bug is also mentioned in the body of the message.

    Please address any problems by updating the GitHub PR.

    When complete, mark this comment as 'Done' and click the [blue 'Reply' button](https://go.dev/wiki/GerritBot#i-left-a-reply-to-a-comment-in-gerrit-but-no-one-but-me-can-see-it) above. These findings are based on heuristics; if a finding does not apply, briefly reply here saying so.

    To update the commit title or commit message body shown here in Gerrit, you must edit the GitHub PR title and PR description (the first comment) in the GitHub web interface using the 'Edit' button or 'Edit' menu entry there. Note: pushing a new commit to the PR will not automatically update the commit message used by Gerrit.

    For more details, see:

    (In general for Gerrit code reviews, the change author is expected to [log in to Gerrit](https://go-review.googlesource.com/login/) with a Gmail or other Google account and then close out each piece of feedback by marking it as 'Done' if implemented as suggested or otherwise reply to each review comment. See the [Review](https://go.dev/doc/contribute#review) section of the Contributing Guide for details.)

    Marcos P. Sánchez

    Done

    Open in Gerrit

    Related details

    Attention is currently required from:
    • Austin Clements
    • Keith Randall
    • Martin Möhrmann
    Submit Requirements:
      • requirement is not satisfiedCode-Review
      • requirement satisfiedNo-Unresolved-Comments
      • requirement is not satisfiedReview-Enforcement
      • requirement is not satisfiedTryBots-Pass
      Inspect html for hidden footers to help with email filtering. To unsubscribe visit settings. DiffyGerrit
      Gerrit-MessageType: comment
      Gerrit-Project: go
      Gerrit-Branch: master
      Gerrit-Change-Id: I7603afabd78f21f67aa236ee57e7a1fc7332c7ef
      Gerrit-Change-Number: 730601
      Gerrit-PatchSet: 2
      Gerrit-Owner: Gerrit Bot <letsus...@gmail.com>
      Gerrit-Reviewer: Austin Clements <aus...@google.com>
      Gerrit-Reviewer: Keith Randall <k...@golang.org>
      Gerrit-Reviewer: Martin Möhrmann <moeh...@google.com>
      Gerrit-CC: Gopher Robot <go...@golang.org>
      Gerrit-CC: Marcos P. Sánchez <mpsanchez....@gmail.com>
      Gerrit-Attention: Keith Randall <k...@golang.org>
      Gerrit-Attention: Martin Möhrmann <moeh...@google.com>
      Gerrit-Attention: Austin Clements <aus...@google.com>
      Gerrit-Comment-Date: Wed, 17 Dec 2025 02:55:21 +0000
      Gerrit-HasComments: Yes
      Gerrit-Has-Labels: No
      Comment-In-Reply-To: Gopher Robot <go...@golang.org>
      unsatisfied_requirement
      satisfied_requirement
      open
      diffy

      Gerrit Bot (Gerrit)

      unread,
      Dec 16, 2025, 10:01:52 PM (4 hours ago) Dec 16
      to goph...@pubsubhelper.golang.org, golang-co...@googlegroups.com
      Attention needed from Austin Clements, Keith Randall and Martin Möhrmann

      Gerrit Bot uploaded new patchset

      Gerrit Bot uploaded patch set #3 to this change.
      Open in Gerrit

      Related details

      Attention is currently required from:
      • Austin Clements
      • Keith Randall
      • Martin Möhrmann
      Submit Requirements:
      • requirement is not satisfiedCode-Review
      • requirement satisfiedNo-Unresolved-Comments
      • requirement is not satisfiedReview-Enforcement
      • requirement is not satisfiedTryBots-Pass
      Inspect html for hidden footers to help with email filtering. To unsubscribe visit settings. DiffyGerrit
      Gerrit-MessageType: newpatchset
      Gerrit-Project: go
      Gerrit-Branch: master
      Gerrit-Change-Id: I7603afabd78f21f67aa236ee57e7a1fc7332c7ef
      Gerrit-Change-Number: 730601
      Gerrit-PatchSet: 3
      unsatisfied_requirement
      satisfied_requirement
      open
      diffy
      Reply all
      Reply to author
      Forward
      0 new messages