From ae48c70aff5404ecf91144c6e3279c3893c9530a Mon Sep 17 00:00:00 2001 From: Rohit Jnagal Date: Mon, 2 Mar 2015 06:48:01 +0000 Subject: [PATCH] Report status of hierarchical memory accounting in validate output. We still report 'Supported and Recommended' even if hierarchical accounting is disabled. Most current distros don't enable it by default. --- validate/validate.go | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/validate/validate.go b/validate/validate.go index 6237d9fd..5534d0de 100644 --- a/validate/validate.go +++ b/validate/validate.go @@ -133,6 +133,31 @@ func areCgroupsPresent(available map[string]int, desired []string) (bool, string return true, "" } +func validateMemoryAccounting(available_cgroups map[string]int) string { + ok, _ := areCgroupsPresent(available_cgroups, []string{"memory"}) + 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 enabled == 1 { + return "\tHierarchical memory accounting enabled. Reported memory usage includes memory used by child containers.\n" + } + return "\tHierarchical memory accounting disabled. Memory usage does not include usage from child containers.\n" + +} + func validateCgroups() (string, string) { required_cgroups := []string{"cpu", "cpuacct"} recommended_cgroups := []string{"memory", "blkio", "cpuset", "devices", "freezer"} @@ -155,6 +180,7 @@ func validateCgroups() (string, string) { } out = fmt.Sprintf("Available cgroups: %v\n", available_cgroups) out += desc + out += validateMemoryAccounting(available_cgroups) return Recommended, out }