Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 5 additions & 2 deletions src/runtime/cgroup_linux.go
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,10 @@ func defaultGOMAXPROCS(ncpu int32) int32 {
//
// 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.

Expand All @@ -109,7 +112,7 @@ func defaultGOMAXPROCS(ncpu int32) int32 {
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)
Expand Down