Skip to content

Commit

Permalink
Merge pull request #1696 from openshift-cherrypick-robot/cherry-pick-…
Browse files Browse the repository at this point in the history
…1693-to-release-4.13

[release-4.13] OCPBUGS-18829: cm: reorder setting of sched_load_balance for sandbox slice
  • Loading branch information
openshift-merge-bot[bot] committed Nov 21, 2023
2 parents fd9ae58 + fea1484 commit aa37255
Showing 1 changed file with 19 additions and 14 deletions.
33 changes: 19 additions & 14 deletions pkg/kubelet/cm/cgroup_manager_linux.go
Expand Up @@ -461,6 +461,25 @@ func (m *cgroupManagerImpl) Create(cgroupConfig *CgroupConfig) error {
return err
}

// Disable cpuset.sched_load_balance for all cgroups Kubelet creates.
// This way, CRI can disable sched_load_balance for pods that must have load balance
// disabled, but the slices can contain all cpus (as the guaranteed cpus are known dynamically).
// Note: this should be done before Apply(-1) below, as Apply contains cpusetCopyIfNeeded(), which will
// populate the cpuset with the parent's cpuset. However, it will be initialized to sched_load_balance=1
// which will cause the kernel to move all cpusets out of their isolated sched_domain, causing unnecessary churn.
if m.cpuLoadBalanceDisable && !libcontainercgroups.IsCgroup2UnifiedMode() {
path := manager.Path("cpuset")
if path == "" {
return fmt.Errorf("Failed to find cpuset for newly created cgroup")
}
if err := os.Mkdir(path, 0o755); err != nil && !os.IsNotExist(err) {
return fmt.Errorf("failed to create cpuset for newly created cgroup: %w", err)
}
if err := cgroups.WriteFile(path, "cpuset.sched_load_balance", "0"); err != nil {
return err
}
}

// Apply(-1) is a hack to create the cgroup directories for each resource
// subsystem. The function [cgroups.Manager.apply()] applies cgroup
// configuration to the process with the specified pid.
Expand All @@ -476,20 +495,6 @@ func (m *cgroupManagerImpl) Create(cgroupConfig *CgroupConfig) error {
if err := manager.Set(libcontainerCgroupConfig.Resources); err != nil {
utilruntime.HandleError(fmt.Errorf("cgroup manager.Set failed: %w", err))
}

// Disable cpuset.sched_load_balance for all cgroups Kubelet creates.
// This way, CRI can disable sched_load_balance for pods that must have load balance
// disabled, but the slices can contain all cpus (as the guaranteed cpus are known dynamically).
if m.cpuLoadBalanceDisable && !libcontainercgroups.IsCgroup2UnifiedMode() {
path := manager.Path("cpuset")
if path == "" {
return fmt.Errorf("Failed to find cpuset for newly created cgroup")
}
if err := cgroups.WriteFile(path, "cpuset.sched_load_balance", "0"); err != nil {
return err
}
}

return nil
}

Expand Down

0 comments on commit aa37255

Please sign in to comment.