Skip to content

Commit ef935bd

Browse files
committed
kubelet: clamp cpu shares to max allowed
clamp the max cpu.shares to the maximum value allowed by the kernel. It is not an issue when using cgroupfs, as the kernel will anyway make sure the value is not out of range and automatically clamp it, systemd has an additional check that prevents the cgroup creation. Closes: kubernetes#92855 Signed-off-by: Giuseppe Scrivano <[email protected]>
1 parent 43fbe17 commit ef935bd

File tree

1 file changed

+8
-2
lines changed

1 file changed

+8
-2
lines changed

pkg/kubelet/cm/helpers_linux.go

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,8 +38,11 @@ import (
3838
)
3939

4040
const (
41-
// Taken from lmctfy https://github.com/google/lmctfy/blob/master/lmctfy/controllers/cpu_controller.cc
42-
MinShares = 2
41+
// These limits are defined in the kernel:
42+
// https://github.com/torvalds/linux/blob/0bddd227f3dc55975e2b8dfa7fc6f959b062a2c7/kernel/sched/sched.h#L427-L428
43+
MinShares = 2
44+
MaxShares = 262144
45+
4346
SharesPerCPU = 1024
4447
MilliCPUToCPU = 1000
4548

@@ -88,6 +91,9 @@ func MilliCPUToShares(milliCPU int64) uint64 {
8891
if shares < MinShares {
8992
return MinShares
9093
}
94+
if shares > MaxShares {
95+
return MaxShares
96+
}
9197
return uint64(shares)
9298
}
9399

0 commit comments

Comments
 (0)