Skip to content
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

Merged
merged 3 commits into from
Sep 11, 2020

Conversation

kolyshkin
Copy link
Contributor

@kolyshkin kolyshkin commented Jul 3, 2020

this is separated out from #2438 in order to make review easier

Limit the use of getSubsystemPath() and d.path() functions, reusing the m.paths instead.

See individual commit descriptions for details.

Number of times mountinfo was parsed during runc --systemd-cgroup run of a busybox container running sleep 1 went down from 50 to 19 as a result of these changes.

@mrunalp
Copy link
Contributor

mrunalp commented Jul 14, 2020

Needs rebase.

@kolyshkin kolyshkin force-pushed the cgroupv1-optimize-path branch from f0e3d48 to 703c29d Compare July 30, 2020 20:43
@kolyshkin
Copy link
Contributor Author

rebased

@kolyshkin kolyshkin force-pushed the cgroupv1-optimize-path branch from 703c29d to 90e3e6b Compare July 30, 2020 22:07
@kolyshkin kolyshkin force-pushed the cgroupv1-optimize-path branch from 90e3e6b to 6d90b53 Compare August 20, 2020 14:58
mrunalp
mrunalp previously approved these changes Aug 25, 2020
@kolyshkin
Copy link
Contributor Author

@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]>
continue
}
return err
// XXX(kolyshkin@): why this check is needed?
Copy link
Member

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?

Copy link
Contributor Author

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.

@kolyshkin
Copy link
Contributor Author

@AkihiroSuda PTAL

@AkihiroSuda AkihiroSuda merged commit 2cf8d24 into opencontainers:master Sep 11, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants