Changed hugetlb pagesizes info source

Signed-off-by: Boris Popovschi <zyqsempai@mail.ru>
This commit is contained in:
Boris Popovschi 2020-03-10 15:28:45 +02:00
parent d804611d05
commit 89a87adb38
2 changed files with 13 additions and 9 deletions

View File

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

View File

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