Skip to content

Commit

Permalink
Merge pull request #2711 from kolyshkin/cgroupv2
Browse files Browse the repository at this point in the history
validateMemoryAccounting: fix for cgroup v2
  • Loading branch information
bobbypage authored Nov 7, 2020
2 parents bf8fe42 + 7080f82 commit 0f8972f
Showing 1 changed file with 15 additions and 11 deletions.
26 changes: 15 additions & 11 deletions validate/validate.go
Original file line number Diff line number Diff line change
Expand Up @@ -156,18 +156,22 @@ func validateMemoryAccounting(availableCgroups map[string]int) string {
if !ok {
return "\tHierarchical memory accounting status unknown: memory cgroup not enabled.\n"
}
mnt, err := cgroups.FindCgroupMountpoint("/", "memory")
if err != nil {
return "\tHierarchical memory accounting status unknown: memory cgroup not mounted.\n"
}
hier, err := ioutil.ReadFile(path.Join(mnt, "memory.use_hierarchy"))
if err != nil {
return "\tHierarchical memory accounting status unknown: hierarchy interface unavailable.\n"
}
var enabled int
n, err := fmt.Sscanf(string(hier), "%d", &enabled)
if err != nil || n != 1 {
return "\tHierarchical memory accounting status unknown: hierarchy interface unreadable.\n"
if cgroups.IsCgroup2UnifiedMode() {
enabled = 1
} else {
mnt, err := cgroups.FindCgroupMountpoint("/", "memory")
if err != nil {
return "\tHierarchical memory accounting status unknown: memory cgroup not mounted.\n"
}
hier, err := ioutil.ReadFile(path.Join(mnt, "memory.use_hierarchy"))
if err != nil {
return "\tHierarchical memory accounting status unknown: hierarchy interface unavailable.\n"
}
n, err := fmt.Sscanf(string(hier), "%d", &enabled)
if err != nil || n != 1 {
return "\tHierarchical memory accounting status unknown: hierarchy interface unreadable.\n"
}
}
if enabled == 1 {
return "\tHierarchical memory accounting enabled. Reported memory usage includes memory used by child containers.\n"
Expand Down

0 comments on commit 0f8972f

Please sign in to comment.