Commit 820a717b authored by Odin Ugedal's avatar Odin Ugedal

Fix cgroup hugetlb size prefix for kB

Mitigation of the issue fixed in master where hugetlb prefix for "KiB" is "kB" in runc, but the correct is "KB" See https://github.com/opencontainers/runc/pull/2065 and https://github.com/kubernetes/kubernetes/pull/78495 for more info. --- The hugetlb cgroup control files (introduced here in 2012: https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/commit/?id=abb8206cb0773) use "KB" and not "kB" (https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/tree/mm/hugetlb_cgroup.c?h=v5.0#n349). The behavior in the kernel has not changed since the introduction, and the current code using "kB" will therefore fail on devices with small amounts of ram (see #77169) running a kernel with config flag CONFIG_HUGETLBFS=y As seen from the code in "mem_fmt" inside hugetlb_cgroup.c, only "KB", "MB" and "GB" are used, so the others may be removed as well. Here is a real world example of the files inside the "/sys/kernel/mm/hugepages/" directory: "hugepages-64kB" "hugepages-2048kB" "hugepages-32768kB" "hugepages-1048576kB" And the corresponding cgroup files: "hugetlb.64KB._____" "hugetlb.2MB._____" "hugetlb.32MB._____" "hugetlb.1GB._____"
parent e4983005
......@@ -51,7 +51,7 @@ const (
// hugePageSizeList is useful for converting to the hugetlb canonical unit
// which is what is expected when interacting with libcontainer
var hugePageSizeList = []string{"B", "kB", "MB", "GB", "TB", "PB"}
var hugePageSizeList = []string{"B", "KB", "MB", "GB", "TB", "PB"}
var RootCgroupName = CgroupName([]string{})
......
......@@ -200,6 +200,15 @@ func validateSystemRequirements(mountUtil mount.Interface) (features, error) {
// Takes the absolute name of the specified containers.
// Empty container name disables use of the specified container.
func NewContainerManager(mountUtil mount.Interface, cadvisorInterface cadvisor.Interface, nodeConfig NodeConfig, failSwapOn bool, devicePluginEnabled bool, recorder record.EventRecorder) (ContainerManager, error) {
// Mitigation of the issue fixed in master where hugetlb prefix for page sizes with "KiB"
// is "kB" in runc, but the correct is "KB"
// See https://github.com/opencontainers/runc/pull/2065
// and https://github.com/kubernetes/kubernetes/pull/78495
// for more info.
for i, pageSize := range fs.HugePageSizes {
fs.HugePageSizes[i] = strings.ReplaceAll(pageSize, "kB", "KB")
}
subsystems, err := GetCgroupSubsystems()
if err != nil {
return nil, fmt.Errorf("failed to get mounted cgroup subsystems: %v", err)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment