Skip to content

selene: parallelize startup disk scan - #74

Closed
FujitsuPolycom wants to merge 1 commit into
mainfrom
perf/selene-parallel-startup-scan-r2
Closed

FujitsuPolycom wants to merge 1 commit into
mainfrom
perf/selene-parallel-startup-scan-r2

Conversation

@FujitsuPolycom

@FujitsuPolycom FujitsuPolycom commented Dec 4, 2026 •

Copy link
Copy Markdown
Owner

Why

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.

What changed

Parallelized startup file inspection across bounded threads with 0 production unsafe and 0 new dependencies. On-disk v3/v4 .ckpt and .input formats, Protobuf wire schemas, and model core loading are unchanged.

  • par_map and record::scan (selene/src/shared/record.rs):
    • 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), std::thread::scope, 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: it returns the first Unreadable error before deleting .tmp or invalid entries and preserves deterministic remove_orphans ordering ((consumed_tokens, digest)). selene-manager/src/disk.rs::recover delegates full directory scans to record::scan.
  • Worker::scan (selene/src/input.rs):
    • 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.
  • Documentation (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.

Result

All measurements below compare clean git archive be4092d7e1f0efe8a16049568c12ec7b841a2e8e (NVIDIA/hyperflare-inference:main commit parent and benchmark control) vs clean git archive b7bd3fa9032f4ee306f0995495ed6dd463818ada (candidate), built --locked --release on plain local NVMe ext4.

1. End-to-end flare run startup A/B (Prepare host prefix cache & timings.disk_scan)

Measured on bare-metal aarch64 GB10 (20-core Grace, local Samsung MZALC4T0HBL1 NVMe ext4) booting a signed TP1 Qwen4-35B-A3B-NVFP4 core with --prefix-cache-disk, --prefix-cache-disk-limit 2000G, and --lossless-kv-compression cpu.

  • Cache population: Booted flare run once with --prefix-cache-drain-on-shutdown=30s and one 443-token chat request to drain a genuine Qwen4-35B-A3B-NVFP4 .ckpt file and observe its exact namespace, identity, fingerprint, page_tokens = 64, ranks, and bucket. Seeded that namespace directory with 10,000 valid .ckpt files (1,000 10-step chains, tail_pages = 1, sparse payloads sized to h.length_with_row()): 5,000 v3 files of 69,779,456 bytes each and 5,000 v4 Representation::Literal files (500 step-0 files of 69,775,483 bytes and 4,500 step 1–9 files of 69,775,487 bytes, where PackedOffer Protobuf varints encode nonzero first_page/logical_index), totaling 697,774,713,000 logical bytes (649.85 GiB), plus 1,000 .input files (4,440 bytes each). Every single boot verified 10,000 scanned records in Prepare host prefix cache, flare_host_cache_disk_records == 10000 and flare_input_cache_disk_records == 1000 on /metrics, HTTP /health ready, and 10,000 .ckpt + 1,000 .input files untouched after clean SIGTERM shutdown (0 deletions, 0 rejections across all 22 boots).
  • Methodology: n=5 interleaved Cold boots per arm (sync && echo 3 > /proc/sys/vm/drop_caches before every boot) and n=5 interleaved Warm boots per arm after 1 warm-up boot per arm. Prepare host prefix cache wall time is measured directly from flushed redirected stderr [ PENDING ] -> [ OK ] timestamps; scan (timings.disk_scan) and phase totals are flare run's printed {:.1}s values; values are medians with min–max ranges.
flare run Startup Metric (10,000 .ckpt + 1,000 .input, n=5/arm) Cache Control (be4092d7) Candidate (b7bd3fa9) Speedup / Delta
Prepare host prefix cache wall time (stderr pipe) Cold (drop_caches) 2,542.00 (2,373.92–3,630.11) ms 295.44 (283.98–346.06) ms 8.60x (-2.25 s)
timings.disk_scan (scan, printed 0.1s res) Cold (drop_caches) 2.2 (2.1–3.4) s 0.2 (0.2–0.3) s -2.0 s
Prepare host prefix cache printed total (0.1s res) Cold (drop_caches) 2.5 (2.4–3.6) s 0.3 (0.3–0.3) s -2.2 s
Process spawn -> HTTP /health ready Cold (drop_caches) 17.57 (17.08–18.94) s 15.36 (14.96–15.74) s -2.21 s (-12.6%)
Prepare host prefix cache wall time (stderr pipe) Warm 95.58 (90.82–97.36) ms 53.20 (52.30–54.06) ms 1.80x (-42.38 ms)
timings.disk_scan (scan, printed 0.1s res) Warm 0.1 (0.1–0.1) s 0.0 (0.0–0.0) s -0.1 s
Process spawn -> HTTP /health ready Warm 14.71 (14.53–14.75) s 14.64 (14.29–15.10) s -0.06 s (within boot noise)

2. Component scan benchmarks & .input sort ablation

Interleaved mirrored rounds on plain local NVMe ext4 using an uncommitted flare-selene public-API harness (scan_bench.rs), reporting medians (p10–p90 in parentheses; 10 Cold rounds n=20/arm with drop_caches before every invocation, 20 Warm rounds n=40/arm after 1 warm-up pass per arm). .ckpt datasets hold 50% v3 ∥ 50% v4 10-step chains (1 rank, 4 KiB plane/row, TAIL_PAGES = 4, PAGE_TOKENS = 64); .input datasets hold 1,000 4,440-byte files.

Bare-metal aarch64 GB10 NVMe (record::scan, n=20 Cold ∥ n=40 Warm):

Workload Cache Control (be4092d7) Candidate (b7bd3fa9) Speedup
record::scan 500 .ckpt Cold 119.44 (103.62–153.22) ms 11.19 (10.08–11.97) ms 10.68x
record::scan 500 .ckpt Warm 3.31 (2.28–4.13) ms 1.70 (1.34–1.88) ms 1.94x
record::scan 2,000 .ckpt Cold 466.08 (422.01–636.24) ms 43.80 (41.94–45.61) ms 10.64x
record::scan 2,000 .ckpt Warm 15.53 (9.86–16.44) ms 4.81 (3.80–5.04) ms 3.23x
record::scan 10,000 .ckpt Cold 2,122.11 (2,083.26–3,033.40) ms 211.29 (199.84–267.23) ms 10.04x
record::scan 10,000 .ckpt Warm 61.43 (51.77–64.07) ms 16.54 (16.08–20.98) ms 3.71x

InputStore::start_bounded (1,000 .input files) sort and concurrency ablation:

Platform & Cache Control (be4092d7, unsorted seq) OsStr::cmp seq (no par_map) Path::cmp + par_map (ablation) Candidate (b7bd3fa9, OsStr::cmp + par_map) Candidate Speedup
aarch64 GB10 NVMe, Cold (n=20) 214.43 (209.18–304.87) ms 218.11 (209.74–323.54, 0.98x) ms 23.96 (22.10–27.13, 8.95x) ms 23.16 (21.25–24.32) ms 9.26x
aarch64 GB10 NVMe, Warm (n=40) 4.73 (3.24–5.24) ms 5.28 (3.32–5.51, 0.90x) ms 3.55 (2.57–3.68, 1.33x) ms 2.50 (1.94–2.62) ms 1.89x
x86_64 Linux NVMe, Warm (n=40, WSL2 ext4) 4.40 (4.29–4.66) ms 4.55 (4.38–6.74, 0.97x) ms 3.05 (2.78–3.34, 1.44x) ms 2.60 (2.28–2.86) ms 1.69x

Sorting .input paths by raw OsStr (sort_unstable_by(|a, b| a.as_os_str().cmp(b.as_os_str()))) avoids Path::cmp component parsing on 1,000 warm files (3.05 -> 2.60 ms on x86_64, raising warm speedup from 1.44x to 1.69x; 3.55 -> 2.50 ms on aarch64 GB10, raising warm speedup from 1.33x to 1.89x) while keeping recovery order deterministic.

Evidence & Limitations

Verified on clean git archive b7bd3fa9032f4ee306f0995495ed6dd463818ada atop NVIDIA/hyperflare-inference:main be4092d7e1f0efe8a16049568c12ec7b841a2e8e (git merge-tree --write-tree clean: bf2ee0ef12c283b709a409486d77751b92e6e66e):

  • Bare-metal aarch64 GB10 non-root NVMe --release tests (uid=1000, rustc 1.99.1, 1,945 passed, 0 failed, 8 ignored):
    • cargo test --locked --release --manifest-path selene/Cargo.toml --features test-support: 645 passed (644 lib + 1 integration), 0 failed, 0 ignored (Unix 0o000 unreadable-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, 0 failed, 0 ignored.
    • cargo test --locked --release --manifest-path selene-manager/Cargo.toml --lib: 205 passed, 0 failed, 1 ignored.
    • cargo test --locked --release --manifest-path flare/Cargo.toml --lib: 247 passed, 0 failed, 4 ignored.
    • cargo test --locked --release --manifest-path flare-cli/Cargo.toml --bins: 228 passed, 0 failed, 3 ignored.
  • x86_64 Linux non-root --release tests (uid=1000, rustc 1.100.0, 3,287 Rust + 4 Python passed, 0 failed, 86 ignored):
    • cargo test --locked --release --manifest-path selene/Cargo.toml --features test-support: 645 passed (644 lib + 1 integration), 0 failed, 0 ignored.
    • cargo test --locked --release --manifest-path selene/Cargo.toml --no-default-features --lib: 620 passed, 0 failed, 0 ignored.
    • FLARE_TEST_TEMPLATE_DIR=<dir> cargo test --locked --release --manifest-path helios/Cargo.toml --features runtime-core,server (11 templates prepared via tests/frontend/prepare_templates.py): 2,022 passed (1,960 lib + 62 integration), 0 failed, 86 ignored (49 lib + 37 integration).
    • pytest tests/preparation/test_core_boundary.py: 4 passed, 0 failed.
  • Unit test coverage: header_eq_implies_same_hash (isolating Header.packed independently of page_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 .ckpt siblings both before and after the 0o000 entry so pre-PR inline deletion fails on both ext4 and LIFO tmpfs), 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 removing entries.sort_unstable_by fails on FIFO, LIFO tmpfs, and hash-indexed ext4 filesystems), and parallel_scan_preserves_directory_and_budget_on_unreadable_entry (seeding 80 valid/over-budget .input, 16 corrupt .input, and 16 .input.pending files split before and after the 0o000 entry under tight DiskBudget).
Reproduction harness (`scan_bench.rs`) and `flare run` startup A/B commands
  1. Component & .input sort ablation harness (scan_bench.rs): Place the source below into selene/examples/scan_bench.rs inside clean git archive checkouts of be4092d7 and b7bd3fa9, build with cargo 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 (with sync && echo 3 > /proc/sys/vm/drop_caches before each cold run).
use std::fs::{self, File};
use std::io::Write;
use std::path::{Path, PathBuf};
use std::sync::Arc;
use std::time::{Duration, Instant};

use flare_selene::input::{DiskBudget, InputStore, PreparedInputRecord};
use flare_selene::record::{self, DirectoryLock, Header, RankSizes, file_name};
use flare_selene::shared::wire::{
    PackedOffer, PackedUnit,
    packed_unit::{Kind, Representation},
};
use flare_selene::PrefixKey;

const IDENTITY: [u8; 32] = [0x11; 32];
const FINGERPRINT: [u8; 16] = [0x22; 16];
const BUCKET: [u8; 16] = [0x33; 16];
const PAGE_TOKENS: u64 = 64;
const TAIL_PAGES: u32 = 4;

fn default_ranks() -> Vec<RankSizes> {
    vec![RankSizes {
        planes: vec![4096],
        row_bytes: 4096,
    }]
}

fn make_key(chain: u64, step: u64) -> PrefixKey {
    let consumed_tokens = (step + 1) * (TAIL_PAGES as u64) * PAGE_TOKENS;
    let mut digest = [0u8; 16];
    digest[..8].copy_from_slice(&chain.to_be_bytes());
    digest[8..16].copy_from_slice(&step.to_be_bytes());
    PrefixKey {
        consumed_tokens,
        digest,
    }
}

fn make_header(ranks: &[RankSizes], chain: u64, step: u64, packed: bool) -> Header {
    let key = make_key(chain, step);
    let parent = if step == 0 {
        None
    } else {
        Some(make_key(chain, step - 1))
    };
    let base = Header::from_sizes(
        PAGE_TOKENS,
        ranks.to_vec(),
        IDENTITY,
        FINGERPRINT,
        key,
        parent,
        BUCKET,
        TAIL_PAGES,
        1_700_000_000 + chain * 10 + step,
    )
    .expect("from_sizes");
    if !packed {
        return base;
    }
    let first_page = parent.map_or(0, |p| p.consumed_tokens / PAGE_TOKENS);
    let mut units = Vec::new();
    for offset in 0..u64::from(TAIL_PAGES) {
        for (rank_idx, rank_sizes) in ranks.iter().enumerate() {
            units.push(PackedUnit {
                kind: Kind::Page as i32,
                logical_index: first_page + offset,
                stored_rank: rank_idx as u32,
                representation: Representation::Packet as i32,
                profile: vec![0x42; 32],
                original_length: rank_sizes.page_record_bytes(),
                stored_length: 256,
                replicas: Vec::new(),
                stored_crc: 11,
                original_crc: 22,
                raw_xxh3: 0,
            });
        }
    }
    for (rank_idx, rank_sizes) in ranks.iter().enumerate() {
        units.push(PackedUnit {
            kind: Kind::Row as i32,
            logical_index: 0,
            stored_rank: rank_idx as u32,
            representation: Representation::Packet as i32,
            profile: vec![0x42; 32],
            original_length: rank_sizes.row_record_bytes(),
            stored_length: 256,
            replicas: Vec::new(),
            stored_crc: 33,
            original_crc: 44,
            raw_xxh3: 0,
        });
    }
    base.with_packed(PackedOffer { first_page, units })
        .expect("with_packed")
}

fn prep_ckpt(dir: &Path, count: usize) {
    assert_eq!(count % 10, 0, "count must be a multiple of 10");
    let _ = fs::remove_dir_all(dir);
    fs::create_dir_all(dir).expect("create_dir_all");
    let ranks = default_ranks();
    let chains = (count / 10) as u64;
    for chain in 0..chains {
        let is_v4 = chain % 2 == 1;
        for step in 0..10u64 {
            let h = make_header(&ranks, chain, step, is_v4);
            let path = dir.join(file_name(&h.key));
            let mut file = File::create(&path).expect("create ckpt");
            if is_v4 {
                file.write_all(&h.packed_metadata().expect("packed_metadata")).expect("write v4");
            } else {
                file.write_all(&h.encode().expect("encode v3")).expect("write v3");
            }
            file.set_len(h.length_with_row()).expect("set_len");
        }
    }
    let lock = DirectoryLock::acquire(dir).expect("lock");
    let scanned = record::scan(&lock, &IDENTITY, &FINGERPRINT, PAGE_TOKENS, &ranks).expect("scan");
    assert_eq!(scanned.len(), count);
}

fn scan_ckpt(dir: &Path, expected: usize) {
    let ranks = default_ranks();
    let lock = DirectoryLock::acquire(dir).expect("lock");
    let t0 = Instant::now();
    let scanned = record::scan(&lock, &IDENTITY, &FINGERPRINT, PAGE_TOKENS, &ranks).expect("scan");
    let elapsed_ms = t0.elapsed().as_secs_f64() * 1000.0;
    assert_eq!(scanned.len(), expected);
    println!("{elapsed_ms:.4}");
}

fn prep_input(dir: &Path, count: usize) {
    let _ = fs::remove_dir_all(dir);
    fs::create_dir_all(dir).expect("create_dir_all");
    let budget = DiskBudget::new(1 << 30, 0);
    let store = InputStore::start_bounded(0, Some(dir.to_path_buf()), budget, 64 << 20).expect("start");
    let sample = Arc::new(PreparedInputRecord {
        metadata: Arc::from(vec![0x5a_u8; 256]),
        payload: Some(Arc::new(vec![0xa5_u8; 4096])),
    });
    for i in 0..count {
        let mut key = [0u8; 32];
        key[..8].copy_from_slice(&(i as u64).to_be_bytes());
        store.insert(key, sample.clone());
        if (i + 1) % 4 == 0 || i + 1 == count {
            let target = (i + 1) as u64;
            let deadline = Instant::now() + Duration::from_secs(60);
            while store.stats().stored < target {
                assert!(Instant::now() < deadline);
                std::thread::sleep(Duration::from_millis(1));
            }
        }
    }
    assert_eq!(store.stats().disk_records, count);
}

fn scan_input(dir: &Path, expected: usize) {
    let budget = DiskBudget::new(1 << 30, 0);
    let t0 = Instant::now();
    let store = InputStore::start_bounded(0, Some(dir.to_path_buf()), budget, 64 << 20).expect("start");
    let elapsed_ms = t0.elapsed().as_secs_f64() * 1000.0;
    assert_eq!(store.stats().disk_records, expected);
    drop(store);
    println!("{elapsed_ms:.4}");
}

fn main() {
    let args: Vec<String> = std::env::args().collect();
    let dir = PathBuf::from(&args[2]);
    let count: usize = args[3].parse().expect("count");
    match args[1].as_str() {
        "prep-ckpt" => prep_ckpt(&dir, count),
        "scan-ckpt" => scan_ckpt(&dir, count),
        "prep-input" => prep_input(&dir, count),
        "scan-input" => scan_input(&dir, count),
        other => panic!("unknown subcommand: {other}"),
    }
}
  1. End-to-end flare run startup A/B: Build --release flare from clean git archive be4092d7 and git 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=30s and one 443-token chat request to drain a template .ckpt for the target core's namespace, then seed that namespace directory with 10,000 sparse .ckpt files (1,000 10-step chains, tail_pages = 1, file.set_len(h.length_with_row()): 5,000 v3 files of 69,779,456 bytes each and 5,000 v4 Representation::Literal files — 500 step-0 files of 69,775,483 bytes and 4,500 step 1–9 files of 69,775,487 bytes — totaling 697,774,713,000 logical bytes / 649.85 GiB) plus 1,000 .input files (256-byte metadata + 4,096-byte payload = 4,440 bytes each). Alternate boots (n=5 Cold with sync && echo 3 > /proc/sys/vm/drop_caches before every boot, then 1 warm-up per arm + n=5 Warm) with:
flare run <core>/model.safetensors \
  --host 127.0.0.1 --port 8096 --no-advertise --gpus 0 \
  --max-concurrency 8 --kv-cache-limit memory --memory-limit=-12G \
  --embedding-table-storage ram \
  --publisher-keys <keys>/development-publisher.json \
  --trust-store <keys>/trust.toml \
  --dangerously-approve-key <pub-key-sha256> \
  --dangerously-accept-publisher local-development \
  --core-cache <serve_cache> \
  --prefix-cache-disk <disk_cache> \
  --prefix-cache-disk-limit 2000G \
  --lossless-kv-compression cpu

Timestamp redirected stderr [ PENDING ] -> [ OK ] Prepare host prefix cache. on every boot, verify HTTP /health (200), scrape /metrics asserting flare_host_cache_disk_records == 10000 and flare_input_cache_disk_records == 1000, send SIGTERM, and verify all 10,000 .ckpt and 1,000 .input files remain on disk.

  • Limitations: Native Windows execution (including handle-close-before-unlink under concurrency) was audited statically and remains unexecuted on a Windows host. The flare run startup A/B exercised a single-GPU TP1 GB10 core (Qwen4-35B-A3B-NVFP4) with sparse seeded .ckpt payload bodies; multi-host TP startup scans and bare-metal x86_64 flare run startup timings were not run on this revision (warm .input isolation on x86_64 ran on local NVMe ext4 inside WSL2).

Discord: Dooner

@FujitsuPolycom FujitsuPolycom changed the title selene: parallelize startup disk scan and coalesce small header reads selene: parallelize startup disk scan Dec 5, 2026
@FujitsuPolycom
FujitsuPolycom force-pushed the perf/selene-parallel-startup-scan-r2 branch from 6962733 to 3314ce1 Compare December 5, 2026 00:07
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
FujitsuPolycom force-pushed the perf/selene-parallel-startup-scan-r2 branch from 3314ce1 to b7bd3fa Compare December 5, 2026 00:51
@FujitsuPolycom

Copy link
Copy Markdown
Owner Author

Published b7bd3fa to NVIDIA#734 in place.

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.

1 participant