Skip to content

Commit 44c6f36

Browse files
authored
Merge pull request #9255 from afbjorklund/cpus-cfs
Make sure CFS_BANDWIDTH is available for --cpus
2 parents b9f3638 + f718e39 commit 44c6f36

File tree

1 file changed

+18
-1
lines changed

1 file changed

+18
-1
lines changed

Diff for: pkg/drivers/kic/oci/oci.go

+18-1
Original file line numberDiff line numberDiff line change
@@ -156,7 +156,24 @@ func CreateContainerNode(p CreateParams) error {
156156
runArgs = append(runArgs, "--security-opt", "apparmor=unconfined")
157157
}
158158

159-
runArgs = append(runArgs, fmt.Sprintf("--cpus=%s", p.CPUs))
159+
cpuCfsPeriod := true
160+
cpuCfsQuota := true
161+
if runtime.GOOS == "linux" {
162+
if _, err := os.Stat("/sys/fs/cgroup/cpu/cpu.cfs_period_us"); os.IsNotExist(err) {
163+
cpuCfsPeriod = false
164+
}
165+
if _, err := os.Stat("/sys/fs/cgroup/cpu/cpu.cfs_quota_us"); os.IsNotExist(err) {
166+
cpuCfsQuota = false
167+
}
168+
if !cpuCfsPeriod || !cpuCfsQuota {
169+
// requires CONFIG_CFS_BANDWIDTH
170+
glog.Warning("Your kernel does not support CPU cfs period/quota or the cgroup is not mounted.")
171+
}
172+
}
173+
174+
if cpuCfsPeriod && cpuCfsQuota {
175+
runArgs = append(runArgs, fmt.Sprintf("--cpus=%s", p.CPUs))
176+
}
160177

161178
memcgSwap := true
162179
if runtime.GOOS == "linux" {

0 commit comments

Comments
 (0)