Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[release-4.14] OCPBUGS-18724: cm: reorder setting of sched_load_balance for sandbox slice #1693

Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
33 changes: 19 additions & 14 deletions pkg/kubelet/cm/cgroup_manager_linux.go
Original file line number Diff line number Diff line change
Expand Up @@ -464,6 +464,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 @@ -479,20 +498,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