From 7317e002509098aa89fa7e1020429762bc1d560c Mon Sep 17 00:00:00 2001 From: Kir Kolyshkin Date: Fri, 22 May 2020 17:28:39 -0700 Subject: [PATCH 1/2] pkg/sysinfo: fix error path in checkCgroupPids In case we failed to find out what version of cgroup we have, it makes little sense to return that pids cgroup controller is available, and yet the current code does it. Fix this. Signed-off-by: Kir Kolyshkin --- pkg/sysinfo/sysinfo_linux.go | 1 + 1 file changed, 1 insertion(+) diff --git a/pkg/sysinfo/sysinfo_linux.go b/pkg/sysinfo/sysinfo_linux.go index 269ea686a..e6b608ef3 100644 --- a/pkg/sysinfo/sysinfo_linux.go +++ b/pkg/sysinfo/sysinfo_linux.go @@ -231,6 +231,7 @@ func checkCgroupPids(quiet bool) cgroupPids { cgroup2, err := cgroupv2.Enabled() if err != nil { logrus.Errorf("Failed to check cgroups version: %v", err) + return cgroupPids{} } if !cgroup2 { _, err := cgroups.FindCgroupMountpoint("", "pids") From 6b5ae787c1f78b07f29aa52614841b1717d67374 Mon Sep 17 00:00:00 2001 From: Kir Kolyshkin Date: Fri, 22 May 2020 17:30:12 -0700 Subject: [PATCH 2/2] pkg/sysinfo/checkCgroupPids: speedup For some reason this code chose not to use information already fetched, and call cgroups.FindCgroupMountpoint() instead. This is not a cheap call, as it has to parse the whole nine yards of /proc/self/mountinfo, and the info it tries to get (whether the pids controller is present) is already available from cgMounts map. Signed-off-by: Kir Kolyshkin --- pkg/sysinfo/sysinfo_linux.go | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/pkg/sysinfo/sysinfo_linux.go b/pkg/sysinfo/sysinfo_linux.go index e6b608ef3..fcb3cab72 100644 --- a/pkg/sysinfo/sysinfo_linux.go +++ b/pkg/sysinfo/sysinfo_linux.go @@ -40,7 +40,7 @@ func New(quiet bool) *SysInfo { sysInfo.cgroupCPUInfo = checkCgroupCPU(cgMounts, quiet) sysInfo.cgroupBlkioInfo = checkCgroupBlkioInfo(cgMounts, quiet) sysInfo.cgroupCpusetInfo = checkCgroupCpusetInfo(cgMounts, quiet) - sysInfo.cgroupPids = checkCgroupPids(quiet) + sysInfo.cgroupPids = checkCgroupPids(cgMounts, quiet) } _, ok := cgMounts["devices"] @@ -227,17 +227,17 @@ func checkCgroupCpusetInfo(cgMounts map[string]string, quiet bool) cgroupCpusetI } // checkCgroupPids reads the pids information from the pids cgroup mount point. -func checkCgroupPids(quiet bool) cgroupPids { +func checkCgroupPids(cgMounts map[string]string, quiet bool) cgroupPids { cgroup2, err := cgroupv2.Enabled() if err != nil { logrus.Errorf("Failed to check cgroups version: %v", err) return cgroupPids{} } if !cgroup2 { - _, err := cgroups.FindCgroupMountpoint("", "pids") - if err != nil { + _, ok := cgMounts["pids"] + if !ok { if !quiet { - logrus.Warn(err) + logrus.Warn("unable to find pids cgroup in mounts") } return cgroupPids{} }