mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-07-23 11:50:44 +00:00
pkg/kubelet/cm/cgroup_manager: simplify setting hugetlb
Commit79be8be10e
made hugetlb settings optional if cgroup v2 is used and hugetlb is not available, fixing issue 92933. Note at that time this was only needed for v2, because for v1 the resources were set one-by-one, and only for supported resources. Commitd312ef7eb6
switched the code to using Set from runc/libcontainer cgroups manager, and expanded the check to cgroup v1 as well. Move this check earlier, to inside m.toResources, so instead of converting all hugetlb resources from ResourceConfig to libcontainers's Resources.HugetlbLimit, and then setting it to nil, we can skip the conversion entirely if hugetlb is not supported, thus not doing the work that is not needed. Signed-off-by: Kir Kolyshkin <kolyshkin@gmail.com>
This commit is contained in:
parent
59148e22d0
commit
11b0d57c93
@ -404,8 +404,34 @@ func (m *cgroupManagerImpl) toResources(resourceConfig *ResourceConfig) *libcont
|
||||
if resourceConfig.PidsLimit != nil {
|
||||
resources.PidsLimit = *resourceConfig.PidsLimit
|
||||
}
|
||||
// if huge pages are enabled, we set them in libcontainer
|
||||
// for each page size enumerated, set that value
|
||||
|
||||
m.maybeSetHugetlb(resourceConfig, resources)
|
||||
|
||||
// Ideally unified is used for all the resources when running on cgroup v2.
|
||||
// It doesn't make difference for the memory.max limit, but for e.g. the cpu controller
|
||||
// you can specify the correct setting without relying on the conversions performed by the OCI runtime.
|
||||
if resourceConfig.Unified != nil && libcontainercgroups.IsCgroup2UnifiedMode() {
|
||||
resources.Unified = make(map[string]string)
|
||||
for k, v := range resourceConfig.Unified {
|
||||
resources.Unified[k] = v
|
||||
}
|
||||
}
|
||||
return resources
|
||||
}
|
||||
|
||||
func (m *cgroupManagerImpl) maybeSetHugetlb(resourceConfig *ResourceConfig, resources *libcontainerconfigs.Resources) {
|
||||
// Check if hugetlb is supported.
|
||||
if libcontainercgroups.IsCgroup2UnifiedMode() {
|
||||
if !getSupportedUnifiedControllers().Has("hugetlb") {
|
||||
klog.V(6).InfoS("Optional subsystem not supported: hugetlb")
|
||||
return
|
||||
}
|
||||
} else if _, ok := m.subsystems.MountPoints["hugetlb"]; !ok {
|
||||
klog.V(6).InfoS("Optional subsystem not supported: hugetlb")
|
||||
return
|
||||
}
|
||||
|
||||
// For each page size enumerated, set that value.
|
||||
pageSizes := sets.NewString()
|
||||
for pageSize, limit := range resourceConfig.HugePageLimit {
|
||||
sizeString, err := v1helper.HugePageUnitSizeFromByteSize(pageSize)
|
||||
@ -429,16 +455,6 @@ func (m *cgroupManagerImpl) toResources(resourceConfig *ResourceConfig) *libcont
|
||||
Limit: uint64(0),
|
||||
})
|
||||
}
|
||||
// Ideally unified is used for all the resources when running on cgroup v2.
|
||||
// It doesn't make difference for the memory.max limit, but for e.g. the cpu controller
|
||||
// you can specify the correct setting without relying on the conversions performed by the OCI runtime.
|
||||
if resourceConfig.Unified != nil && libcontainercgroups.IsCgroup2UnifiedMode() {
|
||||
resources.Unified = make(map[string]string)
|
||||
for k, v := range resourceConfig.Unified {
|
||||
resources.Unified[k] = v
|
||||
}
|
||||
}
|
||||
return resources
|
||||
}
|
||||
|
||||
// Update updates the cgroup with the specified Cgroup Configuration
|
||||
@ -469,17 +485,6 @@ func (m *cgroupManagerImpl) Update(cgroupConfig *CgroupConfig) error {
|
||||
updateSystemdCgroupInfo(libcontainerCgroupConfig, cgroupConfig.Name)
|
||||
}
|
||||
|
||||
if unified {
|
||||
supportedControllers := getSupportedUnifiedControllers()
|
||||
if !supportedControllers.Has("hugetlb") {
|
||||
resources.HugetlbLimit = nil
|
||||
klog.V(6).InfoS("Optional subsystem not supported: hugetlb")
|
||||
}
|
||||
} else if _, ok := m.subsystems.MountPoints["hugetlb"]; !ok {
|
||||
resources.HugetlbLimit = nil
|
||||
klog.V(6).InfoS("Optional subsystem not supported: hugetlb")
|
||||
}
|
||||
|
||||
manager, err := m.adapter.newManager(libcontainerCgroupConfig, paths)
|
||||
if err != nil {
|
||||
return fmt.Errorf("failed to create cgroup manager: %v", err)
|
||||
|
Loading…
Reference in New Issue
Block a user