From 6f77e35daf7d7a25cdd7dd02d2b85047c83458b9 Mon Sep 17 00:00:00 2001 From: Odin Ugedal Date: Thu, 30 May 2019 17:23:50 +0200 Subject: [PATCH] Export list of HugePageSizeUnits This will allow others to import it instead of copying it. Signed-off-by: Odin Ugedal --- libcontainer/cgroups/utils.go | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/libcontainer/cgroups/utils.go b/libcontainer/cgroups/utils.go index 2a9e59f2..ec79ae76 100644 --- a/libcontainer/cgroups/utils.go +++ b/libcontainer/cgroups/utils.go @@ -22,6 +22,13 @@ const ( CgroupProcesses = "cgroup.procs" ) +// HugePageSizeUnitList is a list of the units used by the linux kernel when +// naming the HugePage control files. +// https://www.kernel.org/doc/Documentation/cgroup-v1/hugetlb.txt +// TODO Since the kernel only use KB, MB and GB; TB and PB should be removed, +// depends on https://github.com/docker/go-units/commit/a09cd47f892041a4fac473133d181f5aea6fa393 +var HugePageSizeUnitList = []string{"B", "KB", "MB", "GB", "TB", "PB"} + // https://www.kernel.org/doc/Documentation/cgroup-v1/cgroups.txt func FindCgroupMountpoint(cgroupPath, subsystem string) (string, error) { mnt, _, err := FindCgroupMountpointAndRoot(cgroupPath, subsystem) @@ -422,14 +429,13 @@ func GetHugePageSize() ([]string, error) { func getHugePageSizeFromFilenames(fileNames []string) ([]string, error) { var pageSizes []string - sizeList := []string{"B", "KB", "MB", "GB", "TB", "PB"} for _, fileName := range fileNames { nameArray := strings.Split(fileName, "-") pageSize, err := units.RAMInBytes(nameArray[1]) if err != nil { return []string{}, err } - sizeString := units.CustomSize("%g%s", float64(pageSize), 1024.0, sizeList) + sizeString := units.CustomSize("%g%s", float64(pageSize), 1024.0, HugePageSizeUnitList) pageSizes = append(pageSizes, sizeString) }