From 62a30709d287e9c4b77c88060c48e216de8492d5 Mon Sep 17 00:00:00 2001 From: Kir Kolyshkin Date: Sun, 31 May 2020 14:37:53 -0700 Subject: [PATCH] cgroups/fs/path: optimize The result of cgroupv1.FindCgroupMountpoint() call (which is relatively expensive) is only used in case raw.innerPath is absolute, so it only makes sense to call it in that case. This drastically reduces the number of calls to FindCgroupMountpoint during container start (from 116 to 62 in my setup). Signed-off-by: Kir Kolyshkin --- libcontainer/cgroups/fs/fs.go | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/libcontainer/cgroups/fs/fs.go b/libcontainer/cgroups/fs/fs.go index 245ce84f4c4..96ac93752e6 100644 --- a/libcontainer/cgroups/fs/fs.go +++ b/libcontainer/cgroups/fs/fs.go @@ -359,14 +359,14 @@ func getCgroupData(c *configs.Cgroup, pid int) (*cgroupData, error) { } func (raw *cgroupData) path(subsystem string) (string, error) { - mnt, err := cgroups.FindCgroupMountpoint(raw.root, subsystem) - // If we didn't mount the subsystem, there is no point we make the path. - if err != nil { - return "", err - } - // If the cgroup name/path is absolute do not look relative to the cgroup of the init process. if filepath.IsAbs(raw.innerPath) { + mnt, err := cgroups.FindCgroupMountpoint(raw.root, subsystem) + // If we didn't mount the subsystem, there is no point we make the path. + if err != nil { + return "", err + } + // Sometimes subsystems can be mounted together as 'cpu,cpuacct'. return filepath.Join(raw.root, filepath.Base(mnt), raw.innerPath), nil }