-
Notifications
You must be signed in to change notification settings - Fork 147
/
Copy pathlinux_cgroups_relative_hugetlb.go
54 lines (47 loc) · 1.25 KB
/
linux_cgroups_relative_hugetlb.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
package main
import (
"github.com/mndrix/tap-go"
rspec "github.com/opencontainers/runtime-spec/specs-go"
"github.com/opencontainers/runtime-tools/cgroups"
"github.com/opencontainers/runtime-tools/validation/util"
)
func main() {
page := "2MB"
var pageSize uint64 = 2 * 1024 * 1024 // 2MB in bytes
limit := 100 * pageSize
g := util.GetDefaultGenerator()
g.SetLinuxCgroupsPath(cgroups.RelCgroupPath)
g.AddLinuxResourcesHugepageLimit(page, limit)
err := util.RuntimeOutsideValidate(g, func(config *rspec.Spec, state *rspec.State) error {
t := tap.New()
t.Header(0)
cg, err := cgroups.FindCgroup()
t.Ok((err == nil), "find hugetlb cgroup")
if err != nil {
t.Diagnostic(err.Error())
t.AutoPlan()
return nil
}
lhd, err := cg.GetHugepageLimitData(state.Pid, config.Linux.CgroupsPath)
t.Ok((err == nil), "get hugetlb cgroup data")
if err != nil {
t.Diagnostic(err.Error())
t.AutoPlan()
return nil
}
found := false
for _, lhl := range lhd {
if lhl.Pagesize == page {
found = true
t.Ok(lhl.Limit == limit, "hugepage limit is set correctly")
t.Diagnosticf("expect: %d, actual: %d", limit, lhl.Limit)
}
}
t.Ok(found, "hugepage limit found")
t.AutoPlan()
return nil
})
if err != nil {
util.Fatal(err)
}
}