From b032fead2202859b56dfdbaa70148110f5373eb4 Mon Sep 17 00:00:00 2001 From: Kir Kolyshkin Date: Thu, 25 Apr 2024 15:54:24 -0700 Subject: [PATCH] libct/cg/fs: don't write cpu_burst twice on ENOENT If CPU burst knob is non-existent, the current implementation (added in commit e1584831) still tries to set it again after setting the new CPU quota, which is useless (and we have to ignore ENOENT again). Fix this. Signed-off-by: Kir Kolyshkin --- libcontainer/cgroups/fs/cpu.go | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/libcontainer/cgroups/fs/cpu.go b/libcontainer/cgroups/fs/cpu.go index 727f7f9184f..fbbb8f34eef 100644 --- a/libcontainer/cgroups/fs/cpu.go +++ b/libcontainer/cgroups/fs/cpu.go @@ -89,9 +89,11 @@ func (s *CpuGroup) Set(path string, r *configs.Resources) error { if r.CpuBurst != nil { burst = strconv.FormatUint(*r.CpuBurst, 10) if err := cgroups.WriteFile(path, "cpu.cfs_burst_us", burst); err != nil { - // this is a special trick for burst feature, the current systemd and low version of kernel will not support it. - // So, an `no such file or directory` error would be raised, and we can ignore it . - if !errors.Is(err, unix.ENOENT) { + if errors.Is(err, unix.ENOENT) { + // If CPU burst knob is not available (e.g. + // older kernel), ignore it. + burst = "" + } else { // Sometimes when the burst to be set is larger // than the current one, it is rejected by the kernel // (EINVAL) as old_quota/new_burst exceeds the parent @@ -117,9 +119,7 @@ func (s *CpuGroup) Set(path string, r *configs.Resources) error { } if burst != "" { if err := cgroups.WriteFile(path, "cpu.cfs_burst_us", burst); err != nil { - if !errors.Is(err, unix.ENOENT) { - return err - } + return err } } }