-
Notifications
You must be signed in to change notification settings - Fork 18.7k
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
Avoid fork on mount for overlay2 in common case #25824
Conversation
// name and path separator must be accounted for. The absolute | ||
// directories for work and diff are also accounted for along with a | ||
// buffer for other mount labels. | ||
if (len(d.home)+idLength+len(linkDir)+2)*len(splitLowers)+len(dir)*2+512 < pageSize { |
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.
Would it make sense to make this calculation more precise? I think even calculating the whole opts
even if it is not used would not be noticeably slow(good thing you have benchmarks to prove me wrong). If not then please add a comment that 512
is a buffer for the contants and label, I was initially confused by that.
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.
I had considered just calculating the opts using absolute paths optimistically, I think this might make even more sense considering I found the threshold to be over 60 layers.
c9bb1cb
to
d4016a3
Compare
Updated to optimistically create the mount data with absolute paths and only use relative paths when the mount data is larger than a page. Tested to make sure that the extra buffer is not needed when the mount data is fully computed (see dmcgowan/dsdbench@071a526#diff-c16a9df1a4a40f7564a79598949a5199R136). |
mountTarget = path.Join(id, "merged") | ||
} | ||
|
||
if len(mountData) > pageSize { |
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.
I think it will be much more readable if this branch is moved to L430. i.e.,
mountData = label.FormatMountLabel(opts, mountLabel)
if len(mountData) > pageSize {
...
}
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.
Agree, updated
In the common case where the user is using /var/lib/docker and an image with less than 60 layers, forking is not needed. Calculate whether absolute paths can be used and avoid forking to mount in those cases. Signed-off-by: Derek McGowan <derek@mcgstyle.net> (github: dmcgowan)
d4016a3
to
c13a985
Compare
LGTM |
1 similar comment
LGTM |
In the common case where the user is using /var/lib/docker and an image with less than 60 layers, forking is not needed. Calculate whether absolute paths can be used and avoid forking to mount in those cases. cherry-pick from: moby#25824 Signed-off-by: Derek McGowan <derek@mcgstyle.net> (github: dmcgowan) Signed-off-by: Lei Jitang <leijitang@huawei.com> (cherry picked from commit c13a985)
In the common case where the user is using /var/lib/docker and
an image with less than 60 layers, forking is not needed. Calculate
whether absolute paths can be used and avoid forking to mount in
those cases.
I do not have any statistics of what percentage of images
are less than 60 layers deep, but my guess is a vast majority and
even larger majority when accounting for images which are run most often.
Mount Benchmarks
Overlay2 (pre-change) vs Overlay2 (updated)
Overlay vs Overlay2 (updated)
AUFS vs Overlay2 (updated)
AUFS vs Overlay2 (pre-change)
Note
overlay
will always mount faster thanoverlay2
for a larger number of lower directories since it can only have one lower directory (which it achieves at the expense of duplicating files). These are the first benchmarks I have done with aufs vs overlay2 so I included the benchmark comparison with the pre-changed overlay2.Benchmarks done with https://github.com/dmcgowan/dsdbench