Case file: PR #734 — selene: parallelize startup disk scan and coalesce small header reads
https://github.com/NVIDIA/hyperflare-inference/pull/734 · draft · base main @ 22d2ac9 · head 015076e · opened & last updated 2026-12-04 · labels area:selene, performance
Key findings
- The motivation has no issue, bug report or maintainer request behind it. The tracker contains no report about slow startup scanning; searches for "startup disk scan / recovery / record directory scan" return only #734 itself. The scale argument in the description (
MAX_DISK_RECORDS = 4096caps the input store atselene/src/input.rs:26;.ckptdirectories are bounded only by--prefix-cache-disk-limit) is checkable and plausible, but the problem statement is the PR's own. - It is the third PR in a series by the same author applying one pattern to Selene I/O — #497 (bounded
std::thread::scopehashing in the restore path, merged 2026-11-29) and #496 (read coalescing in the fetch path, merged 2026-11-29). #734 moves the same two ideas into the startup scan path. Nothing is reversed or superseded; #496/#497 are complementary, not overlapping. selene-manageris only half covered, contrary to how the description reads.record::scanis delegated to (selene-manager/src/disk.rs:101), but the pre-pass that opens every.ckptto find identity/fingerprint (selene-manager/src/disk.rs:71-98,Header::read_metadata(File::open(...))at:77) is still a sequential QD=1 loop;par_mapispub(crate)(selene/src/shared/record.rs:1148) so selene-manager cannot reuse it.- The coalesced read only helps
.ckptheaders..inputrecords are inspected byinspectatselene/src/input.rs:1008-1030with a plainread_exact(&mut h[..88]); they never go throughHeader::read_metadata, so the.inputwin is parallelism only. Correspondingly, the only declared regression is on the.inputwarm path. - The author declares one real regression: warm
InputStore::start_boundedon x86_64, 1,000 files: 2.09 → 2.53 ms (0.83x, +0.44 ms), attributed to thread-scope setup plusentries.sort()and explicitly "not separately isolated by ablation". This is a served path (container restart with warm page cache) getting measurably slower, in exchange for 8.36x cold. - Evidence does not meet the repo's served-workload rule. AGENTS.md/charter require performance PRs to show a speedup on a served workload (#210); the description itself says these are "isolated component microbenchmarks, not end-to-end
flare runstartup timings". Also, the ~200-line harness lives in an uncommittedselene/examples/scan_bench.rs(not opened) (onlyrank_nodeis declared inselene/Cargo.toml:57-59), so the numbers cannot be reproduced from the branch, only by pasting the description. - Undeclared behavioural changes beyond performance:
.tmp/invalid/.input.pendingdeletion is now deferred to a second pass, so a mid-scanUnreadableerror leaves garbage on disk that the old code would have removed before failing; and.inputadmission order is now lexicographic (selene/src/input.rs:552), which changes which records survive a tightDiskBudget/MAX_DISK_RECORDS. - Process: draft, no CI on the head commit, no comments, reviews or reactions. The repo's
native-serving.ymldoes run selene tests onwindows-2022(.github/workflows/native-serving.yml:48-55(not opened)), which would partly cover the one admitted gap (no native Windows execution). - No compatibility surface changes: no on-disk v3/v4
.ckpt/.inputformat change, no protobuf/wire change, no new dependency, nounsafein production code, no flag or metric rename.read_metadata's new read-ahead is cursor-unsafe for apub fn, but all five callers either drop the handle or use positional reads (verified). - The win lands in an operator-visible, already-timed phase:
record::scanandInputStore::start_boundedboth run insidePrepare host prefix cache, which emitson_step("scanning disk records")and recordstimings.disk_scan(selene/src/offload.rs:750-765,:767-779), a timing added by merged PR #625 and documented atdocs/prefix-cache-offload.md:1070-1076. #734 adds no metric of its own.
The change
Size: +554/−30 in 2 files (pr_files), matching the description's arithmetic (+135/−30 production, +419 test LOC; 554 − 419 = 135).
selene/src/shared/record.rs+424/−23;selene/src/input.rs+130/−7.
1. Coalesced metadata read — Header::read_metadata (selene/src/shared/record.rs:357-397). Baseline on main is vec![0; HEADER_BYTES] + read_exact, then a second read_exact for the v4 directory tail (selene/src/shared/record.rs:354-370 at ref main). The new version fills a stack buffer of HEADER_BYTES + 4096 in a read() loop that tolerates short reads and retries ErrorKind::Interrupted, so v3 headers and v4 directories ≤ 4 KiB cost one syscall; larger v4 directories (up to packed::MAX_DIRECTORY, selene/src/shared/packed.rs:17 (not opened)) fall back to one read_exact tail. The doc comment now states "May read ahead past the end of the metadata … callers must not rely on the reader cursor position after this returns" (:359-360). Note the read-ahead can pull up to 4 KiB of the first page segment into the buffer and discard it; harmless for every current caller (below).
2. Bounded parallel map — par_map (selene/src/shared/record.rs:1142-1192), pub(crate): threshold 64 items, chunk 8, at most 16 workers from available_parallelism().map_or(4, ..); std::thread::scope + Builder::name("flare-scan").spawn_scoped(..).ok() (a failed spawn silently degrades capacity), calling thread participates, results re-sorted by index so order is preserved; below threshold or with one worker it degrades to a serial iter().map.
3. record::scan restructured — selene/src/shared/record.rs:1209-1278: collect candidate names/symlink flags from fs::read_dir, par_map over fs::symlink_metadata (never follows symlinks; !metadata.is_file() → Absent) and inspect, then a serial reduction that returns the first Inspection::Unreadable(error) before any deletion, then a removal pass for .tmp/invalid paths, then unchanged remove_orphans (:1280+) with its deterministic (consumed_tokens, digest) ordering.
4. Worker::scan restructured — selene/src/input.rs:514-587: collect .input and .input.pending paths without deleting anything inside read_dir, entries.sort() (:552), par_map(inspect), return the first non-InvalidData error (:554-562) before unlinking temporaries or mutating self.disk/self.budget, then delete temporaries and apply the unchanged serial budget/MAX_DISK_RECORDS admission loop (:568-585).
Tests added (inside the same two files): single-read/EINTR/short-read/truncation coverage for read_metadata (:2474+), parallel_scan_handles_large_mixed_v3_v4_directory_deterministically (also pins that dangling and live symlinks, subdirectories and foreign files survive), parallel_scan_preserves_directory_on_unreadable_entry and an input-side variant that asserts corrupt/over-budget/.pending/blocked files all survive an unreadable-entry failure and the budget is untouched (selene/src/input.rs:1643-1750).
What the description does not say (verified in the diff)
- Deletion is deferred and skipped on failure. In
record::scan, removals now happen in a second pass (:1274-1276); previously.tmpand invalid files were removed inline (mainselene/src/shared/record.rs:1174-1185). Net effect is the same on success; on a mid-scanUnreadableerror everything the old code had already deleted stays. Same intentional fail-closed change for.input.pending(selene/src/input.rs:540-567), which used to be unlinked as encountered insideread_dir. .inputadmission order is now lexicographic (:552). Under a tightDiskBudget/MAX_DISK_RECORDSthis changes which records survive a restart, not just how fast the scan runs; the new testparallel_scan_recovers_large_directory_deterministically_under_tight_budget(selene/src/input.rs:1645+) pins the new order (first 80 by sorted name kept, rest deleted).- Failures now complete all inspections before reporting.
par_maphas no early abort, so a directory of thousands of files pays the whole inspection cost before returning the first error; and the reported error is the first non-InvalidDataone in sorted order (:554-561,swap_remove). selene-manager's pre-pass is still sequential (see Key finding 3).- Symlink semantics are unchanged — neither followed nor deleted, live symlink to a regular file is treated as
Absent(selene/src/shared/record.rs:1246-1258; input side relies onentry.file_type()atselene/src/input.rs:530-535). The new tests lock that in. - The
.inputread path is untouched —inspectstill doesFile::open+metadata()+read_exactof the 88-byte header (selene/src/input.rs:1008-1030;HEADER = 88at:21). No coalescing there. par_mapbypasses Selene's existing rayoncpu_pool(selene/src/shared/codec.rs:37-60), so the scan does not inherit the codec pool's nice policy.
Description claims that check out
- "all five callers in
seleneandselene-managereither drop the file handle or use positionalread_exact_at" — verified:selene/src/shared/record.rs:1334(handle dropped ininspect),selene/src/disk.rs:1478(later reads positional:read_exact_atatselene/src/disk.rs:1464, io_uring submits explicitspan.offset),selene/src/shard.rs:1202and:1251(inline open, dropped),selene-manager/src/disk.rs:77(temporary dropped each iteration). Plus test-only callers (selene/src/offload/sharded/tests.rs:450-451(not opened),selene-manager/tests/packed.rs:526(not opened),:2474+). - "
0productionunsafe,0new dependencies" — verified; the onlyunsafeadded islibc::geteuid()-style code in a#[cfg(unix)]test;Cargo.tomluntouched. - "+105 net production LOC" — arithmetically consistent with
pr_filescounts.
The why
The description's argument: recovery inspects every cached .ckpt and .input file sequentially at QD=1, with two blocking read() calls per v4 header, so local NVMe queue depth is unused and startup stalls; caches hold "hundreds to tens of thousands of records".
- No filed issue or report. No tracker item asks for faster startup scanning; the nearest operator-visible startup complaints are #616 (closed) "v0.4.4 takes over 15 minutes to prepare a 119 GiB host prefix cache on fragmented Linux memory" and its fix #625 (merged 2026-12-01), which was about host slab population/THP compaction in
eos::map_host, not the record scan — but #625 is what added the per-stepscantiming that makes #734's target visible (docs/prefix-cache-offload.md:1070-1076,helios/src/runtime_core/model.rs:1049). - No long-standing request history. The sequential scan shape dates back to the original record store; the only prior latency work in this file family was fetch/restore-side (#496, #497). This is the first startup-latency PR in the area.
- Scale bounds are checkable:
.inputrecovery is capped atMAX_DISK_RECORDS = 4096(selene/src/input.rs:26), soWorker::scansees at most ~4,096 relevant files; the.ckptdirectory is bounded only by the disk limit (defaultfree_space/10,selene/src/offload.rs:658-664), so tens of thousands are plausible. The benchmark's 500/2,000/10,000 rows map onto that.
Related work
- #497 (merged 2026-11-29) "Reduce disk offload restore latency and integrated-memory intake overhead" — same author, same pattern: bounded
std::thread::scopeparallel xxh3 hashing inselene/src/disk.rs(MAX_HASH_THREADS = 4, inline fallback when a helper cannot spawn) plus a single-read raw open. #734 reuses the pattern for scanning; the coalescing is in a different path (scan vs restore), so they are complementary. #497's Autobot review flagged "available_parallelism()per batch" — #734 computes it once perpar_mapcall (:1149). - #496 (merged 2026-11-29) "Coalesce shared ancestor reads across concurrent Selene disk fetches" — same author, also touches
selene/src/shared/record.rs(Header: Hash,packed::LayoutEq/Hash) for the fetch path; does not overlapread_metadataorscan. - #610 (merged 2026-11-29, yatesdr) "fix(selene): fix local storage tier, input cache, sharding, and codec edge cases" — last commit (
a56333a0) to either changed file; reworkedinput.rsscan/eviction error handling. #734 composes with it: the fail-closed deletion rule and budget accounting are refinements, not reversals. - #625 (merged 2026-12-01) and #616 (closed issue) — see above; #625 supplies the measurement surface, #616 is the adjacent startup complaint that is not this problem.
- No competing or stacked PRs. No open PR touches these files (#729, #725, #715, #703 are other areas; #703 is a helios/selene DRAM-spill retry storm, unrelated to startup scanning). Nothing on
mainsince22d2ac9touches the two changed files, so there is no rebase conflict. - Unaddressed neighbours: #703 (retry storm under DRAM spill), #78 (Engram disk first-touch latency), #189 (closed: startup row thinning overflow).
- Nothing in the repo is undone or superseded by #734.
Recent activity
selene/src in the last 60 days is dominated by yatesdr (38 commits), then Luke Alonso (7), Martin Vit (2). Recent, directly relevant: #694 (write-side NVMe / pool spill profitability gate, 2026-12-04), #674 (prefix-cache hit rate, L1 retention, NVMe throughput, GPU snapshot packing), #625 (offload startup timings — the hook #734's improvement shows up in), #612/#611/#610 (selene-manager and selene hardening/fixes). #734 builds on this work and conflicts with none of it: no shared hunks, no format changes, no reversal of the hardening PRs.
People
- Author: FujitsuPolycom (repo association CONTRIBUTOR; Discord "Dooner" per the description). In the last 180 days: 20 merged, 12 closed, 0 open PRs — a steady, mostly-merged contributor. Recent work: helios scheduler tuning (#697, #681, #661, #660), helios prefix-cache eviction (#665), RoCE proxy opcodes (#649, closed), export/offload acceleration (#586, #587, #585, #588). Their merged history is docs (15) and helios/src (15) heavy, with only 4
heliopause/srcand 4ignition— i.e. selene is not their usual area; #496 and #497 were their first Selene PRs. - Customary owners of the touched area: yatesdr (38 commits in
selene/src), Luke Alonso, Martin Vit. None has engaged on #734. - Engagement so far: none.
pr_commentsreturns "No comments"; no reviews, no reactions, no triage labels beyondarea:selene/performance(contrast #496/#497, which carriedtriage:validation/triage:reviewand went through multiple Autobot review rounds with rebases).
Community
Zero comments, zero reviews, zero reactions at the time of this case file. The description is unusually complete (four-part why/what/result/evidence structure, two architectures, interleaved A-B-B-A method, explicit limitations), which is consistent with the author's history of answering review rounds on #496/#497. Interest is currently nil; the PR is a same-day draft.
Project fit
- Squarely within charter goals: "Store prefix-cache checkpoints in host memory and share them across Flare instances via Selene" (charter line 24). Startup recovery of that disk tier is core Selene work. No per-model branch, no new flag, no new dependency — nothing that would trip the "keep the runtime small and model-agnostic" constraint (charter line 12).
- Docs:
AGENTS.md:233asks Selene/offload changes to account fordocs/prefix-cache-offload.md,selene-manager/README.md(not opened),selene-manager/PROTOCOL.md(not opened). #734 changes no docs. The documented scan contract it must preserve is atdocs/prefix-cache-offload.md:677-680(validate magic/version/identity/fingerprint/name, derive row presence from size, seed access order from mtime, delete temporaries and missing-parent nodes) — preserved — plus:113-116(v3 readers prune v4.ckptfiles during the startup scan) and:746(referencesHeader::read_metadatadirectly, so the coalescing changes behaviour of a documented routine). The documented operator-visiblescanduration (:1070-1076) will shrink without any doc note, andselene-manager/src/disk.rs's still-sequential pre-pass means the documented per-directory recovery cost is only partly improved. - Evidence rule tension: charter/AGENTS.md require served-workload benchmarks for performance PRs (#210); the description concedes the numbers are isolated component microbenchmarks. AGENTS.md:110-112 also requires reproduction commands that identify inputs directly — the harness is not in the diff (
selene/Cargo.toml:57-59declares only therank_nodeexample).
Claims and evidence
| Claim | Evidence | Verdict |
|---|---|---|
Cold scan speedups, 9–11x at 10,000 .ckpt on both arches |
Author's bare-metal benchmark, medians + p10–p90, interleaved A-B-B-A, control 22d2ac9 vs candidate 015076e |
Self-reported, not independently reproduced; methodologically described in unusual detail, but harness uncommitted |
| Warm scan speedups 1.38x/1.85x/2.28x (x86_64) and 2.39x/3.14x/2.99x (aarch64) | same | Self-reported; much weaker than cold, as expected for page-cache-warm metadata |
Cold InputStore::start_bounded 8.36x / 9.02x |
same | Self-reported; consistent with parallelism over 1,000 files |
Warm InputStore::start_bounded 0.83x on x86_64 (2.09 → 2.53 ms, +0.44 ms) |
declared by the author, attributed to thread-scope setup + entries.sort(), "not separately isolated by ablation" |
Honest disclosure of a real regression on a common path; cause unproven |
aarch64 warm distributions bimodal, arms overlap on InputStore |
author says so | Declared; cold cells do not overlap (max(cand) ≪ min(ctrl)) |
591 selene tests (590 lib + 1 integration) with test-support, 566 with --no-default-features, on bare-metal GB10 and x86_64 container, non-root |
author-reported counts, three rustc versions | Plausible and far above the 522/475 quoted in #496/#497 after ~10 days of main growth; not verifiable without CI |
| Full-suite counts: helios 1,976; flare 247; flare-cli 224; selene-manager 205 + 98; pytest 4 | author-reported | Not verifiable without CI |
| read-ahead is cursor-safe | verified in code (five call sites) | Confirmed |
0 unsafe, 0 new deps, formats unchanged |
verified in diff | Confirmed |
selene-manager benefits |
partially — only the scan call, not its identity pre-pass |
Overstated in effect |
| Windows correctness | statically audited only, never executed | Admitted gap; windows-2022 CI in native-serving.yml:48-55 would exercise the non-#[cfg(unix)] new test once run |
Impact on end-to-end flare run startup |
not measured | Missing; also missing: RSS/CPU cost of up to 16 extra threads at startup, and any measurement with a cold page cache smaller than the cache directory |
| Attribution between the two mechanisms (coalesced read vs parallelism) | no ablation | Missing — #497's review asked for exactly this kind of separation |
Reach
- Users/operators: every
flare runusing the local disk prefix-cache tier (--prefix-cache-disk/--prefix-cache-disk-limit) and everyselene-managerinstance serving a record root; in multi-host setups, every rank. Startup timing in thePrepare host prefix cachephase changes (faster cold, marginally slower in the warm.inputcase) with no metric, flag or default change. - Compatibility: none broken. On-disk v3/v4
.ckptand.inputlayouts unchanged (all I/O still throughHeader::encode/packed_metadata), protobuf/wire untouched, model core loading untouched, no dependency change,.inputheader stays 88 bytes. The one soft API change:read_metadatais apub fnwhose reader cursor is now left mid-file (up to 4 KiB in), documented but not type-enforced (selene/src/shared/record.rs:359-361). - Deployment: up to 16 short-lived
flare-scanthreads created only for directories with ≥ 64 candidates, during startup before serving begins;available_parallelism()is cgroup-quota aware so the pool shrinks under CPU limits; no priority/nice adjustment, no interaction with CUDA or model worker threads. - Other crates:
record::scanispuband used byhelios/src/offload/gpu_tests.rs(not opened) (4 sites),selene-manager/tests/{client,packed}.rs,selene/tests/mixed_codec_root.rs(not opened) — same signature and same deterministic ordering guarantee. - Not addressed: the sequential
selene-manageridentity pre-pass (selene-manager/src/disk.rs:71-98).
Process
- Draft, opened and last updated 2026-12-04 (same day as this case file). No CI checks on head
015076e. No reviews, no comments, no reactions. Labelsarea:selene,performance; notriage:*label yet. - Base/head relationship:
git archiveof015076eapplies cleanly onmain@22d2ac9; no commits on main since touch the two files. - Precedent: the author's #496/#497 went through multi-round review (Changes Requested → Ready To Merge); a similar cycle is likely here.
Open questions / what could not be found
- Where did the problem come from? No issue, no user report, no maintainer request. Would a maintainer confirm the scan is a real startup bottleneck in a served deployment (and at what record counts)?
- End-to-end effect on
flare run'sPrepare host prefix cachephase (the timing exists via #625) — nothing measured. - Split of the win between read coalescing and parallelism; especially whether the 0.83x warm
.inputregression would disappear withoutentries.sort()or with the existing rayon pool. - Why raw scoped threads instead of the existing rayon
cpu_pool(selene/src/shared/codec.rs:37-60)? A deliberate choice (nice/policy isolation) or a convenience? - Intended permanence of the deferred-deletion/fail-closed semantics — this looks like a deliberate hardening addition riding along with a performance PR, and is not called out as such.
- Will the benchmark harness be committed? AGENTS.md asks for reproducible inputs; the only harness is ~200 lines pasted in the description.
- Windows: nothing executed; CI would cover it once checks run.
- Not found: any reaction from yatesdr/other
selene/srcowners; any prior discussion of the.inputscan ordering guarantee that the newsort()establishes.