Skip to content

fix(volume): share extents via FICLONERANGE when packing volumes - #1706

Open
PierreLeGuen wants to merge 1 commit into
Dstack-TEE:nextfrom
nearai:fix/volume-reflink-pack
Open

PierreLeGuen wants to merge 1 commit into
Dstack-TEE:nextfrom
nearai:fix/volume-reflink-pack

Conversation

@PierreLeGuen

Copy link
Copy Markdown
Contributor

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

  • Use Linux FICLONE / FICLONERANGE in dstack/crates/dstack-volume/src/volume.rs (adding libc to dstack-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_variables and cargo fmt --all -- --check: pass.
  • Verified packing a 1.1 TB squashfs volume on XFS without needing a second 1.1 TB of disk space.

Split out from #1703.

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>
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Dec 2, 2026 •

Copy link
Copy Markdown
Codex Review Summary: ✅ Completed

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-12-02T13:28:54.383395Z f6fb5f6 PR opened
ℹ️ 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" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 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)?;

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge 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 👍 / 👎.

This branch has not been deployed

No deployments
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