Skip to content

Commit

Permalink
pkg/sysinfo/checkCgroupPids: speedup
Browse files Browse the repository at this point in the history
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 <[email protected]>
  • Loading branch information
kolyshkin committed May 23, 2020
1 parent 7317e00 commit 6b5ae78
Showing 1 changed file with 5 additions and 5 deletions.
10 changes: 5 additions & 5 deletions pkg/sysinfo/sysinfo_linux.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"]
Expand Down Expand Up @@ -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{}
}
Expand Down

0 comments on commit 6b5ae78

Please sign in to comment.