Repository navigation
selene: parallelize startup disk scan - #74
Closed
FujitsuPolycom wants to merge 1 commit into
Closed
FujitsuPolycom wants to merge 1 commit into
FujitsuPolycom wants to merge 1 commit into
Conversation
FujitsuPolycom
force-pushed
the
perf/selene-parallel-startup-scan-r2
branch
from
December 5, 2026 00:07
6962733 to
3314ce1
Compare
Startup recovery in Selene (`selene/src/shared/record.rs::scan` and
`selene/src/input.rs` `Worker::scan`) inspects every cached `.ckpt` and
`.input` file sequentially (`QD=1`). On local NVMe caches holding
hundreds to tens of thousands of records, serial metadata inspection
leaves storage queue depth unused and stalls `Prepare host prefix cache`
during server startup.
Changes:
- `selene/src/shared/record.rs` (`par_map`, `record::scan`):
- Before: inspected `.ckpt` and `.tmp` entries sequentially in
`fs::read_dir` order and unlinked invalid entries inline.
- After: pre-filters candidate `.ckpt` and `.*.tmp` paths
(`Vec<PathBuf>`) and, at 64 or more items, runs `fs::symlink_metadata`
(never following symlinks) and `inspect` across bounded threads
(`available_parallelism().min(16)` via `std::thread::scope` and
chunk size 8). Workers use fallible `Builder::spawn_scoped` named
`flare-scan` with calling-thread participation, return per-chunk
`(start, Vec<R>)` blocks for order restoration, and close all file
handles before scope exit for Windows handle-close-before-unlink
safety. The sequential reduction pass fails closed, returning the
first `Unreadable` error before deleting `.tmp` or invalid entries
and preserving deterministic `remove_orphans` ordering
(`(consumed_tokens, digest)`). `selene-manager/src/disk.rs::recover`
delegates full directory scans to `record::scan`.
- `selene/src/input.rs` (`Worker::scan`):
- Before: unlinked `.input.pending` files inline during `fs::read_dir`
and inspected `.input` files sequentially.
- After: defers `.input.pending` removal, sorts `.input` paths in
lexicographic `OsStr` order
(`sort_unstable_by(|a, b| a.as_os_str().cmp(b.as_os_str()))`, avoiding
`Path::cmp` component parsing), inspects headers in parallel via
`record::par_map`, rejects non-`InvalidData` I/O errors before
unlinking `.input.pending` or mutating `self.disk`/`self.budget`,
and admits records deterministically under `MAX_DISK_RECORDS` and
`DiskBudget`.
- `docs/prefix-cache-offload.md`: documents that unreadable `.ckpt` and
`.input` entries fail startup scans before deleting temporary, invalid,
or over-budget files, that `.input` startup also fails if removing
those files fails, and that `.input` recovery admits files in
lexicographic path order.
- Compatibility: on-disk v3/v4 `.ckpt` and `.input` record formats,
Protobuf wire schemas, and model core loading are unchanged. Zero
production `unsafe` and zero new dependencies.
Expected and measured scope:
- Parallelizing metadata inspection up to 16 workers reduces cold and warm
local NVMe scan time on directories at or above the 64-entry threshold
while preserving deterministic order and fail-closed cleanup. Sorting
`.input` paths by raw `OsStr` keeps recovery deterministic without
`Path::cmp` component-parsing overhead on warm scans.
- End-to-end `flare run` `Prepare host prefix cache` startup A/B and
local NVMe component measurements comparing this commit against its
`main` base are recorded in the pull request description.
Evidence and limitations:
- Unit tests in `selene/src/shared/record.rs` and `selene/src/input.rs`
cover single-field `Header.packed` equality/hash isolation, large
mixed v3/v4 deterministic parallel `.ckpt` scans (preserving foreign
files, subdirectories including `.dir.tmp`, and dangling and
live-target Unix symlinks including `.link.tmp`), deterministic
parallel `.input` recovery under tight `DiskBudget` (seeded in
non-monotonic odd-then-even order so admission fails without sorting
on FIFO, LIFO `tmpfs`, and hash-indexed `ext4` filesystems), and
fail-closed preservation on unreadable `.ckpt` and `.input` entries
(seeding temporary, invalid/corrupt, and valid/over-budget siblings
both before and after the `0o000` entry).
- Release crate suites (`selene` with `--features test-support` and
`--no-default-features --lib`, `helios --features runtime-core,server`,
`flare --lib`, `flare-cli --bins`, `selene-manager --lib`, and
`pytest tests/preparation/test_core_boundary.py`) execute on clean
non-root archives of this commit on Linux (`x86_64` and `aarch64`).
- Limitation: native Windows execution (including handle-close-before-
unlink under concurrency) is audited statically and not executed on a
Windows host.
Discord: Dooner
Design-Signed-Off-By: Antigravity (Gemini 4 Neon); design-review=2e5b
Signed-off-by: FujitsuPolycom <87842395+FujitsuPolycom@users.noreply.github.com>
FujitsuPolycom
force-pushed
the
perf/selene-parallel-startup-scan-r2
branch
from
December 5, 2026 00:51
3314ce1 to
b7bd3fa
Compare
Owner
Author
|
Published b7bd3fa to NVIDIA#734 in place. |
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.
Why
Startup recovery in Selene (
selene/src/shared/record.rs::scanandselene/src/input.rsWorker::scan) inspects every cached.ckptand.inputfile sequentially (QD=1). On local NVMe caches holding hundreds to tens of thousands of records, serial metadata inspection leaves storage queue depth unused and stallsPrepare host prefix cacheduring server startup.What changed
Parallelized startup file inspection across bounded threads with
0productionunsafeand0new dependencies. On-disk v3/v4.ckptand.inputformats, Protobuf wire schemas, and model core loading are unchanged.par_mapandrecord::scan(selene/src/shared/record.rs):.ckptand.tmpentries sequentially infs::read_dirorder and unlinked invalid entries inline..ckptand.*.tmppaths (Vec<PathBuf>) and, at64or more items, runsfs::symlink_metadata(never following symlinks) andinspectacross bounded threads (available_parallelism().min(16),std::thread::scope, chunk size8). Workers use fallibleBuilder::spawn_scopednamedflare-scanwith calling-thread participation, return per-chunk(start, Vec<R>)blocks for order restoration, and close all file handles before scope exit for Windows handle-close-before-unlink safety. The sequential reduction pass fails closed: it returns the firstUnreadableerror before deleting.tmpor invalid entries and preserves deterministicremove_orphansordering ((consumed_tokens, digest)).selene-manager/src/disk.rs::recoverdelegates full directory scans torecord::scan.Worker::scan(selene/src/input.rs):.input.pendingfiles inline duringfs::read_dirand inspected.inputfiles sequentially..input.pendingremoval, sorts.inputpaths in lexicographicOsStrorder (sort_unstable_by(|a, b| a.as_os_str().cmp(b.as_os_str())), avoidingPath::cmpcomponent parsing), inspects headers in parallel viarecord::par_map, rejects non-InvalidDataI/O errors before unlinking.input.pendingor mutatingself.disk/self.budget, and admits records deterministically underMAX_DISK_RECORDSandDiskBudget.docs/prefix-cache-offload.md): Documents that unreadable.ckptand.inputentries fail startup scans before deleting temporary, invalid, or over-budget files, that.inputstartup also fails if removing those files fails, and that.inputrecovery admits files in lexicographic path order.Result
All measurements below compare clean
git archive be4092d7e1f0efe8a16049568c12ec7b841a2e8e(NVIDIA/hyperflare-inference:maincommit parent and benchmark control) vs cleangit archive b7bd3fa9032f4ee306f0995495ed6dd463818ada(candidate), built--locked --releaseon plain local NVMeext4.1. End-to-end
flare runstartup A/B (Prepare host prefix cache&timings.disk_scan)Measured on bare-metal
aarch64GB10 (20-core Grace, localSamsung MZALC4T0HBL1NVMeext4) booting a signed TP1Qwen4-35B-A3B-NVFP4core with--prefix-cache-disk,--prefix-cache-disk-limit 2000G, and--lossless-kv-compression cpu.flare runonce with--prefix-cache-drain-on-shutdown=30sand one 443-token chat request to drain a genuineQwen4-35B-A3B-NVFP4.ckptfile and observe its exact namespace,identity,fingerprint,page_tokens = 64,ranks, andbucket. Seeded that namespace directory with10,000valid.ckptfiles (1,00010-step chains,tail_pages = 1, sparse payloads sized toh.length_with_row()):5,000v3 files of69,779,456bytes each and5,000v4Representation::Literalfiles (500step-0 files of69,775,483bytes and4,500step 1–9 files of69,775,487bytes, wherePackedOfferProtobuf varints encode nonzerofirst_page/logical_index), totaling697,774,713,000logical bytes (649.85 GiB), plus1,000.inputfiles (4,440bytes each). Every single boot verified10,000scanned records inPrepare host prefix cache,flare_host_cache_disk_records == 10000andflare_input_cache_disk_records == 1000on/metrics, HTTP/healthready, and10,000.ckpt+1,000.inputfiles untouched after cleanSIGTERMshutdown (0deletions,0rejections across all22boots).n=5interleaved Cold boots per arm (sync && echo 3 > /proc/sys/vm/drop_cachesbefore every boot) andn=5interleaved Warm boots per arm after1warm-up boot per arm.Prepare host prefix cachewall time is measured directly from flushed redirected stderr[ PENDING ]->[ OK ]timestamps;scan(timings.disk_scan) and phase totals areflare run's printed{:.1}svalues; values are medians withmin–maxranges.flare runStartup Metric (10,000.ckpt+1,000.input,n=5/arm)be4092d7)b7bd3fa9)Prepare host prefix cachewall time (stderr pipe)drop_caches)2,542.00(2,373.92–3,630.11) ms295.44(283.98–346.06) ms8.60x(-2.25 s)timings.disk_scan(scan, printed0.1sres)drop_caches)2.2(2.1–3.4) s0.2(0.2–0.3) s-2.0 sPrepare host prefix cacheprinted total (0.1sres)drop_caches)2.5(2.4–3.6) s0.3(0.3–0.3) s-2.2 s/healthreadydrop_caches)17.57(17.08–18.94) s15.36(14.96–15.74) s-2.21 s(-12.6%)Prepare host prefix cachewall time (stderr pipe)95.58(90.82–97.36) ms53.20(52.30–54.06) ms1.80x(-42.38 ms)timings.disk_scan(scan, printed0.1sres)0.1(0.1–0.1) s0.0(0.0–0.0) s-0.1 s/healthready14.71(14.53–14.75) s14.64(14.29–15.10) s-0.06 s(within boot noise)2. Component scan benchmarks &
.inputsort ablationInterleaved mirrored rounds on plain local NVMe
ext4using an uncommittedflare-selenepublic-API harness (scan_bench.rs), reporting medians (p10–p90in parentheses;10Cold roundsn=20/arm withdrop_cachesbefore every invocation,20Warm roundsn=40/arm after1warm-up pass per arm)..ckptdatasets hold50%v3 ∥50%v4 10-step chains (1rank,4 KiBplane/row,TAIL_PAGES = 4,PAGE_TOKENS = 64);.inputdatasets hold1,0004,440-byte files.Bare-metal
aarch64GB10 NVMe (record::scan,n=20Cold ∥n=40Warm):be4092d7)b7bd3fa9)record::scan500.ckpt119.44(103.62–153.22) ms11.19(10.08–11.97) ms10.68xrecord::scan500.ckpt3.31(2.28–4.13) ms1.70(1.34–1.88) ms1.94xrecord::scan2,000.ckpt466.08(422.01–636.24) ms43.80(41.94–45.61) ms10.64xrecord::scan2,000.ckpt15.53(9.86–16.44) ms4.81(3.80–5.04) ms3.23xrecord::scan10,000.ckpt2,122.11(2,083.26–3,033.40) ms211.29(199.84–267.23) ms10.04xrecord::scan10,000.ckpt61.43(51.77–64.07) ms16.54(16.08–20.98) ms3.71xInputStore::start_bounded(1,000.inputfiles) sort and concurrency ablation:be4092d7, unsorted seq)OsStr::cmpseq (nopar_map)Path::cmp+par_map(ablation)b7bd3fa9,OsStr::cmp+par_map)aarch64GB10 NVMe, Cold (n=20)214.43(209.18–304.87) ms218.11(209.74–323.54,0.98x) ms23.96(22.10–27.13,8.95x) ms23.16(21.25–24.32) ms9.26xaarch64GB10 NVMe, Warm (n=40)4.73(3.24–5.24) ms5.28(3.32–5.51,0.90x) ms3.55(2.57–3.68,1.33x) ms2.50(1.94–2.62) ms1.89xx86_64Linux NVMe, Warm (n=40, WSL2ext4)4.40(4.29–4.66) ms4.55(4.38–6.74,0.97x) ms3.05(2.78–3.34,1.44x) ms2.60(2.28–2.86) ms1.69xSorting
.inputpaths by rawOsStr(sort_unstable_by(|a, b| a.as_os_str().cmp(b.as_os_str()))) avoidsPath::cmpcomponent parsing on1,000warm files (3.05 -> 2.60 msonx86_64, raising warm speedup from1.44xto1.69x;3.55 -> 2.50 msonaarch64GB10, raising warm speedup from1.33xto1.89x) while keeping recovery order deterministic.Evidence & Limitations
Verified on clean
git archive b7bd3fa9032f4ee306f0995495ed6dd463818adaatopNVIDIA/hyperflare-inference:mainbe4092d7e1f0efe8a16049568c12ec7b841a2e8e(git merge-tree --write-treeclean:bf2ee0ef12c283b709a409486d77751b92e6e66e):aarch64GB10 non-root NVMe--releasetests (uid=1000,rustc 1.99.1,1,945passed,0failed,8ignored):cargo test --locked --release --manifest-path selene/Cargo.toml --features test-support: 645 passed (644lib +1integration),0failed,0ignored (Unix0o000unreadable-entry tests and live-target symlink checks ran without skipping).cargo test --locked --release --manifest-path selene/Cargo.toml --no-default-features --lib: 620 passed,0failed,0ignored.cargo test --locked --release --manifest-path selene-manager/Cargo.toml --lib: 205 passed,0failed,1ignored.cargo test --locked --release --manifest-path flare/Cargo.toml --lib: 247 passed,0failed,4ignored.cargo test --locked --release --manifest-path flare-cli/Cargo.toml --bins: 228 passed,0failed,3ignored.x86_64Linux non-root--releasetests (uid=1000,rustc 1.100.0,3,287Rust +4Python passed,0failed,86ignored):cargo test --locked --release --manifest-path selene/Cargo.toml --features test-support: 645 passed (644lib +1integration),0failed,0ignored.cargo test --locked --release --manifest-path selene/Cargo.toml --no-default-features --lib: 620 passed,0failed,0ignored.FLARE_TEST_TEMPLATE_DIR=<dir> cargo test --locked --release --manifest-path helios/Cargo.toml --features runtime-core,server(11templates prepared viatests/frontend/prepare_templates.py): 2,022 passed (1,960lib +62integration),0failed,86ignored (49lib +37integration).pytest tests/preparation/test_core_boundary.py: 4 passed,0failed.header_eq_implies_same_hash(isolatingHeader.packedindependently ofpage_segment/row_segment),parallel_scan_handles_large_mixed_v3_v4_directory_deterministically(preserving foreign files, subdirectories including.dir.tmp, dangling symlinks, and live Unix symlinks including.link.tmp),parallel_scan_preserves_directory_on_unreadable_entry(seeding valid,.tmp, and invalid.ckptsiblings both before and after the0o000entry so pre-PR inline deletion fails on bothext4and LIFOtmpfs),parallel_scan_recovers_large_directory_deterministically_under_tight_budget(seeded in non-monotonic odd-then-even order(1..140).step_by(2).chain((0..140).step_by(2))so removingentries.sort_unstable_byfails on FIFO, LIFOtmpfs, and hash-indexedext4filesystems), andparallel_scan_preserves_directory_and_budget_on_unreadable_entry(seeding80valid/over-budget.input,16corrupt.input, and16.input.pendingfiles split before and after the0o000entry under tightDiskBudget).Reproduction harness (`scan_bench.rs`) and `flare run` startup A/B commands
.inputsort ablation harness (scan_bench.rs): Place the source below intoselene/examples/scan_bench.rsinside cleangit archivecheckouts ofbe4092d7andb7bd3fa9, build withcargo build --locked --release --manifest-path selene/Cargo.toml --example scan_bench, remove the example file, prepare datasets with<bin> prep-ckpt <dir> <500|2000|10000>and<bin> prep-input <dir> 1000, and run interleaved mirrored rounds of<bin> scan-ckpt <dir> <N>and<bin> scan-input <dir> 1000(withsync && echo 3 > /proc/sys/vm/drop_cachesbefore each cold run).flare runstartup A/B: Build--releaseflarefrom cleangit archive be4092d7andgit archive b7bd3fa9(cargo build --locked --release --manifest-path flare-cli/Cargo.toml --bin flare), boot once with--prefix-cache-disk <disk_cache> --prefix-cache-memory 1G --prefix-cache-drain-on-shutdown=30sand one 443-token chat request to drain a template.ckptfor the target core's namespace, then seed that namespace directory with10,000sparse.ckptfiles (1,00010-step chains,tail_pages = 1,file.set_len(h.length_with_row()):5,000v3 files of69,779,456bytes each and5,000v4Representation::Literalfiles —500step-0 files of69,775,483bytes and4,500step 1–9 files of69,775,487bytes — totaling697,774,713,000logical bytes /649.85 GiB) plus1,000.inputfiles (256-byte metadata +4,096-byte payload =4,440bytes each). Alternate boots (n=5Cold withsync && echo 3 > /proc/sys/vm/drop_cachesbefore every boot, then1warm-up per arm +n=5Warm) with:Timestamp redirected stderr
[ PENDING ]->[ OK ] Prepare host prefix cache.on every boot, verify HTTP/health(200), scrape/metricsassertingflare_host_cache_disk_records == 10000andflare_input_cache_disk_records == 1000, sendSIGTERM, and verify all10,000.ckptand1,000.inputfiles remain on disk.flare runstartup A/B exercised a single-GPU TP1 GB10 core (Qwen4-35B-A3B-NVFP4) with sparse seeded.ckptpayload bodies; multi-host TP startup scans and bare-metalx86_64flare runstartup timings were not run on this revision (warm.inputisolation onx86_64ran on local NVMeext4inside WSL2).Discord: Dooner