Skip to content

Commit

Permalink
cgroupv1/Apply: do not overuse path/getSubsystemPath
Browse files Browse the repository at this point in the history
When paths are already set, we only need to place the PID into proper
cgroups, and we already know all the cgroups path.

The fs function d.path(), and the systemd v1 function getSubsystemPath()
are both parsing /proc/self/mountinfo, and the only reason they are used
here is to check whether the subsystem is available.

Use a much simpler check instead.

Frankly, I am not sure why the check is needed at all. Maybe we just
need to drop it altogether.

Signed-off-by: Kir Kolyshkin <[email protected]>
  • Loading branch information
kolyshkin committed May 30, 2020
1 parent 8761859 commit da089c0
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 13 deletions.
9 changes: 4 additions & 5 deletions libcontainer/cgroups/fs/fs.go
Original file line number Diff line number Diff line change
Expand Up @@ -188,14 +188,13 @@ func (m *manager) Apply(pid int) (err error) {
m.paths = make(map[string]string)
if c.Paths != nil {
for name, path := range c.Paths {
_, err := d.path(name)
cgMap, err := cgroups.ParseCgroupFile("/proc/self/cgroup")
if err != nil {
if cgroupv1.IsNotFound(err) {
continue
}
return err
}
m.paths[name] = path
if _, ok := cgMap[name]; ok {
m.paths[name] = path
}
}
return cgroups.EnterPid(m.paths, pid)
}
Expand Down
14 changes: 6 additions & 8 deletions libcontainer/cgroups/systemd/v1.go
Original file line number Diff line number Diff line change
Expand Up @@ -140,16 +140,14 @@ func (m *legacyManager) Apply(pid int) error {

if c.Paths != nil {
paths := make(map[string]string)
cgMap, err := cgroups.ParseCgroupFile("/proc/self/cgroup")
if err != nil {
return err
}
for name, path := range c.Paths {
_, err := getSubsystemPath(m.cgroups, name)
if err != nil {
// Don't fail if a cgroup hierarchy was not found, just skip this subsystem
if cgroupv1.IsNotFound(err) {
continue
}
return err
if _, ok := cgMap[name]; ok {
paths[name] = path
}
paths[name] = path
}
m.paths = paths
return cgroups.EnterPid(m.paths, pid)
Expand Down

0 comments on commit da089c0

Please sign in to comment.