Skip to content

read-ahead has two sequential thresholds and only one is configurable #247

Closed

Description

@scttfrdmn

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_sequential is 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.NewDefault and
    fuse.DefaultReadAheadConfig both say 3, so the documented default does not describe the default
    behavior. examples/config.yaml now carries a paragraph explaining this, which is a doc comment
    standing in for a fix.
  • Above 6 the confidence floor becomes redundant and min_sequential governs 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:

  1. Drop the confidence floor from the gate and let min_sequential mean what it says. confidence
    is still computed and still on ReadPattern; nothing else reads it. This makes min_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.
  2. 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

  1. added
    type: bug
    priority: low
    area: fuse
    area: config
    effort: small
    on Aug 3, 2026
  2. scttfrdmn commented on Aug 3, 2026

    @scttfrdmn
    OwnerAuthor

    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 OnRead directly with a stub queue:

    min_sequential first prefetch on read #
    1 6
    2 6
    3 6
    4 6
    5 6
    6 6
    7 7

    max(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_sequential GETs bytes ratio
    1, 2, 3, 4, 5, 6, 7, 10 24 3,145,728 1.0000x

    Identical throughout, because FileSystem.fetch shares 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:

    run length min_sequential: 3 min_sequential: 6
    3 reads 1.3333x (waste 131,072) 1.0000x
    4 reads 1.2500x (waste 131,072) 1.0000x
    5 reads 1.2000x (waste 131,072) 1.0000x
    6 reads 1.1667x (waste 131,072) 1.1667x (waste 131,072)

    Note the last row: at a 6-read run, min_sequential: 6 wastes 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:

    confidence is 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.yaml paragraph 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 recommending min_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_AfterEnoughHits 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. 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 >= 1 fails 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 ReadPattern has lastOffset and lastSize both zero and so offset == lastOffset+lastSize holds at offset 0. min_sequential: 3 therefore means the third read of a file — which is what the configuration documentation claims, so no doc change was needed there.

  3. added a commit that references this issue on Aug 3, 2026
    ced363d
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    area: configarea: fuseeffort: smallpriority: lowtype: bug

    Type

    No type

    Projects

    No projects

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions