Skip to content

AVA1 1.0.9: read-back while the file arrives, from the drive - #12

Merged
phantomptr merged 4 commits into
mainfrom
readback-overlap
Nov 10, 2026
Merged

phantomptr merged 4 commits into
mainfrom
readback-overlap

Conversation

@phantomptr

@phantomptr phantomptr commented Nov 10, 2026 •

Copy link
Copy Markdown
Owner

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_READBACK used 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

  • Durability point. A sync batch fsyncs the part file and the outboard, syncs new directory entries, journals the ranges, and only then adds them to lf->durable. Right there it also adds them to lf->rb_todo. So nothing is read back before it is durable in the same sense as today ("every byte is durable by now").
  • Live read-back. Each job has 6 read-back threads of its own (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 with rb_todo, reads them through its own dup'd descriptors, compares the group CVs with the outboard, and records them in lf->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_todo is 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.
  • From the drive, not the cache. A console run of ae204b0 read back live at 1026 MiB/s: the page cache was answering. Each read now first drops its range from the cache through the platform layer (ava1_platform_drop_cache): posix_fadvise(DONTNEED) on Linux; on FreeBSD and the PS5 also msync(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 separate O_DIRECT descriptor (ava1_platform_open_direct) where the filesystem allows, with 4 KiB-aligned buffers and lengths, falling back to the ordinary descriptor on EINVAL. 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), or read-back may read cached pages: <why>. macOS has neither, so it says so. The outboard CVs are unchanged.
  • Rewrites and resets. A write over durable bytes (a late duplicate) takes its range out of rb_todo and rb_done and bumps lf->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.
  • Mismatch. A mismatch found while the file arrives is recorded (rb_found) and acted on at the commit, exactly as before: reset + FileRetry{RETRY_VERIFY}, and after 3 ERR_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.
  • Commit. It waits for that file's in-flight live reads (no new ones start once committing is set), then reads only the groups not in rb_done, striped as before. A resume after a restart has an empty rb_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.
  • Bounded. The job caps read-back buffers at 8 × 8 MiB (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.
  • Timing line: 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 arrive line 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 give ERR_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_cache checks 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.rs checks the new ava1_rset_remove/ava1_rset_overlaps against a bitmap.

Checks run (at 4fd6233)

  • make lib and the example node with gcc 14 (gcc:14 container); make lib with clang. Both -Wall -Wextra -Werror, clean.
  • The touched units (platform_ps5.c, ava1_apply.c, ava1_job.c, ava1_ranges.c, ava1_recv.c) compile with the PS5 SDK's prospero-clang -Werror, and the PS5 build takes the O_DIRECT branch.
  • cargo fmt --check, cargo clippy --workspace --all-targets -D warnings, ava1-gen --check
  • cargo test --workspace --exclude ava1-ctest, scripts/aead-test.sh, cargo test -p ava1-ctest -- --test-threads=1 (797 passed, 0 failed), make interop
  • Linux: readback and ranges tests in a rust:1 container 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).
  • The ignored release tests (1 GiB stripes, 4 GiB with a restart) pass on macOS. macOS reads through the cache: there, neither dropping pages nor O_DIRECT is available.

Not run: the sanitizer suite (CI runs it). Not run on a console: the PS5's posix_fadvise and msync(MS_INVALIDATE), and whether O_DIRECT reaches 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_DIRECT part.

  • The live reads' rate (MiB per thread-second spent reading) should drop from ~1 GiB/s to roughly the drive's per-thread rate (~25-30 MiB/s). If it stays near 1 GiB/s, the PS5 kernel serves the reads from memory despite both measures, and the line will show which ones worked.
  • "After their last byte" should stay small (tens of MiB) and the job close to the ~62 s transfer, if 6 threads at ~25 MiB/s (~150 MiB/s) keep up with 65 MiB/s while the drive also takes the writes. If "after" grows, raise AVA1_READBACK_THREADS; the 8-buffer cap allows 8.

🤖 Generated with Claude Code

https://claude.ai/code/session_01GtiJiKKJsHLtjPXabu2A5E

adorabledev and others added 4 commits November 10, 2026 02:03
…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
phantomptr marked this pull request as ready for review November 10, 2026 10:16
@phantomptr phantomptr changed the title Read-back while the file arrives: only the tail is left after the last byte AVA1 1.0.9: read-back while the file arrives, from the drive Nov 10, 2026
@phantomptr
phantomptr merged commit 2d0c21a into main Nov 10, 2026
13 checks passed
@phantomptr
phantomptr deleted the readback-overlap branch November 10, 2026 10:26
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