From 89a87adb38c7d53b80eb0e5e6bc44ae2e70018a5 Mon Sep 17 00:00:00 2001 From: Boris Popovschi Date: Tue, 10 Mar 2020 15:28:45 +0200 Subject: [PATCH] Changed hugetlb pagesizes info source Signed-off-by: Boris Popovschi --- libcontainer/cgroups/fs2/fs2.go | 2 +- libcontainer/cgroups/fs2/hugetlb.go | 20 ++++++++++++-------- 2 files changed, 13 insertions(+), 9 deletions(-) diff --git a/libcontainer/cgroups/fs2/fs2.go b/libcontainer/cgroups/fs2/fs2.go index 069ff235..76ec3c0c 100644 --- a/libcontainer/cgroups/fs2/fs2.go +++ b/libcontainer/cgroups/fs2/fs2.go @@ -126,7 +126,7 @@ func (m *manager) GetStats() (*cgroups.Stats, error) { } // hugetlb (since kernel 5.6) if _, ok := m.controllers["hugetlb"]; ok { - if err := statHugeTlb(m.dirPath, &st, m.config); err != nil { + if err := statHugeTlb(m.dirPath, &st); err != nil { errs = append(errs, err) } } diff --git a/libcontainer/cgroups/fs2/hugetlb.go b/libcontainer/cgroups/fs2/hugetlb.go index 7975b10d..c7610c0a 100644 --- a/libcontainer/cgroups/fs2/hugetlb.go +++ b/libcontainer/cgroups/fs2/hugetlb.go @@ -25,30 +25,34 @@ func setHugeTlb(dirPath string, cgroup *configs.Cgroup) error { return nil } -func statHugeTlb(dirPath string, stats *cgroups.Stats, cgroup *configs.Cgroup) error { +func statHugeTlb(dirPath string, stats *cgroups.Stats) error { + hugePageSizes, err := cgroups.GetHugePageSize() + if err != nil { + return errors.Wrap(err, "failed to fetch hugetlb info") + } hugetlbStats := cgroups.HugetlbStats{} - for _, entry := range cgroup.Resources.HugetlbLimit { - usage := strings.Join([]string{"hugetlb", entry.Pagesize, "current"}, ".") + for _, pagesize := range hugePageSizes { + usage := strings.Join([]string{"hugetlb", pagesize, "current"}, ".") value, err := fscommon.GetCgroupParamUint(dirPath, usage) if err != nil { - return errors.Wrapf(err, "failed to parse hugetlb.%s.current file", entry.Pagesize) + return errors.Wrapf(err, "failed to parse hugetlb.%s.current file", pagesize) } hugetlbStats.Usage = value - fileName := strings.Join([]string{"hugetlb", entry.Pagesize, "events"}, ".") + fileName := strings.Join([]string{"hugetlb", pagesize, "events"}, ".") filePath := filepath.Join(dirPath, fileName) contents, err := ioutil.ReadFile(filePath) if err != nil { - return errors.Wrapf(err, "failed to parse hugetlb.%s.events file", entry.Pagesize) + return errors.Wrapf(err, "failed to parse hugetlb.%s.events file", pagesize) } _, value, err = fscommon.GetCgroupParamKeyValue(string(contents)) if err != nil { - return errors.Wrapf(err, "failed to parse hugetlb.%s.events file", entry.Pagesize) + return errors.Wrapf(err, "failed to parse hugetlb.%s.events file", pagesize) } hugetlbStats.Failcnt = value - stats.HugetlbStats[entry.Pagesize] = hugetlbStats + stats.HugetlbStats[pagesize] = hugetlbStats } return nil