Repository navigation
fix: min_sequential is the threshold, not one of two - #281
Merged
Merged
Conversation
The prefetch gate required sequentialHits >= MinSequential *and* confidence > 0.5, where confidence was assigned sequentialHits/10 a few lines above. So the second condition was sequentialHits > 5 — the same quantity in different units — and the stricter always won. The effective gate was max(MinSequential, 6): 1, 2, 3, 4 and 5 all prefetched first on the sixth sequential read, and the shipped default is 3, so the documented default did not describe the default behavior. Above 6 the floor was redundant, meaning the setting worked as documented in exactly the upper part of its range. Dropping the floor rather than raising the defaults to 6, and the measurement is why. A continuing traversal costs the same either way. 3 MiB read sequentially at the kernel's 128 KiB buffer transfers exactly 3,145,728 bytes at every MinSequential from 1 to 10, because FileSystem.fetch shares one flight between a prefetch and the read it anticipates — a prefetch that is going to be read adds no bytes at all. What prefetching sooner actually costs is a run that *stops* before consuming what was fetched, and that cost is exactly one prefetch rather than a growing tail: a reader that goes sequential and then walks away wastes 131,072 bytes whether it stops after three reads at min_sequential: 3 or after six at min_sequential: 6. The floor never prevented a class of waste, it only moved the point at which the single unredeemed prefetch became possible. Trading one prefetch's exposure for prefetching from the third read instead of the sixth is worth it, and the number a user sets is now the number the detector uses. The confidence field is deleted rather than left computed-and-unread. It was read at exactly one place, the gate, and a score derived from the threshold it guards is not independent evidence and cannot become any. The paragraph in examples/config.yaml explaining why the number did not mean what it said is deleted too, which is the test of whether this was fixed rather than documented. doc.go's high-throughput profile no longer recommends 6 as "the effective floor whatever is set"; it recommends 2, because committing to a prefetch early is the actual advice for a reader that does not stop. The gate test now drives both sides of the threshold — nothing on the read before it, a prefetch on the read at it. It previously read six times at min_sequential: 3 and 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 if MinSequential were ignored altogether. A gate test that only drives the satisfying case cannot tell a threshold of 3 from one of 6. Verified by mutation in both directions: restoring the confidence floor fails it, and replacing the gate with `>= 1` fails it. The threshold lands on read N rather than N+1, because the first read of a file counts as sequential: a fresh ReadPattern has lastOffset and lastSize both zero, so `offset == lastOffset+lastSize` holds at offset 0. That makes "min_sequential: 3" mean the third read of a file, which is what the configuration documentation says. Closes #247
scttfrdmn
enabled auto-merge (squash)
August 3, 2026 18:48
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.
Closes #247.
The prefetch gate required
sequentialHits >= MinSequentialandconfidence > 0.5, where confidence was assignedsequentialHits / 10.0a few lines above. So the second condition wassequentialHits > 5— the same quantity in different units — and the stricter always won. The effective gate wasmax(MinSequential, 6).Measured directly, driving
OnReadwith a stub queue:min_sequentialThe shipped default is 3, so the documented default did not describe the default behavior, and the setting worked as documented in exactly the upper part of its range.
Why drop the floor rather than raise the defaults to 6
The issue left this open as a behavior decision wanting measurement. Here is the measurement, taken against a real S3 endpoint with the request recorder, asserting bytes transferred.
A continuing traversal costs the same either way. 3 MiB read sequentially at the kernel's 128 KiB buffer:
min_sequentialIdentical at every value, because
FileSystem.fetchshares one flight between a prefetch and the read it anticipates — a prefetch that is going to be read adds no bytes at all. So the "prefetches sooner and more often" concern does not cost anything on a reader that keeps going.What prefetching sooner costs is a run that stops. A reader that goes sequential for N reads and then walks away, with the floor removed:
min_sequential: 3min_sequential: 6The waste is exactly one prefetch, not a growing tail, and
min_sequential: 6shows the same single waste once a run reaches 6. The floor never prevented a class of waste — it only moved the point at which the single unredeemed prefetch became possible, from read 6 to read 3. Trading that for prefetching from the third read instead of the sixth is worth it, and the number a user sets is now the number the detector uses.Scope
The
confidencefield is deleted rather than left computed-and-unread. It was read at exactly one place, the gate, and a score derived from the threshold it guards is not independent evidence and cannot become any.The paragraph in
examples/config.yamlexplaining why the number did not mean what it said is deleted too — the issue's own stated test of whether this was fixed rather than documented: "that comment should be deletable."internal/config/doc.go's high-throughput profile no longer recommendsmin_sequential: 6with the comment "6 is the effective floor whatever is set." It recommends 2, because committing to a prefetch early is the actual advice for a reader that does not stop.The test
The gate test now drives both sides of the threshold — nothing on the read before it, a prefetch on the read at it. It previously read six times at
min_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. A gate test that only drives the satisfying case cannot tell a threshold of 3 from a threshold of 6.Mutation-verified in both directions:
>= 1One detail worth recording: the threshold lands on read N rather than N+1, because the first read of a file counts as sequential — a fresh
ReadPatternhaslastOffsetandlastSizeboth zero, sooffset == lastOffset+lastSizeholds at offset 0. That makesmin_sequential: 3mean the third read of a file, which is what the configuration documentation says. I had the arithmetic off by one on the first attempt and the test caught it.Two stale comments elsewhere were corrected rather than left:
ReadAheadConfig's note on the removedMaxDistancefield, andTestPrefetchStopsAtEndOfFile's explanation of why its file is 16 steps long — which had relied on the seven-read figure, and which the new threshold makes generous rather than marginal.Gates
go build ./...·go vet ./...·gofmt -l .— cleango test -count=1 -race -covermode=atomic ./...— exit 0./scripts/coverage-gate.sh— 35 packages at or above floorgolangci-lint --new-from-merge-base=origin/main— 0 issuesgosec ./internal/fuse/ ./internal/config/— no findingsgo test ./internal/config/(doc/changelog gates) — ok