Repository navigation
fix(volume): share extents via FICLONERANGE when packing volumes - #1706
PierreLeGuen wants to merge 1 commit into
Conversation
Building a volume copied the filesystem image twice: into a scratch file, then into the GPT image through a 1 MiB userspace buffer. For a large image that doubles the disk space and the time. Clone instead with FICLONE / FICLONERANGE: the partitions are 1 MiB aligned and the data and hash images are padded to whole blocks, so XFS and Btrfs share the extents. Fall back to a copy where cloning is not supported. copy_file_range is not used because it does not reliably clone (it did not on Linux 7.0 with XFS). Tested: packing a 1.1 TB squashfs on XFS no longer needs a second 1.1 TB, and the scratch copy completes immediately. Signed-off-by: Pierre LE GUEN <26087574+PierreLeGuen@users.noreply.github.com>
Codex Review Summary: ✅ CompletedThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: f6fb5f6e46
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| break; | ||
| } | ||
| out.write_all(&buf[..n])?; | ||
| std::io::copy(&mut input, out)?; |
There was a problem hiding this comment.
Preserve the large-buffer fallback when reflinking fails
When reflinks are unsupported, or the scratch and output files reside on different filesystems, both arguments here are fs_err::File wrappers. Consequently, std::io::copy cannot use its std::fs::File kernel-copy specialization and instead uses the generic 8 KiB buffer. This replaces the previous 1 MiB loop with 128 times as many read/write calls; a cached-file benchmark with equivalent wrappers on Rust 1.92 was over twice as slow. Large-volume builds on non-reflink storage therefore regress in this performance-focused change. Retain the 1 MiB fallback buffer or copy through the underlying standard file handles.
Useful? React with 👍 / 👎.
Summary
Packing a dm-verity GPT volume previously copied the filesystem image twice: into a scratch file and then into the GPT image through a 1 MiB userspace buffer, doubling disk usage and I/O time for large volumes.
Changes
FICLONE/FICLONERANGEindstack/crates/dstack-volume/src/volume.rs(addinglibctodstack-volume) to share extents on copy-on-write filesystems (XFS, Btrfs), falling back to a normal copy when cloning is unsupported. Partitions are 1 MiB aligned and data/hash images are padded to whole blocks.Verification
cargo test --locked -p dstack-volume: 12 passed across unit/integration tests.cargo clippy --locked -p dstack-volume -- -D warnings --allow unused_variablesandcargo fmt --all -- --check: pass.Split out from #1703.