From ef935bd99178b0cb0f288f5a3824d7a11e5654e4 Mon Sep 17 00:00:00 2001 From: Giuseppe Scrivano Date: Mon, 20 Jul 2020 13:57:20 +0200 Subject: [PATCH] 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: https://github.com/kubernetes/kubernetes/issues/92855 Signed-off-by: Giuseppe Scrivano --- pkg/kubelet/cm/helpers_linux.go | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/pkg/kubelet/cm/helpers_linux.go b/pkg/kubelet/cm/helpers_linux.go index ce2d9a9670f..9b115ab5380 100644 --- a/pkg/kubelet/cm/helpers_linux.go +++ b/pkg/kubelet/cm/helpers_linux.go @@ -38,8 +38,11 @@ import ( ) const ( - // Taken from lmctfy https://github.com/google/lmctfy/blob/master/lmctfy/controllers/cpu_controller.cc - MinShares = 2 + // These limits are defined in the kernel: + // https://github.com/torvalds/linux/blob/0bddd227f3dc55975e2b8dfa7fc6f959b062a2c7/kernel/sched/sched.h#L427-L428 + MinShares = 2 + MaxShares = 262144 + SharesPerCPU = 1024 MilliCPUToCPU = 1000 @@ -88,6 +91,9 @@ func MilliCPUToShares(milliCPU int64) uint64 { if shares < MinShares { return MinShares } + if shares > MaxShares { + return MaxShares + } return uint64(shares) }