Skip to content

Commit c09ecf1

Browse files
authored
Merge pull request kubernetes#93248 from giuseppe/cgroup-set-max-shares
kubelet: clamp cpu.shares to max allowed
2 parents 5a529aa + ef935bd commit c09ecf1

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)