Export list of HugePageSizeUnits

This will allow others to import it instead of copying it.

Signed-off-by: Odin Ugedal <odin@ugedal.com>
This commit is contained in:
Odin Ugedal 2019-05-30 17:23:50 +02:00
parent c6445b1c1c
commit 6f77e35daf
No known key found for this signature in database
GPG Key ID: AFF9C8242CF7A7AF
1 changed files with 8 additions and 2 deletions

View File

@ -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)
}