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

Eliminate redundant parsing of mountinfo #608

Merged
merged 3 commits into from
Apr 24, 2016

Conversation

inatatsu
Copy link
Contributor

@inatatsu inatatsu commented Mar 2, 2016

Fixes #631 (and the corresponding issue moby/moby#20851). The solutions here are:

  1. Skip parsing of mountinfo in FindCgroupMountpoint() and FindCgroupMountpointAndRoot() when a given cgroup subsystem is not enabled. The check is done by testing the subsystem is included in a result of ParseCgroupFile().
  2. Break the parsing loop in FindCgroupMountpointDir() when all the cgroup subsystems are found.
  3. Skip parsing of mountinfo in getSelinuxMountPoint() when the mount point is found, instead of invoking mount.GetMounts().
  4. Postpone parsing mountinfo by invoking rootfsParentMountPrivate() and getParentMount() until pivot_root() actually fails.

@LK4D4
Copy link
Contributor

LK4D4 commented Mar 4, 2016

rootfs parent mount change doesn't look like it preserves behaviour. Pivot root can be not called at all.

@inatatsu inatatsu force-pushed the reduce-parsing-mountinfo branch 4 times, most recently from 85e9042 to 7351913 Compare March 10, 2016 06:47
@inatatsu
Copy link
Contributor Author

@LK4D4 Thanks! Modified to invoke rootfsParentMountPrivate() at the original timing if config.NoPivotRoot is enabled.

@inatatsu inatatsu force-pushed the reduce-parsing-mountinfo branch 2 times, most recently from b4ee7b6 to d259a17 Compare March 14, 2016 04:20
@inatatsu
Copy link
Contributor Author

@LK4D4 Do I need any other fix?

txt := scanner.Text()
sepIdx := strings.Index(txt, " - ")
if sepIdx == -1 {
return selinuxfs
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is this correct to return here if the line is malformed? I'm not sure it should return.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@crosbymichael Thanks! I referred to cgroups.getCgroupMountsHelper() to parse mountinfo. Is it better to continue the loop here for robustness?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Probably, @LK4D4 @mrunalp what do you think?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we should continue and just skip the malformed lines.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@crosbymichael @mrunalp Fixed according to your comments. Thanks!

@inatatsu inatatsu force-pushed the reduce-parsing-mountinfo branch 5 times, most recently from f88d2c2 to 33cde44 Compare March 21, 2016 15:24
@inatatsu
Copy link
Contributor Author

@crosbymichael Do I need any other fix?

@LK4D4
Copy link
Contributor

LK4D4 commented Mar 21, 2016

LGTM
ping @rhatdan because it changes selinux parsing

@rhatdan
Copy link
Contributor

rhatdan commented Mar 21, 2016

LGTM, although I am a little worried about the fragility of the /proc/self/mountinfo parsing, but perhaps this was just as bad when we were using "github.com/docker/docker/pkg/mount"

@inatatsu inatatsu force-pushed the reduce-parsing-mountinfo branch 3 times, most recently from 447b004 to fbd388d Compare March 24, 2016 02:10
@inatatsu
Copy link
Contributor Author

@LK4D4 @rhatdan Thanks. Is this PR ready to be merged?

@rhatdan
Copy link
Contributor

rhatdan commented Mar 24, 2016

Fine with me.

if len(txt) < sepIdx+12 {
continue
}
if txt[sepIdx+3:sepIdx+12] != "selinuxfs" {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why not strings.Contains() or even just a comment explaining where these magic numbers come from?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This stuff runs like gazillion times per container stat, so even Splits and Contains in the top of Docker CPU usage :(

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In that case we should cache it, If we don't already. This only needs to be checked once, only way to change this state is to reboot the machine.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yup, it would be cool. Thanks for info @rhatdan

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could probably be an option to runc and if passed we can skip this check. We can also do the same for the systemd cgroups 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.

@cyphar @LK4D4 Thank you very much for your helpful suggestions. I think eliminating the magic numbers makes sense in this context to run a large number of containers, since the primary overhead of mount.GetMounts() comes from parsing all lines in mountinfo and creating corresponding objects. Fixed to use strings.Contains().

@rhatdan
Copy link
Contributor

rhatdan commented Mar 25, 2016

Looking at the code, this will only be called once. selinuxfs=unknown to start, First call gets set to "", then if it is in SELInux mode it will get set to the path. All future calls will return "" or SELINUXFSPATH. And never call this code.

@inatatsu inatatsu force-pushed the reduce-parsing-mountinfo branch 5 times, most recently from 2ea6286 to 962a0eb Compare April 1, 2016 04:34
@inatatsu
Copy link
Contributor Author

inatatsu commented Apr 1, 2016

@rhatdan Thank you for your suggestion. When SELinux is enabled, getSelinuxMountPoint() seems to be invoked once by every container, along the call path factory.StartInitialization() -> linuxStandardInit.Init() -> label.Init() -> selinux.SelinuxEnabled().

scanner := bufio.NewScanner(f)
for scanner.Scan() {
txt := scanner.Text()
sepIdx := strings.Index(txt, " - ")
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I realise this is exactly what the old code did, but Is this field always guaranteed to be -? Why not just look at the 9th field? Or is this to protect against spaces in the mountpoint names?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@cyphar Thanks. Replicated the original comment.

@inatatsu inatatsu force-pushed the reduce-parsing-mountinfo branch 2 times, most recently from 57fa063 to be38788 Compare April 5, 2016 01:55
@inatatsu
Copy link
Contributor Author

inatatsu commented Apr 5, 2016

@cyphar Does this look good to you?

@inatatsu inatatsu force-pushed the reduce-parsing-mountinfo branch 2 times, most recently from 2452f27 to c373395 Compare April 8, 2016 02:02
@inatatsu
Copy link
Contributor Author

inatatsu commented Apr 8, 2016

@LK4D4 @rhatdan @crosbymichael @mrunalp @cyphar Is this PR ready to be merged? Or, is any other fix required?

@inatatsu inatatsu force-pushed the reduce-parsing-mountinfo branch 6 times, most recently from cf4ed0d to 38b37ce Compare April 18, 2016 05:28
@crosbymichael
Copy link
Member

LGTM

Avoid parsing the whole lines of mountinfo after all mountpoints
of the target subsytems are found, or when the target subsystem
is not enabled.

Signed-off-by: Tatsushi Inagaki <e29253@jp.ibm.com>
Avoid parsing the whole lines of mountinfo after the mountpoint
is found.

Signed-off-by: Tatsushi Inagaki <e29253@jp.ibm.com>
Postpone parsing mountinfo until pivot_root() actually failed

Signed-off-by: Tatsushi Inagaki <e29253@jp.ibm.com>
@LK4D4
Copy link
Contributor

LK4D4 commented Apr 24, 2016

LGTM

@LK4D4 LK4D4 merged commit ae0fc15 into opencontainers:master Apr 24, 2016
stefanberger pushed a commit to stefanberger/runc that referenced this pull request Sep 8, 2017
Fix several format issues found by pdf and html
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.

None yet

7 participants