Skip to content

feat: skip O_DIRECT when the page cache is warm (sample-read gate) - #33

Open
AlperenKonukbay wants to merge 2 commits into
mainfrom
speed/hl-probe-v1
Open

feat: skip O_DIRECT when the page cache is warm (sample-read gate)#33
AlperenKonukbay wants to merge 2 commits into
mainfrom
speed/hl-probe-v1

Conversation

@AlperenKonukbay

@AlperenKonukbay AlperenKonukbay commented Jul 25, 2026

Copy link
Copy Markdown

The parallel reader always uses O_DIRECT, even when the node's page cache is already hot for the pack, leaving memory-speed reads unused. This adds a cheap gate: sample a few spread 16 MiB windows before committing; if mincore residency is high or the sampled bandwidth clears 5 GB/s, switch to buffered reads. Knobs: FLASHPACK_SAMPLE_PROBE, FLASHPACK_SAMPLE_PROBE_MIN_GBPS.

Measured on id-lora (38 GB per-request transformer re-reads, A/B apps differing by exactly this commit):

node page cache stock 0.4.0 this branch
warm (n=4/arm) 3.0–3.7 s (10–13 GB/s, O_DIRECT) 1.8–1.9 s (20–21 GB/s, buffered)
cold (n=3/arm) 2.7–3.0 s 3.2–3.3 s — small deficit, within the fleet's measured node-to-node disk variance

Same-seed outputs byte-identical across arms. The observed bandwidths match the independently measured tier ceilings, confirming the mechanism. Two honest notes: the warm figures come from one node pair per arm (replicated once on a fresh allocation), so treat the percentages as a band, not a point estimate; and on filesystem-warm but page-cold nodes the probe can clear the 5 GB/s threshold and flip to buffered early — that flip measured favorably where we saw it, but it means the gate is bandwidth-driven, not strictly "stay O_DIRECT until page-warm".

Summary claim: up to +40–50% on warm-cache nodes; when cold, no measurable regression beyond node variance (n=3/arm). Complementary to #30 — prefetch warms the cache, this gate is what lets reads use the warmth.

Alperen Konukbay added 2 commits July 22, 2026 11:16
…ng O_DIRECT

mincore can report 0.0 residency under cgroup-managed runners even when
the page cache is demonstrably hot (buffered repeat measured at 21.6 GB/s
right after a 0.0 reading), which silently forces every warm reload onto
the ~2x-slower direct path. Gate O_DIRECT behind a 4-thread 16 MiB spread
sample read: page-hot files scale with reader threads while cache-cold
reads saturate ~2-4 GB/s aggregate, so a 5 GB/s threshold separates the
tiers with margin. mincore remains the fast positive signal; the probe
only runs when mincore says cold. FLASHPACK_SAMPLE_PROBE=0 restores the
old behavior; FLASHPACK_SAMPLE_PROBE_MIN_GBPS tunes the threshold.
@AlperenKonukbay AlperenKonukbay changed the title feat: sample-gated buffered reads — stop O_DIRECT on page-warm nodes feat: skip O_DIRECT when the page cache is warm (sample-read gate) Jul 27, 2026
@GencSaracaydin

Copy link
Copy Markdown
Contributor

@fal-9000 can you review and report on the difference between O_DIRECT and buffered reads for warm caches

@jfischoff

Copy link
Copy Markdown
Contributor

Review by fal-9000 (GPT-5.6 Sol, xhigh) — reviewed at head b4caf08840c110d6930bb519bb4fbbc6e78d5b7f, posted on the agent's behalf while its write access to this repo is being enabled (see FEA-8199).

No correctness issue found.

On the O_DIRECT vs buffered question (@GencSaracaydin): O_DIRECT bypasses the page cache — a predictable cold path with no cache fill/pollution — but it cannot reuse warm pages; buffered reads can hit memory bandwidth when the cache is warm, but fill and compete for cache when cold. The mincore positive signal plus four spread 16 MiB timed samples is a sensible gate for choosing between them. The 5 GB/s cutoff is node/filesystem-specific, but the environment overrides and A/B evidence make the default reasonable.

Checks were green at review time.

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.

3 participants