Skip to content

fix(restore): bound the blob writes queued at once - #667

Open
stefanwichmann wants to merge 1 commit into
rustic-rs:mainfrom
stefanwichmann:fix/restore-write-cap-main
Open

stefanwichmann wants to merge 1 commit into
rustic-rs:mainfrom
stefanwichmann:fix/restore-write-cap-main

Conversation

@stefanwichmann

Copy link
Copy Markdown
Contributor

Closes #666

What and why

restore_contents spawned a write task for every blob it decoded, and decoding runs far ahead of writing. So a restore held most of its data in memory: about 24 GiB for a 24 GiB file. On macOS 27, that memory pressure made writes that run alongside each other lose the first partial 4 KiB block of a blob, while the restore reported success. #666 has the reproduction and measurements.

At most MAX_PENDING_WRITES (20) writes are now queued. Beyond that, the task that decoded a blob writes it itself. Decoding can no longer run ahead, peak buffer memory is bounded at about 20 blobs, and no pool thread ever blocks waiting for a slot, so the scope cannot deadlock however many packs are in flight.

Measured

On a 16 GiB Apple silicon Mac, restoring a 24 GiB file of 8 MiB blobs:

Result Time
Unpatched, same-day control zeroed bytes 74–78 s
This change byte-exact in 3 of 3 runs 14–17 s

Tests

  • cargo fmt --check and cargo clippy --all-targets are clean.
  • cargo test -p rustic_core passes, except five insta snapshot tests (backup tar, ls, rewrite, vfs). On macOS those fail on the unmodified rustic_core-v0.14.0 tag as well.

restore_contents queued a write task for every blob it decoded, and
decoding runs far ahead of writing, so a restore held most of its data
in memory: about 24 GiB for a 24 GiB file. On macOS 27 that memory
pressure made concurrent writes lose the first partial block of a blob
written beside its neighbour, zeroing it, while the restore reported
success.

At most MAX_PENDING_WRITES (20) writes are now queued; beyond that the
task that decoded a blob writes it itself, so decoding cannot run ahead
and no pool thread waits on another.

Measured on a 16 GiB Apple silicon Mac with a 24 GiB file of 8 MiB
blobs: unpatched restores zeroed bytes in every run; with this change
3 of 3 were byte-exact, and the restore took 14-17 s instead of
74-78 s.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: 968888b2-f42d-41c1-8ac4-262142c8a7c4
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.

Restore queues every decoded blob, and on macOS the memory pressure zeroes the start of blobs

1 participant