-
Notifications
You must be signed in to change notification settings - Fork 2.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
libct/cg: support hugetlb rsvd #4073
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,8 @@ | ||
package fs | ||
|
||
import ( | ||
"errors" | ||
"os" | ||
"strconv" | ||
|
||
"github.com/opencontainers/runc/libcontainer/cgroups" | ||
|
@@ -19,8 +21,23 @@ func (s *HugetlbGroup) Apply(path string, _ *configs.Resources, pid int) error { | |
} | ||
|
||
func (s *HugetlbGroup) Set(path string, r *configs.Resources) error { | ||
const suffix = ".limit_in_bytes" | ||
skipRsvd := false | ||
|
||
for _, hugetlb := range r.HugetlbLimit { | ||
if err := cgroups.WriteFile(path, "hugetlb."+hugetlb.Pagesize+".limit_in_bytes", strconv.FormatUint(hugetlb.Limit, 10)); err != nil { | ||
prefix := "hugetlb." + hugetlb.Pagesize | ||
val := strconv.FormatUint(hugetlb.Limit, 10) | ||
if err := cgroups.WriteFile(path, prefix+suffix, val); err != nil { | ||
return err | ||
} | ||
if skipRsvd { | ||
continue | ||
} | ||
if err := cgroups.WriteFile(path, prefix+".rsvd"+suffix, val); err != nil { | ||
if errors.Is(err, os.ErrNotExist) { | ||
skipRsvd = true | ||
Comment on lines
+36
to
+38
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. the idea here, those |
||
continue | ||
} | ||
return err | ||
} | ||
} | ||
|
@@ -32,24 +49,29 @@ func (s *HugetlbGroup) GetStats(path string, stats *cgroups.Stats) error { | |
if !cgroups.PathExists(path) { | ||
return nil | ||
} | ||
rsvd := ".rsvd" | ||
hugetlbStats := cgroups.HugetlbStats{} | ||
for _, pageSize := range cgroups.HugePageSizes() { | ||
usage := "hugetlb." + pageSize + ".usage_in_bytes" | ||
value, err := fscommon.GetCgroupParamUint(path, usage) | ||
again: | ||
prefix := "hugetlb." + pageSize + rsvd | ||
|
||
value, err := fscommon.GetCgroupParamUint(path, prefix+".usage_in_bytes") | ||
if err != nil { | ||
if rsvd != "" && errors.Is(err, os.ErrNotExist) { | ||
rsvd = "" | ||
goto again | ||
} | ||
Comment on lines
+60
to
+63
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. For getting the stats, we prefer |
||
return err | ||
} | ||
hugetlbStats.Usage = value | ||
|
||
maxUsage := "hugetlb." + pageSize + ".max_usage_in_bytes" | ||
value, err = fscommon.GetCgroupParamUint(path, maxUsage) | ||
value, err = fscommon.GetCgroupParamUint(path, prefix+".max_usage_in_bytes") | ||
if err != nil { | ||
return err | ||
} | ||
hugetlbStats.MaxUsage = value | ||
|
||
failcnt := "hugetlb." + pageSize + ".failcnt" | ||
value, err = fscommon.GetCgroupParamUint(path, failcnt) | ||
value, err = fscommon.GetCgroupParamUint(path, prefix+".failcnt") | ||
if err != nil { | ||
return err | ||
} | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This can be a
break
instead, so the loop stops.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We don't want to stop the loop here. We want to write all
hugetlb.XXX.limit_in_bytes
and, if available, allhugetlb.XXX.rsvd.limit_in_bytes
as well (and we're looping over XXX).