Repository navigation
Description
Summary
Four defects in internal/fuse/optimizations.go, all fixed in the v0.10.1 read-path
commit, filed here for the record because none of them appeared in the v0.10.0 audit.
The audit covered the cache keying (H5/H6) and the read amplification (C4) but never
examined the prefetcher, and the prefetcher was independently transferring more bytes than
the files it was prefetching.
They are recorded together because they share one root cause worth naming: nothing measured
the prefetcher's own egress. Three of the four are invisible to a hit-rate metric, and the
fourth was the metric being wrong.
The four
1. The prefetch window was smaller than the read it anticipated. WindowSize defaulted
to 64 KiB against the kernel's 128 KiB MaxRead. The cache answers only for a range it
holds in full, so every prefetched entry was walked straight past and its bytes were
fetched a second time by the read itself. Measured on a 3 MiB file read sequentially at
128 KiB:
| GETs | bytes transferred | |
|---|---|---|
| before | 43 (24 reads + 18 prefetches, zero prefetches ever hit) | 4,325,644 |
| after | 24 | 3,145,728 |
1.38× amplification whose entire excess was prefetch, paid twice — in egress and in the
cache capacity the useless entries occupied. The window is now at least one read's worth,
with the configured WindowSize as a floor rather than a ceiling.
2. Reading a file to its end billed a guaranteed-failing S3 request. A sequential
reader's predicted next offset runs past EOF by construction: the last read of every
complete traversal is followed by a prediction one read beyond the end. v0.10.0 sent it,
earning a 416 InvalidRange — a billed request, an error log line, and a latency spike on
the reliability path, for a range that cannot exist. Exactly one per traversal, every time.
The clamp must be applied before the already-cached check, not after. Asking the cache
for the unclamped length misses forever on the last stretch of every file, so each traversal
re-fetches its tail.
3. A successful prefetch hid the next read from the detector that scheduled it. OnRead
was called only on the cache-miss path. The read after a hit was compared against the offset
of the read before the gap, appeared non-contiguous, and reset sequentialHits to zero.
The counter cycled 0→6→prefetch→0 forever: exactly one prefetch landed per seven reads and a
long sequential traversal never reached steady state. On the 3 MiB traversal this was the
difference between 3 and 18 of 24 reads served without blocking on S3.
4. The prefetch metric reported bytes requested, not bytes transferred. Those differ on
the last prefetch of every file now that the range is clamped. A prefetch metric that
overstates its own egress is the wrong number to tune a prefetcher with.
Why the tests did not catch these
Three of the four were, at the moment the fix was written, covered by no test that could
fail — the full -race suite passed with each fix mutated back out. That is the part worth
keeping:
- The window undersizing (ci(deps): Bump actions/setup-go from 4 to 5 #1) is invisible to a hit-rate assertion, which is the obvious
thing to assert. The wasted entries were never hit, so they were never counted as misses
either: a hit-rate assertion passes on the defect. The regression test asserts bytes
transferred. - The hit-path blindness (ci(deps): Bump actions/configure-pages from 3 to 5 #3) changes neither GET count nor bytes transferred — every byte is
fetched exactly once either way. What it changes is which reads block on S3, and that
depends on prefetch workers winning a race, which is not a property a test should assert on.
The test asserts on the detector's own contiguity state (sequentialHits), which is
deterministic: it pre-fills the cache and setsConcurrentReads: 0so nothing drains the
prefetch queue.
Status
Fixed. internal/fuse/read_path_test.go (nine tests, driving FileHandle.Read against a
real byte-range cache, a real write path, and a substrate-backed S3 endpoint). Each fix was
verified by mutating it back out and watching the right test fail. internal/fuse coverage
17.7% → 37.7%.
Related
- performance.read_ahead is validated, documented, and read by nothing #176 —
performance.read_aheadis read by nothing, so the 64 KiB default in ci(deps): Bump actions/setup-go from 4 to 5 #1 above was
the only window value ever used in production. That issue is the reason this one's blast
radius was every mount rather than every default mount.
Activity
scttfrdmn commentedon Aug 2, 2026
Fixed in v0.10.1 (
53910b0,4ec631a,721a25f). All four: the token bucket's sub-second refill no longer truncates to zero (so the prefetcher is not permanently starved), the predictive cache can be shut down without panicking on a closedprefetchQueue, in-flight fetches deduplicate by containment rather than equality, and a prefetch that overlaps a read already in flight now trims its range instead of skipping. The trim distinction is the load-bearing one: skipping also produces the right byte count, but by never prefetching at all — a reader that consistently wins the race has a read in flight every time a prefetch is scheduled, so a 16 KiB file read in 1 KiB steps went to 16 GETs, one per read, with read-ahead contributing nothing. Trimmed: 8 GETs, tail fetched once, ahead of the reader, and 16,384 bytes transferred for a 16,384-byte file. Pinned by a test that asserts both properties, so neither a skip-regression nor an amplification-regression can pass.