From f718e39ab962a3ee74324fe1275d7ded6a099ae2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Anders=20F=20Bj=C3=B6rklund?= Date: Tue, 15 Sep 2020 12:54:39 +0200 Subject: [PATCH] Make sure CFS_BANDWIDTH is available for --cpus --- pkg/drivers/kic/oci/oci.go | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) diff --git a/pkg/drivers/kic/oci/oci.go b/pkg/drivers/kic/oci/oci.go index b388140f71a6..ebc32b6af47e 100644 --- a/pkg/drivers/kic/oci/oci.go +++ b/pkg/drivers/kic/oci/oci.go @@ -156,7 +156,24 @@ func CreateContainerNode(p CreateParams) error { runArgs = append(runArgs, "--security-opt", "apparmor=unconfined") } - runArgs = append(runArgs, fmt.Sprintf("--cpus=%s", p.CPUs)) + cpuCfsPeriod := true + cpuCfsQuota := true + if runtime.GOOS == "linux" { + if _, err := os.Stat("/sys/fs/cgroup/cpu/cpu.cfs_period_us"); os.IsNotExist(err) { + cpuCfsPeriod = false + } + if _, err := os.Stat("/sys/fs/cgroup/cpu/cpu.cfs_quota_us"); os.IsNotExist(err) { + cpuCfsQuota = false + } + if !cpuCfsPeriod || !cpuCfsQuota { + // requires CONFIG_CFS_BANDWIDTH + glog.Warning("Your kernel does not support CPU cfs period/quota or the cgroup is not mounted.") + } + } + + if cpuCfsPeriod && cpuCfsQuota { + runArgs = append(runArgs, fmt.Sprintf("--cpus=%s", p.CPUs)) + } memcgSwap := true if runtime.GOOS == "linux" {