-
Notifications
You must be signed in to change notification settings - Fork 2.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
cgroups/v1: optimize path usage #2494
cgroups/v1: optimize path usage #2494
Conversation
Needs rebase. |
f0e3d48
to
703c29d
Compare
rebased |
703c29d
to
90e3e6b
Compare
90e3e6b
to
6d90b53
Compare
@AkihiroSuda PTAL |
When paths are set, we only need to place the PID into proper cgroups, and we do know all the paths already. Both fs/d.path() and systemd/v1/getSubsystemPath() parse /proc/self/mountinfo, and the only reason they are used here is to check whether the subsystem is available. Use a much simpler/faster check instead. Frankly, I am not sure why the check is needed at all. Maybe it should be dropped. Also, for fs driver, since d is no longer used in this code path, move its initialization to after it. Signed-off-by: Kir Kolyshkin <[email protected]>
We call joinCgroups() from Apply, and in there we iterate through the list of subsystems, calling getSubsystemPath() for each. This is expensive, since every getSubsystemPath() involves parsing mountinfo. At the end of Apply(), we iterate through the list of subsystems to fill the m.paths, again calling getSubsystemPath() for every subsystem. As a result, we parse mountinfo about 20 times here. Let's find the paths first and reuse m.paths in joinCgroups(). While at it, since join() is just two calls now, inline it. Signed-off-by: Kir Kolyshkin <[email protected]>
In all these cases, getSubsystemPath() was already called, and its result stored in m.paths map. It makes no sense to not reuse it. Signed-off-by: Kir Kolyshkin <[email protected]>
6d90b53
to
940e154
Compare
continue | ||
} | ||
return err | ||
// XXX(kolyshkin@): why this check is needed? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What happens without this check?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As far as I can see, nothing bad. The paths
map is then used to write pid to cgroups, and WriteCgroupProc
has a check that path exists.
There may be other scenarios (with software that uses runc/libcontainer) I don't envision, and I have broken stuff in the past, so I am trying to be extra careful here.
So, ideally, I'd remove this, but maybe later, thus TODO
.
The new check is already 100x better than the old one, so this patch is a big improvement -- I'm just not sure if the check is needed at all.
@AkihiroSuda PTAL |
this is separated out from #2438 in order to make review easier
Limit the use of
getSubsystemPath()
andd.path()
functions, reusing them.paths
instead.See individual commit descriptions for details.
Number of times mountinfo was parsed during
runc --systemd-cgroup run
of a busybox container runningsleep 1
went down from 50 to 19 as a result of these changes.