Skip to content

Use syncfs#7883

Merged
xzfc merged 2 commits intodevfrom
syncfs
Jan 8, 2026
Merged

Use syncfs#7883
xzfc merged 2 commits intodevfrom
syncfs

Conversation

@xzfc
Copy link
Member

@xzfc xzfc commented Jan 8, 2026

Problem

Restoring snapshot that contains a lot of small files takes a lot of time.
This happen because we set tar::Archive::set_sync (from our tar-rs fork) that calls fsync on every file in a sequence. Fsyncing each file individually is slow.

Solution

Disable set_sync and use syncfs instead. syncfs syncs the whole filesystem at once, not just a particular single file.
A potential drawback is that background writes (outside of snapshot restore code) can slow syncfs down, but I think it's a worthy tradeoff.

Also, since set_sync was the last thing from our tar-rs fork, we can switch to the upstream tar-rs.

Alternatives & synthetic benchmarks

I've considered the

  1. fsync in sequence (baseline).
  2. sync_file_range in sequence then fsync in sequence.
  3. syncfs on a single file.
  4. io_uring: call fsync through io_uring pipeline.

Results and code: https://gist.github.com/xzfc/b22591fa5a5a192a1574857b00d7cb8d#file-results-md

Also, this method was the last remaining part of our `tar-rs` fork,
so we can switch to the upstream version now.
@xzfc xzfc requested review from generall and timvisee January 8, 2026 14:03
coderabbitai[bot]

This comment was marked as resolved.

coderabbitai[bot]

This comment was marked as resolved.

coderabbitai[bot]

This comment was marked as resolved.

@qdrant qdrant deleted a comment from coderabbitai bot Jan 8, 2026
Copy link
Member

@timvisee timvisee left a comment

Choose a reason for hiding this comment

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

Simple and effective, brilliant!

I like that we can now use upstream tar-rs.

@xzfc xzfc merged commit 65141c9 into dev Jan 8, 2026
15 checks passed
@xzfc xzfc deleted the syncfs branch January 8, 2026 15:07
generall pushed a commit that referenced this pull request Feb 9, 2026
* Remove call to Archive::set_sync

Also, this method was the last remaining part of our `tar-rs` fork,
so we can switch to the upstream version now.

* Do syncfs
@timvisee timvisee mentioned this pull request Feb 17, 2026
5 tasks
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.

2 participants