Repository navigation
AVA1 1.0.9: read-back while the file arrives, from the drive - #12
Merged
Merged
Conversation
…t byte JF_READBACK used to read every large file back after its last byte; on a PS5 Pro that added ~19.5 s to a 4 GiB file (~30%). Each sync batch now hands the ranges it has made durable (data and outboard fsynced, ranges journaled) to the file's rb_todo, and up to two work items on the job's own workers read whole groups back from there while the rest arrives. They queue behind the chunks and give their turn up when chunks wait with no free worker. The commit waits for that file's reads in flight and reads back only what is left. A write over durable bytes (a late duplicate) or a reset voids what was read of them (rb_gen), so every group is read back once after it was last made durable. A mismatch found while the file arrives is acted on at the commit (reset + FileRetry, ERR_VERIFY after 3), so senders see nothing new. Read-back buffers stay at 8 x 8 MiB per job, live reads included. The end-of-job line says how much was read back while files arrived and after. Tests: out-of-order lanes with verification between waves (each byte read once), a byte changed before/after its group is read (caught / the documented gap), duplicate writes, a stop or end mid read, ERR_VERIFY after three live mismatches; rset_remove/overlaps against a bitmap. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01GtiJiKKJsHLtjPXabu2A5E
The live read-back ran as work items on the receive workers and gave its turn up whenever chunks waited with no free worker, so a busy upload could keep it from ever reading. And 2 readers could not keep up anyway: an 8 MiB read on the console runs at ~30 MiB/s per thread (135.8 s of reading for 4 GiB over 8 threads), and 65 MiB/s needs at least 3. Each job now has 4 read-back threads of its own (AVA1_READBACK_THREADS), started at its first durable large-file range and woken by every batch. While chunks wait for a worker, all but one hold back: one read in flight. They read no more than the batches have made durable. Quiesce waits for live reads in flight, teardown joins the threads, and they exit once the job ends. The end-of-job line now also says how many ranges the batches handed over, how many live reads ran, and how many of those ran with chunks waiting. A "read-back: 4 threads ..." line marks the start. Test: every worker kept busy for the whole transfer (each chunk write takes 20 ms, chunks always queued); at least half the file must be read back live. Locally all 200 MiB was, 21 of 26 reads with chunks waiting. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01GtiJiKKJsHLtjPXabu2A5E
…_DIRECT On the PS5 Pro the live reads of ae204b0 ran at 1026 MiB/s, against ~211 MiB/s for reads that reach the drive: the page cache answered, right after the batch had synced the range, and a read answered from memory cannot find a drive or filesystem fault. Before each read (live and at the commit) the range's pages are now dropped from the cache: posix_fadvise(DONTNEED) on Linux; on FreeBSD and the PS5 also msync(MS_INVALIDATE) over a mapping, since FreeBSD 11's DONTNEED only deactivates the pages. They are clean, so they drop. Reads then go through a separate O_DIRECT descriptor where the filesystem allows one (4 KiB-aligned buffer and length), falling back to the ordinary descriptor on EINVAL. On the PS5 the first drop runs with SIGSYS ignored, so a call the kernel lacks answers ENOSYS instead of killing the helper, and is not made again. macOS has neither and says so. Each job logs one line on how its read-back reaches the drive; the end-of-job line counts reads with the cache dropped and with O_DIRECT. The outboard CVs are read as before. Drive reads run at ~26-30 MiB/s per thread, so the live read-back now has 6 threads (~150 MiB/s, twice a 65 MiB/s upload). Test: one cache drop per read, live and at the commit, all answered on Linux. Checked on Linux ext4 in a container: every read used O_DIRECT and the corruption tests still catch the flipped byte. Every touched unit compiles for the PS5 with -Werror. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01GtiJiKKJsHLtjPXabu2A5E
Read-back while the file arrives, from the drive. Nothing changes on the wire format. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01GtiJiKKJsHLtjPXabu2A5E
phantomptr
marked this pull request as ready for review
November 10, 2026 10:16
phantomptr
force-pushed
the
readback-overlap
branch
from
November 10, 2026 10:16
4fd6233 to
57ca378
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Builds on #11 (8 threads of 8 MiB reads + the read/hash timing line); that commit is included here unchanged, so this PR shows both until #11 merges.
What
JF_READBACKused to read every large file back after its last byte. Measured on a PS5 Pro, a 4 GiB file arrives in ~62 s and the read-back then added ~19.5 s (~30%). The drive reads back faster than the network delivers, so this reads each part back while the rest of the file still arrives, and the commit reads only what is left (normally the last batch).Design
lf->durable. Right there it also adds them tolf->rb_todo. So nothing is read back before it is durable in the same sense as today ("every byte is durable by now").AVA1_READBACK_THREADS), started at the job's first durable large-file range and woken by every batch. Each takes up to 8 whole groups (8 MiB) from the first file withrb_todo, reads them through its owndup'd descriptors, compares the group CVs with the outboard, and records them inlf->rb_done. They are not the receive workers, so a steady stream of chunks never keeps them from reading. While chunks wait for a worker, all but one hold back, so the drive sees one read-back read at a time. They can never read more than the batches have written. Lanes write out of order;rb_todois a range set, so any order works. 6 threads because the drive reads ~26-30 MiB/s per thread (8 threads: ~211 MiB/s), so 6 give ~150 MiB/s, about twice a 65 MiB/s upload, with the drive also taking the writes.ava1_platform_drop_cache):posix_fadvise(DONTNEED)on Linux; on FreeBSD and the PS5 alsomsync(MS_INVALIDATE)over a mapping of the range, because FreeBSD 11's DONTNEED only deactivates the pages and leaves them valid. The pages are clean, since the batch synced them. Reads then go through a separateO_DIRECTdescriptor (ava1_platform_open_direct) where the filesystem allows, with 4 KiB-aligned buffers and lengths, falling back to the ordinary descriptor onEINVAL. The commit pass does the same. On the PS5 the first drop runs with SIGSYS ignored, so a call the kernel lacks answers ENOSYS instead of killing the helper, and is never made again. Each job logs one line saying how:read-back from the drive: O_DIRECT reads + posix_fadvise(DONTNEED) + msync(MS_INVALIDATE), orread-back may read cached pages: <why>. macOS has neither, so it says so. The outboard CVs are unchanged.rb_todoandrb_doneand bumpslf->rb_gen. That voids any read-back of the file still in flight, and the range is read again once its own batch makes it durable. A reset clears everything and bumps the generation too. So each group is read back once after it was last made durable.rb_found) and acted on at the commit, exactly as before: reset +FileRetry{RETRY_VERIFY}, and after 3ERR_VERIFY. An old sender never gets a FileRetry for a file it is still sending. If the bad group is written again, the new bytes decide.committingis set), then reads only the groups not inrb_done, striped as before. A resume after a restart has an emptyrb_done, so the commit reads everything the new process has not read. The flag stays out of the job identity, nothing new goes on the wire or in the journal, and old peers are unaffected.j->rb_bufs), shared between live reads and commit stripes; a commit takes as many stripes as are free, at least one. A manifest change (quiesce) waits for live reads in flight, and none start while the feed is held. Teardown joins the threads, and they exit once the job ends.read back N files, X MiB: L MiB while they arrived (K ranges handed over, R reads, C with chunks waiting), A MiB after their last byte in T ms (R MiB/s; threads spent … ms reading, … ms hashing; D of N reads with the cache dropped first, O with O_DIRECT), M mismatches.K> 0 confirms the batch hook fired for the file. A[ava1] job …: read-back: 4 threads read large files back as they arriveline marks the threads starting.Documented gap (SPEC §13.5, test
a_byte_changed_after_its_group_was_read_back_is_not_found): a byte that changes on the drive after its group was read back, while later groups still arrive, is not caught.Tests
crates/ava1-ctest/tests/readback.rs: every receive worker kept busy for the whole transfer (each chunk write takes 20 ms, chunks always queued), where at least half the file must be read back live; locally all 200 MiB was, 21 of 26 reads with chunks waiting. Also: four lanes in mixed order with verification between waves (every byte read back exactly once), a byte changed before its group is read is caught live and acted on at the commit, a byte changed after is not caught (documented), a duplicate write is read back again, a group found wrong then rewritten is judged by its new bytes, 3 live mismatches giveERR_VERIFY, a stop mid live read is prompt and the resume reads back the rest, and ending a job mid live read is prompt. The existing tests now flip the byte right before whichever pass reads it (ava1_test_rb_corrupt), so they do not depend on timing.every_read_back_read_first_drops_its_range_from_the_cachechecks that every read, live or at commit, first drops its range: one drop per read, and on Linux every drop answered (a real cache miss can't be asserted portably).tests/ranges.rschecks the newava1_rset_remove/ava1_rset_overlapsagainst a bitmap.Checks run (at 4fd6233)
make liband the example node with gcc 14 (gcc:14container);make libwith clang. Both-Wall -Wextra -Werror, clean.platform_ps5.c,ava1_apply.c,ava1_job.c,ava1_ranges.c,ava1_recv.c) compile with the PS5 SDK'sprospero-clang -Werror, and the PS5 build takes theO_DIRECTbranch.cargo fmt --check,cargo clippy --workspace --all-targets -D warnings,ava1-gen --checkcargo test --workspace --exclude ava1-ctest,scripts/aead-test.sh,cargo test -p ava1-ctest -- --test-threads=1(797 passed, 0 failed),make interopreadbackandrangestests in arust:1container with the temp dir on an ext4 volume. All pass. Every read used O_DIRECT with the cache dropped first, and the corruption tests still catch the flipped byte. Job line:read-back from the drive: O_DIRECT reads + posix_fadvise(DONTNEED).Not run: the sanitizer suite (CI runs it). Not run on a console: the PS5's
posix_fadviseandmsync(MS_INVALIDATE), and whetherO_DIRECTreaches the drive there; the first console run will show it.To measure on a console
Same 4 GiB upload with the read-back on. First check the job's
read-back from the drive: …line, which names the method, and that the end-of-job line has the new… reads with the cache dropped first, … with O_DIRECTpart.AVA1_READBACK_THREADS; the 8-buffer cap allows 8.🤖 Generated with Claude Code
https://claude.ai/code/session_01GtiJiKKJsHLtjPXabu2A5E