Skip to content

util/layercopy: share lowerdir answers across a copy's sources - #14967

Closed
sipsma wants to merge 4 commits into
mainfrom
sipsma/layercopy-share-lowerdir-answers
Closed

sipsma wants to merge 4 commits into
mainfrom
sipsma/layercopy-share-lowerdir-answers

Conversation

@sipsma

@sipsma sipsma commented Oct 29, 2026

Copy link
Copy Markdown
Contributor

A files mount links each file into its directory with one Copier, one CopyFile per file, each from its own snapshot's overlay. Before linking a file, the copy finds the lowest layer still visible below it by asking every layer about every ancestor directory: an lstat and up to two getxattr calls each. The files' snapshots usually share most of their layers, so a mount of ~1,400 files asked the same lowerdirs the same questions again for every file.

A lowerdir can't change while an overlay uses it, so one copy now keeps each lowerdir path's answer and shares it across its sources. Upperdirs aren't added to this shared cache. Each source still picks the same layer as before, and errors are unchanged.

Measured: the copy stays linear in the number of files, at about 30% less time per file (copying from N 6-layer overlays sharing 5 layers: 109–138 µs per file before, 70–99 µs after, for N from 100 to 2,800). In a Go link step with ~1,400 mounted package archives, building the exec's spec went from 104 ms to 78.5 ms. That was too small to show in the builds' overall wall time.

The tests check that each source still links its file from its own visible layer when sources stack shared lowerdirs differently, and that a second source asks the filesystem only about its own layers.

A files mount links each file into its directory with one Copier, one
CopyFile per file, each from its own snapshot's overlay. Before it links
a file, selectBase finds the lowest layer still visible below the file's
directory, asking every layer about every ancestor directory: an lstat
and up to two getxattr calls each. The files' snapshots share most of
their layers, the image the container they came from was built on, so a
link step's ~1,400 archives asked the same layers the same questions
again for each file.

A lowerdir can't change while an overlay uses it, so keep each lowerdir
path's answer for the whole copy, shared by its sources. An upperdir's
answers are still asked each time.

Signed-off-by: Erik Sipsma <[email protected]>
…wers

The shared-lowerdir test checked each source still links from its own
visible layer, which held without the shared answers too. Check that a
second source on the same lowerdir asks only about its own layers, and
that an upperdir's answers are never kept.

Signed-off-by: Erik Sipsma <[email protected]>
The test checked which answers the copy kept, which still held if the
copy stopped reading them back. Count the paths a second source asks the
filesystem about: its own layers, never the lowerdir the first source
already asked about.

Signed-off-by: Erik Sipsma <[email protected]>
@sipsma

sipsma commented Oct 30, 2026

Copy link
Copy Markdown
Contributor Author

Folded unchanged into #15007, the engine performance batch; continuing there.

@sipsma sipsma closed this Oct 30, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant