Repository navigation
Support warm image cache for erofs snapshotter - #13813
Conversation
| // the source layer's uncompressed digest (diffID) so the runtime finds it | ||
| // by the same key the unpacker labels the extraction Prepare with. | ||
| if convertOpts.layerCacheDir != "" { | ||
| if err := teeLayerCache(convertOpts.layerCacheDir, uncompressedDesc.Digest, blobPath); err != nil { |
There was a problem hiding this comment.
I wonder could we have another dedicated command to just copy a committed layer into the cache instead of reusing convert command? since in principle, every OCI-unpacked erofs snapshot (rather than just converted erofs native images) can be moved to the distributed cache directory too.
There was a problem hiding this comment.
Yup, though about this too, convert is a bit overloaded.
Extracted into separate subcommand:
sudo ./ctr images build-erofs-cache $IMG /mnt/output/
There was a problem hiding this comment.
@mxpv okay, so may I ask if your main point is to use compressed native erofs?
since oci layers will be converted to uncompressed erofs by erofs snapshotters during unpacking: if uncompressed erofs is used, I guess we could just reuse these instead of converting again?
Also if compressed erofs is really needed, I think we could just reuse convert functionally to get compressed erofs native images, and build-erofs-cache again?
In short, my own thought is to reuse the layer.erofs in the snapshot directories for all commited snapshots, and push them into image cache; so that if uncompressed erofs is used, users don't need to convert again..
but if you really would like to convert unconditionally (no matter if local snapshots has the converted ones), I think in that case, no need to introduce a dedicated command; just confirm what kind of functionality you'd like.
There was a problem hiding this comment.
A cache blob is basically the same uncompressed erofs the snapshotter would produce — build-erofs-cache just makes it straight from the content store. So you don't need a node to have unpacked the image first, and it's snapshotter-agnostic: you can build the cache anywhere (just needs mkfs.erofs), no matter what snapshotter runs there. Harvesting from committed snapshots would work too, it's just more tangled up with snapshot layout/lifecycle.
One thing though — convert + build-erofs-cache doesn't quite substitute: the cache is keyed by the original layer diffID, which is what the unpacker looks up when pulling the upstream image. ctr convert mints a new erofs image with new diffIDs, so it'd only speed up pulls of that image, not the original.
There was a problem hiding this comment.
A cache blob is basically the same uncompressed erofs the snapshotter would produce — build-erofs-cache just makes it straight from the content store. So you don't need a node to have unpacked the image first, and it's snapshotter-agnostic: you can build the cache anywhere (just needs mkfs.erofs), no matter what snapshotter runs there. Harvesting from committed snapshots would work too, it's just more tangled up with snapshot layout/lifecycle.
One thing though — convert + build-erofs-cache doesn't quite substitute: the cache is keyed by the original layer diffID, which is what the unpacker looks up when pulling the upstream image. ctr convert mints a new erofs image with new diffIDs, so it'd only speed up pulls of that image, not the original.
ok, i'm fine with that, but maybe hear others' thoughts about this too.
yes, currently erofs-filebacked-mount on overlayfs is disallowed for now due to |
|
Also it'd be better to have a |
There was a problem hiding this comment.
Pull request overview
This PR adds support for a “warm” (pre-populated) EROFS layer cache so the EROFS snapshotter can short-circuit layer pulls by committing pre-converted, diffID-keyed .erofs blobs and signaling the unpacker via the remote-snapshot (ErrAlreadyExists) protocol.
Changes:
- Add
layer_content_cacheconfiguration and snapshotter logic to detect cached diffID blobs, symlink them into committed snapshots, and skip download/convert on hits. - Export
snapshots.LabelSnapshotRef/snapshots.LabelSnapshotDiffIDand update unpacker/metadata code to use them for the remote-snapshot flow. - Add
ctr images build-erofs-cacheto generate a diffID-keyed EROFS cache directory from an already-pulled image’s layers, plus EROFS cache-focused unit tests.
Reviewed changes
Copilot reviewed 10 out of 10 changed files in this pull request and generated 4 comments.
Show a summary per file
| File | Description |
|---|---|
| plugins/snapshots/erofs/plugin/plugin.go | Adds layer_content_cache config plumbing and disables rebase capability when cache is enabled. |
| plugins/snapshots/erofs/erofs.go | Implements cache lookup, cache-hit fast path commit, blob symlinking, and safe removal behavior for symlinked cached blobs. |
| plugins/snapshots/erofs/erofs_linux_test.go | Adds test coverage for cache hit/miss, dm-verity sidecar behavior, and removal semantics. |
| core/unpack/unpacker.go | Switches unpacker to use exported snapshot label constants. |
| core/snapshots/snapshotter.go | Exports LabelSnapshotRef and LabelSnapshotDiffID constants and updates inherited-label filtering. |
| core/metadata/snapshot.go | Updates metadata snapshotter to use exported label constants when resolving remote-snapshot targets. |
| core/metadata/snapshot_test.go | Updates tests to use exported snapshot label constant. |
| core/images/converter/erofs/erofs.go | Refactors EROFS conversion into reusable ConvertLayerToErofs helper returning the diffID. |
| cmd/ctr/commands/images/images.go | Registers the new build-erofs-cache subcommand. |
| cmd/ctr/commands/images/build_erofs_cache.go | Implements ctr images build-erofs-cache to populate a diffID-keyed EROFS cache directory. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 10 out of 10 changed files in this pull request and generated 3 comments.
Comments suppressed due to low confidence (1)
cmd/ctr/commands/images/images.go:56
- The PR description says "ctr image convert" gains a "--erofs-layer-cache" flag, but this change introduces a new "ctr images build-erofs-cache" subcommand instead and there is no "erofs-layer-cache" flag in the convert command. Either the PR description needs to be updated, or the intended flag needs to be implemented on the existing convert flow.
buildErofsCacheCommand,
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 10 out of 10 changed files in this pull request and generated 1 comment.
Comments suppressed due to low confidence (1)
cmd/ctr/commands/images/images.go:56
- The PR description says the cache builder is exposed via
ctr image convert --erofs-layer-cache <dir>, but this change adds a newctr images build-erofs-cachesubcommand instead. Please either update the PR description/examples to match the implemented CLI, or add the documented flag to the existingconvertcommand.
buildErofsCacheCommand,
Add a --dmverity flag to `ctr images build-erofs-cache`. When set, each cached erofs blob is dm-verity formatted (the hash tree is appended in place) and a .dmverity sidecar is written alongside it. This is required when the erofs snapshotter runs with dmverity_mode=on, which rejects cache hits that lack a sidecar; without it such layers would have to be formatted out-of-band. Extract the differ's dm-verity formatting into a shared dmverity.FormatLayer so the differ and the cache builder share one implementation; the differ's formatDmverityLayer now delegates to it. Signed-off-by: Maksym Pavlenko <[email protected]>
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 15 out of 15 changed files in this pull request and generated no new comments.
Comments suppressed due to low confidence (2)
plugins/snapshots/erofs/plugin/plugin.go:61
- The config comment for layer_content_cache doesn’t document the on-disk layout expected by the snapshotter/ctr producer. The PR description mentions
<dir>/<algorithm>/<hex>.erofs, but the implementation (via erofsutils.CacheBlobPath) uses a sharded layout<dir>/<algorithm>/<xx>/<hex>.erofs(where<xx>is the first two hex chars). Clarifying this here will reduce operator misconfiguration.
// LayerContentCache is a directory of pre-converted, diffID-keyed erofs
// layer blobs. When set, layers already present in the cache are committed
// without being downloaded or converted. Empty disables the feature.
cmd/ctr/commands/images/build_erofs_cache.go:212
- build-erofs-cache claims existing cache entries are overwritten/idempotent, but os.Rename does not replace an existing destination on Windows. This makes re-running the command (or updating entries) fail on Windows builds. Consider removing the destination path(s) first so the behavior matches the comment across platforms.
if withDmverity {
if err := os.Rename(dmverity.MetadataPath(tmpPath), dmverity.MetadataPath(dest)); err != nil {
return err
}
}
if err := os.Rename(tmpPath, dest); err != nil {
return err
}
containerd 2.4.0 Created-by: HarmonybrewBot Commit-by: HarmonybrewBot Merged-by: HarmonybrewBot Description: Created by `brew bump` --- Created with `brew bump-formula-pr`.<details> <summary>release notes</summary> <pre>Welcome to the v2.4.0 release of containerd! containerd 2.4 is a regular (non-LTS) release with a shorter support window, intended for users who want to adopt new features sooner. As the release following the 2.3 LTS, it is the point in the release cycle where previously deprecated features may be removed, so this release may include breaking changes; check the notes below and clear any deprecation warnings from your current version before upgrading. Users prioritizing stability and a longer support lifecycle should stay on the 2.3 LTS release. ### Highlights #### Container Runtime Interface (CRI) * Enable mount manager for image mounts in CRI ([#13542](containerd/containerd#13542)) * Export sandbox image and CNI directory configuration in CRI plugin info ([#13940](containerd/containerd#13940)) * Set default runtimeFeatures.UserNamespacesHostNetwork to true ([#13162](containerd/containerd#13162)) * Support OCI runtime feature introspection for non-runc runtimes ([#13504](containerd/containerd#13504)) #### Image Distribution * Apply hardening to strip sensitive authentication headers when fetching descriptor URLs ([#12889](containerd/containerd#12889)) * Support propagating HTTP 299 warning headers from registries to the resolver ([#12698](containerd/containerd#12698)) * Use klauspost/compress for gzip layer decompression ([#13560](containerd/containerd#13560)) #### Image Storage * Add client options to fetch all layer content during unpack even when snapshots exist ([#14126](containerd/containerd#14126)) * Include media type in content create events ([#13833](containerd/containerd#13833)) * Add forward References to the GC collection context ([#13634](containerd/containerd#13634)) #### Node Resource Interface (NRI) * Expose container image name, digest, and config digest to NRI plugins ([#13960](containerd/containerd#13960)) * Emit deprecation warnings for plugins using deprecated NRI interfaces ([#13916](containerd/containerd#13916)) #### Runtime * Mask /proc/interrupts and CPU thermal throttle sysfs paths in Linux containers by default ([#14090](containerd/containerd#14090)) * Add UpdateSandbox RPC to propagate sandbox controller updates to the shim ([#14105](containerd/containerd#14105)) * Avoid immediately restarting containers with restart=always policy after they are explicitly stopped ([#13993](containerd/containerd#13993)) * Pass tracing context from shim to runc and hooks ([#14036](containerd/containerd#14036)) * Fix user and group lookup failures in container rootfs containing symlinked /etc/passwd or /etc/group ([#13818](containerd/containerd#13818)) * Implement Windows named-pipe server and log streaming support in pkg/shim ([#13948](containerd/containerd#13948)) * Enable log scrubbing by default on Windows ([#13837](containerd/containerd#13837)) * Allow specifying parent checkpoint directory when checkpointing with runc ([#13699](containerd/containerd#13699)) #### Snapshotters * Add Prometheus metrics for EROFS snapshotter layer content cache ([#13941](containerd/containerd#13941)) * Support warm image cache for erofs snapshotter ([#13813](containerd/containerd#13813)) * Add max size label for snapshots ([#13520](containerd/containerd#13520)) #### Breaking * Remove deprecated CRI and tracing configuration options: * Remove `enable_cdi` in CRI runtime configuration (CDI is now always enabled) * Remove `bin_dir` in CRI CNI configuration (use `bin_dirs`) * Remove `endpoint`, `protocol`, and `insecure` in OTLP tracing processor configuration (use standard OTLP environment variables) * Remove `service_name` and `sampling_ratio` in internal tracing configuration (use standard OpenTelemetry environment variables) ([#14166](containerd/containerd#14166)) * Remove restore in CreateContainer ([#13871](containerd/containerd#13871)) #### Deprecations * Deprecate containerd.io/runtime-allow-mounts shim annotation in favor of MountCapabilities bootstrap extension ([#14002](containerd/containerd#14002)) * Remove deprecated shim.Command from pkg ([#13991](containerd/containerd#13991)) * Deprecate task API address and version fields in runc options and move to CreateTaskRequest ([#13360](containerd/containerd#13360)) Please try out the release binaries and report any issues at https://github.com/containerd/containerd/issues. ### Contributors * Maksym Pavlenko * Sebastiaan van Stijn * Samuel Karp * Derek McGowan * Wei Fu * Akihiro Suda * Mike Brown * Paweł Gronowski * Chris Henzie * Phil Estes * Brian Goff * Austin Vazquez * ningmingxiao * Jordan Liggitt * Akhil Mohan * Eshaan Mathur * Krisztian Litkey * Chris Ayoub * Kazuyoshi Kato * Kir Kolyshkin * Sergey Kanzhelev * Ahmet Alp Balkan * Arpit Jain * Cindy Li * Damien Grisonnet * Esteban Ginez * Gao Xiang * Harsh Rawat * Laura Lorenz * Maksim An * Oleh Konko * Philip Laine * Abhishek Bhunia * Alan Grosskurth * Albin Kerouanton * Alex Lyn * Aman Raj * Amir Alavi * Amit Barve * Andrew Halaney * AprilNEA * Arjun Yogidas * Ayato Tokubi * Aysha Afrah Ziya * Ben Cressey * Bing Hongtao * Chris Crone * Craig Gumbley * Daniel De Graaf * Davanum Srinivas * Dr. Jan-Philip Gehrcke * Harshal Patel * Henry Wang * Hsiu-Chi Tsai * JP Phillips * Jing Chen * Kohei Tokunaga * LEI WANG * Martín Fernández * Mikhail Dmitrichenko * Nahum Litvin * Nikolaus Schuetz * Pablo Garcia Caceres * Paco Xu * Robert Cronin * SaloniRathi * Shambhavi Srivastava * Tianon Gravi * XlabAI * Yuanliang Zhang * ayush-panta * crawfordxx * cshung * match man * s3onghyun * 归寂 * 徐晓伟 ### Changes <details><summary>658 commits</summary> <p> * [`647fafa847`](containerd/containerd@647fafa) Prepare release notes for v2.4.0 * Prepare release notes for api/v1.12.0 ([#14170](containerd/containerd#14170)) * [`5c4ea21de3`](containerd/containerd@5c4ea21) Prepare release notes for api/v1.12.0 * Deprecations and removals for 2.4 ([#14166](containerd/containerd#14166)) * [`531b3a37b9`](containerd/containerd@531b3a3) tracing: remove deprecated tracing config options * [`ca8579a334`](containerd/containerd@ca8579a) tracing: add tests for otlp exporter and env vars * [`ee024b7c99`](containerd/containerd@ee024b7) tracing: remove deprecated otlp configs * [`f7c654fb4f`](containerd/containerd@f7c654f) cri: remove deprecated cni bin_dir * [`4f7de25abb`](containerd/containerd@4f7de25) cri: remove enable_cdi config option * [`830b48d3fd`](containerd/containerd@830b48d) cri: delay registry config removal to 2.7 * Prepare release notes for v2.4.0-rc.0 ([#14115](containerd/containerd#14115)) * [`c02620e398`](containerd/containerd@c02620e) Prepare release notes for v2.4.0-rc.0 * [`02c7c97f43`](containerd/containerd@02c7c97) Update release doc for 2.4.0 release * [`484e5aba58`](containerd/containerd@484e5ab) vendor: github.com/containerd/containerd/api v1.12.0-rc.1 * [`67174d675c`](containerd/containerd@67174d6) mailmap: add Paweł Gronowski * Update erofs snapshotter to record blob source ([#14107](containerd/containerd#14107)) * [`697a7571a4`](containerd/containerd@697a757) erofs: give a dm-verity device a name unique to its mount * [`f75817eb3b`](containerd/containerd@f75817e) erofs: record where a layer blob is * [`d92088d822`](containerd/containerd@d92088d) erofs: refuse to apply into a read-only snapshot * [`8cc0b076a6`](containerd/containerd@8cc0b07) erofs: serve layer content cache on parented Prepare * build(deps): bump the golang-x group with 4 updates ([#14150](containerd/containerd#14150)) * [`75138b3fda`](containerd/containerd@75138b3) build(deps): bump the golang-x group with 4 updates * build(deps): bump github.com/klauspost/compress from 1.19.2 to 1.20.0 ([#14153](containerd/containerd#14153)) * [`353342cae6`](containerd/containerd@353342c) build(deps): bump github.com/klauspost/compress from 1.19.2 to 1.20.0 * pkg/oci: mask thermal interrupt info ([#14090](containerd/containerd#14090)) * [`c176f185b0`](containerd/containerd@c176f185b08e14bde055d81dc509 See merge request: Harmonybrew/homebrew-core!20372
A common technique to speed up cold container launches is to prefetch image
content onto the node:
Two approaches are common:
snapshotter consume it.
The OS image must be re-baked whenever the set of prefetched
containers changes, coupling the bake pipeline to container images.
The second approach is hard to combine with erofs today. To keep container
writes local you'd either need a writable cache mount — which then can't be
shared read-only across nodes — or you'd layer the read-only cache under an
overlay that routes writes elsewhere. The overlay route doesn't work with erofs,
because of nested-overlay constraints:
falls back to a loop device
overlay and the two would conflict.
This PR proposes a
layer_content_cacheoption to the erofs snapshotter: a path to aRO directory of pre-converted, diffID-keyed erofs layer blobs (
<dir>/<algorithm>/<hex>.erofs).external storage. containerd never writes to it.
and returns
ErrAlreadyExists, so the pull skips both the layer download andthe on-the-fly tar→erofs conversion — i.e. it acts as a remote snapshotter.
A miss transparently falls back to the normal download+convert path.
across images that share layers, independent of chain position (a similar approach was
proposed for overlayfs in Proposal: cross-image layer deduplication for the overlay snapshotter #13307)
ctr imagesgainsbuild-erofs-cache <img> <dir>to create erofs blobs from content store.The converted image itself is discarded; only the cache blobs are kept (and can
then be synced to shared storage). Keying by the source layer's diffID means the
cache is consumed when the fleet pulls the original image.
containerd config:
This way containerd can start with literally empty state directory and
still launch containers blazingly fast with erofs!