Repository navigation
Description
Split out of #176, which wired performance.read_ahead to the prefetcher and made this visible.
ReadAheadManager.OnRead gates the prefetch on two conditions:
if pattern.sequentialHits >= ram.config.MinSequential && pattern.confidence > 0.5 {and confidence is assigned, a few lines above, as float64(pattern.sequentialHits) / 10.0. So the
second condition is sequentialHits > 5, expressed in different units. The two thresholds are the same
quantity and the stricter one always wins.
The consequences:
min_sequentialis inert below 6. Setting 1, 2, 3, 4 or 5 all behave identically — the first
prefetch happens on the sixth consecutive sequential read in every case.- The shipped default is one of those values.
config.NewDefaultand
fuse.DefaultReadAheadConfigboth say 3, so the documented default does not describe the default
behavior.examples/config.yamlnow carries a paragraph explaining this, which is a doc comment
standing in for a fix. - Above 6 the confidence floor becomes redundant and
min_sequentialgoverns alone, so the setting
works as documented in exactly the upper part of its range.
Two ways out, and the choice is a behavior decision rather than a cleanup:
- Drop the confidence floor from the gate and let
min_sequentialmean what it says.confidence
is still computed and still onReadPattern; nothing else reads it. This makesmin_sequential: 3
prefetch on the third sequential read — a real behavior change at the default configuration, in the
direction of prefetching sooner and more often. - Raise both defaults to 6 and validate
min_sequential >= 6, rejecting values the code cannot
honor. Keeps todays behavior exactly; makes the configuration honest by narrowing it.
(1) is probably right — a confidence score derived from the same counter as the threshold it guards is
not independent evidence, and two knobs for one decision is what made this invisible — but it changes
prefetch behavior for every existing mount, so it wants a measurement alongside it: the
bytes-transferred figures in prefetchLength's doc comment are the shape of evidence to bring.
Not urgent: the current behavior is conservative rather than wrong, and it has been shipped for
several releases. It is filed because the workaround in examples/config.yaml is a comment explaining
why a number does not mean what it says, and that comment should be deletable.
Activity
fix: performance.read_ahead now reaches the prefetcher (#248)
scttfrdmn commentedon Aug 3, 2026
Fixed in #281, taking option 1 — drop the confidence floor. The issue asked for measurement alongside it, so here it is.
The effective gate, measured by driving
OnReaddirectly with a stub queue:min_sequentialmax(MinSequential, 6), exactly as the issue reasoned.A continuing traversal costs the same at every value. 3 MiB read sequentially at the kernel's 128 KiB buffer, against a real endpoint with the request recorder:
min_sequentialIdentical throughout, because
FileSystem.fetchshares one flight between a prefetch and the read it anticipates — so a prefetch that is going to be read costs nothing. That removes most of the concern behind "prefetching sooner and more often": on a reader that keeps going, sooner is free.The cost of prefetching sooner is a run that stops, and it is bounded at one prefetch:
min_sequential: 3min_sequential: 6Note the last row: at a 6-read run,
min_sequential: 6wastes the same 131,072 bytes. The waste is one prefetch either way, not a growing tail — the floor never prevented a class of waste, it moved the point at which the single unredeemed prefetch became possible from read 6 to read 3. That is a good trade, and it makes the setting mean what it says.Two things beyond the gate, both because the issue frames this as making the configuration honest rather than as a cleanup:
confidenceis deleted, not left computed-and-unread. It had exactly one reader — the gate — and a score derived from the threshold it guards is not independent evidence and cannot become any.The
examples/config.yamlparagraph is deleted, which the issue named as the test of whether this got fixed rather than documented.internal/config/doc.go's high-throughput profile also stopped recommendingmin_sequential: 6"because 6 is the effective floor whatever is set" — it now recommends 2, which is the actual advice for a reader that does not stop.The test that should have caught this.
TestReadAheadManager_PrefetchScheduled_AfterEnoughHitsread six times atmin_sequential: 3and asserted a prefetch, with a comment explaining that six was required — so it documented the defect instead of catching it, and would have passed identically ifMinSequentialwere ignored altogether. It now drives both sides of the threshold, and is mutation-verified in both directions: restoring the floor fails it, and replacing the gate with>= 1fails it.One correction to the issue's arithmetic, found by that test: the threshold lands on read N, not N+1. The first read of a file counts as sequential, because a fresh
ReadPatternhaslastOffsetandlastSizeboth zero and sooffset == lastOffset+lastSizeholds at offset 0.min_sequential: 3therefore means the third read of a file — which is what the configuration documentation claims, so no doc change was needed there.fix: min_sequential is the threshold, not one of two (#281)