Repository navigation
Conversation
sipsma
force-pushed
the
sipsma/path-walk-lookups
branch
from
October 30, 2026 19:02
a4ae4f3 to
dad5315
Compare
overlayEntryState read each opaque attribute through continuity's LGetxattr, which allocates a 128-byte buffer per call, for every directory. The marker is the single byte "y", so the attribute is now read into a one-byte buffer: a longer value doesn't fit, and isn't the marker. Signed-off-by: Erik Sipsma <[email protected]>
…ectory Each file copied from an overlay, as an exec's files mount copies each of its files, first found the lowest layer its ancestors leave visible: an lstat, and for directories two xattr reads, of every ancestor in every layer down to one that hides the layers below it. Only a directory's walk needs that bound. The view shows a non-directory, so the topmost layer holding it is the one the view shows, and no ancestor hides it. A non-directory is now looked up from the top layer down, and the ancestors' layers aren't read. In a cold first build of dagger's CLI that was 0.60 CPU-s and 111 MiB of allocations, most of the files mounts' cost. Signed-off-by: Erik Sipsma <[email protected]>
…ctory opaque Signed-off-by: Erik Sipsma <[email protected]>
rootPath resolved every path through continuity's RootPath, which lstats each component from the root, and allocates for each, to follow symlinks within the root. An exec's files mount resolves each of its files that way twice: its path in the source snapshot's view, and its name in the mount's directory. Most paths hold no symlinks, and such a path resolves to itself. One openat2 that refuses symlinks now settles that case; a path it refuses, or can't settle, is walked as before. A path that is already clean is no longer cleaned again, which allocated too. Signed-off-by: Erik Sipsma <[email protected]>
After each exec, the mount-stub cleanup resolved every stub path, and then its parent, from the rootfs root with continuity's RootPath, one lstat and several allocations per path component. A mount at a deep path such as a Go module's directory leaves a chain of stubs, so the same prefixes were walked again for every stub and its parent. It also read each stub directory to see whether it was empty. Now each directory above a stub is checked once per cleanup, with an lstat that must find a real directory, not a symlink, and a directory stub is removed only if rmdir finds it empty. A stub whose path the exec replaced with a symlink is left alone, as are stubs below a parent it replaced with one: before, the cleanup followed the symlink and could remove an empty directory or file the exec had made elsewhere. Signed-off-by: Erik Sipsma <[email protected]>
layercopy settles a path that holds no symlinks with one openat2 that refuses symlinks, where continuity's RootPath lstats each component from the root and allocates for each. The engine still walked every path that way elsewhere on each exec: its rootfs setup and working directory, its mount-stub setup, its user lookup and read-only mounts, and the Directory.stat and File mounts that builds run between execs. fsxutil.RootPath is continuity's RootPath with that lookup first, and the lookup moves there from layercopy. A path it refuses, or can't settle, is walked by continuity as before, so the result is continuity's in every case. That includes a path with a ".." component: continuity takes a ".." after the symlinks before it, so the lookup leaves such a path to continuity rather than cleaning the ".." away first. Signed-off-by: Erik Sipsma <[email protected]>
sipsma
force-pushed
the
sipsma/path-walk-lookups
branch
from
October 30, 2026 20:53
dad5315 to
0a9c8e1
Compare
Contributor
Author
|
Superseded by #15007, which carries these commits unchanged. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Every exec the engine runs pays for path resolution before it starts and after it ends. A per-package Go build runs thousands of small execs, each with deep mounts. In such a build, a few of these code paths were walking the same directories again and again, one
lstatand a few allocations per path component. This PR removes most of that repeated work. It answers the same questions with fewer syscalls and allocations, and it changes no results except one cleanup fix, described below.Measured one at a time, the changes cut about 250 MiB of engine allocations per cold first build of dagger's own CLI, and one-line edits rebuild about 0.1–0.2 s faster.
What changes
Resolving a path that holds no symlinks takes one syscall. Code that resolves a path inside a root (a snapshot, a container's rootfs) used continuity's
fs.RootPath.RootPathwalks the path from the root, onelstatper component, so that a symlink stays inside the root. Most paths hold no symlinks, and such a path resolves to itself. Oneopenat2withRESOLVE_NO_SYMLINKS(plusO_NOFOLLOWwhen the caller doesn't follow a final symlink) now settles that case. Success, orENOENT, means every component that exists is a real directory, so the answer is the root joined with the path. Everything else goes toRootPathexactly as before:ENOSYSon kernels before 5.6;..component.RootPathapplies..after the symlinks before it, so cleaning the..away first could change the answer.The fast path first lands in layercopy's
rootPath. A files mount calls it twice per file: once in the source snapshot's merged view, once in the mount's directory. It then moves toutil/fsxutilasfsxutil.RootPath, a drop-in forRootPath, used by:Directory.statandFilemounts.The result is
RootPath's in every case. The only other caller left on the hot path is containerd's ownmount.Mount.Layercopy reads ancestors' overlay layers only to copy a directory. For each source path,
source.selectBasecomputed the lowest overlay layer the path's ancestors leave visible (overlayAncestorMinLayer). That took anlstat, plus xattr reads, of every ancestor in every layer. Only a directory's walk needs that bound, to skip lower layers an ancestor hides (#13848). For anything else, the merged view already shows the file. So the topmost layer that holds it is the one the view shows, and no ancestor can hide that layer. Non-directories are now looked up from the top layer down, and a whiteout above them still stops the lookup. Layercopy never followed overlay redirects or metacopy, so nothing about them changes.The opaque marker is read into a one-byte buffer.
overlayEntryStatereadstrusted.overlay.opaque, thenuser.overlay.opaque, for every ancestor directory it probes, in every layer. The marker is the single bytey. So a one-byte stack buffer is enough: a longer value fails withERANGE, and isn't the marker anyway. Before, each read allocated a buffer.The mount-stub cleanup checks each parent once. Before an exec, the engine creates empty files and directories ("stubs") for mount targets that don't exist yet, together with any missing parents. After the exec,
MountStubsCleanerremoves the ones left empty and restores their parents' timestamps. A deep mount target such as a module under/go/pkg/modleaves a chain of about 5 stubs. The cleanup resolved each stub, and then its parent, with a fullRootPathwalk, and read each stub directory to see whether it was empty. Now it checks each directory above a stub once per cleanup, with a memoizedlstatthat must find a real directory, not a symlink. A stub directory is removed only ifrmdirsucceeds;ENOTEMPTYmeans the exec wrote into it.This makes the cleanup stricter. It now leaves alone a stub the exec replaced with a symlink, and anything below a directory the exec replaced with one. Before, it followed such a symlink and could remove an empty file or directory the exec had made elsewhere in its rootfs. Nothing outside the rootfs was at risk.
Numbers
Each change was measured on its own, against the same engine without it, building dagger's CLI with the per-package Go build (github.com/dagger/go) at GC target 100.
runtime.MemStatstotals from one profiled run per arm.openat2lookup costs kernel time of its own.Tests
TestRootPathResolvesAsContinuity, in bothutil/layercopyandutil/fsxutil, compares the fast path withRootPath, answer and error...after a symlink and after a file.TestRootPathWithoutSymlinksTakesOneLookup, in both packages, checks that a 5-component path costs at most 3 allocations. It takes 2, against 56 without the fast path. It assumes a kernel withopenat2, as CI's kernels have.TestCopyFileFromOverlayLinksTheVisibleLayerchecks that a file is hard-linked from the layer the merged view shows. It covers a file above a layer with a stale copy and a file below an upper layer that lacks it. It also checks that no ancestor's layers are read.TestOverlayEntryStateOpaqueMarkerchecks thatymarks a directory opaque, whilen,yy,yesand no value don't. The longer values reach the one-byte read'sERANGEpath.TestMountStubsCleanerchecks: