Repository navigation
Conversation
sipsma
force-pushed
the
sipsma/overlay-size-walk
branch
from
October 30, 2026 19:02
fdcbda3 to
070d8e7
Compare
containerd's overlay snapshotter walks a snapshot's whole upper directory at every commit, to store its size, and on every Usage of an active snapshot. It walks with continuity's fs.DiskUsage, which allocates a FileInfo and a joined path for each entry: 58-70 MiB in a cold build of dagger's CLI, from exec outputs and module extraction. The engine now wraps the overlay snapshotter with its own Commit and Usage, which size the upper directory with the same result (each distinct inode's allocated blocks, and the number of distinct inodes) by reading each directory's entries into a reused buffer and stating them relative to the directory's descriptor. Commit is otherwise containerd's: the same transaction on the engine's snapshotter store, storing the usage with the snapshot. The wrapper passes Cleanup through, which the asynchronous removal depends on. The system calls stay: they are most of the walk's CPU. Signed-off-by: Erik Sipsma <[email protected]>
…, and test the walk through the snapshotter Review found the walk checked the context only on entering a directory, so a canceled commit could finish a large directory's scan and commit; continuity checks at each entry, and so does this walk now. The allocation check also called the walk directly, so it passed with the wrapper unwired; it now measures an active snapshot's Usage and a Commit through the snapshotter the engine builds. Signed-off-by: Erik Sipsma <[email protected]>
…ading the root Review found that with the check at each entry only, an empty snapshot was sized and committed under a canceled context. continuity checks before the root too, so this walk now does; a test commits an empty snapshot under a canceled context. Signed-off-by: Erik Sipsma <[email protected]>
sipsma
force-pushed
the
sipsma/overlay-size-walk
branch
from
October 30, 2026 20:53
070d8e7 to
5f16b2c
Compare
Contributor
Author
|
Superseded by #15007, which carries these commits unchanged as part of the engine performance batch. |
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 snapshot commit makes the engine walk the snapshot's whole upper directory to record its size, and the walk allocates two objects per file. This PR keeps the walk and its result but drops those per-file allocations. That cuts about 40 MiB of the engine's allocations from a cold build of dagger's CLI.
Why
containerd's overlay snapshotter stores each committed snapshot's size, so it walks the upper directory at every
Commit, and again for everyUsageof an active snapshot. It walks with continuity'sfs.DiskUsage, which goes throughfilepath.Walk: anos.Lstatper entry, which allocates aFileInfo, and afilepath.Joinper entry for its path. In a cold build of dagger's CLI with dagger.io/go, most commits are exec outputs and extracted Go modules. There the walk allocated 54 MiB, about 1.5% of everything the engine allocated during the build. Every byte the engine allocates is work for its garbage collector.How
The engine wraps the overlay snapshotter it builds (in
engine/server/snapshotter.go) with its ownCommitandUsage:getdentsinto a pooled 32 KiB buffer. Itfstatats each entry relative to the directory's descriptor, into one reusedStat_t. An entry now costs only its name.fs.DiskUsage's: the allocated blocks of each distinct inode, the root's included, and the number of distinct inodes. Only non-directories with more than one link are tracked for de-duplication, since an inode with a single link, or a directory, can't appear twice in one tree.Commitis containerd's own otherwise: the same write transaction on the engine's snapshotter store, the samestorage.CommitActivewith the computed usage. It checks for cancellation before the walk and at each entry, as continuity does.Usageof a committed snapshot still returns the stored size; only an active snapshot is walked.Cleanupis passed through to the overlay, since containerd's metadata store calls it to remove deleted snapshots' directories under asynchronous removal.The system calls stay: they are most of the walk's CPU.
Numbers
Measured on one 16-core arm64 machine (AWS c8gd.4xlarge). Each run is a cold build of dagger's CLI with dagger.io/go on a fresh engine. Engines were built with and without this change from the same source, 4 runs each in alternating order.
Tests
TestOverlaySnapshotterUsagebuilds the overlay snapshotter throughnewSnapshotterand fills an active snapshot with:It checks that the size, while active and once committed, equals
fs.DiskUsage's. It also checks that sizing and committing a second such snapshot allocate under a quarter of whatfs.DiskUsagedoes for the same tree, which fails if the wrapper isn't wired in.TestOverlaySnapshotterUsageCanceledchecks that sizing or committing an empty snapshot under a canceled context fails and commits nothing.