You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Commit dad2fa5
Browse filesBrowse the repository at this point in the historyBrowse files
Reduce disk offload restore latency and integrated-memory intake overhead (#497)
Why
Disk-only prefix-cache offload (`--prefix-cache-memory 0` with
`--prefix-cache-disk`, default `--lossless-kv-compression off`) incurred five
host and coordination costs: (1) opening a raw v1-v3 record file
(`selene/src/disk.rs`) issued two sequential `O_DIRECT` reads (4 KiB header,
then page checksums); (2) `xxh3` page hashing ran serially on the single disk
thread across up to 64 pages (`268 MB` at `4.19 MB`/page); (3) `Staged::pump_all`
(`selene/src/disk_store.rs`) submitted unlinks/truncates and outbound writes
ahead of interactive restores; (4) while waiting on an inbound restore with an
idle GPU, Helios's worker (`helios/src/server/runtime.rs`) slept up to `2 ms`
and multi-host disk peers (`selene/src/shard.rs`) slept `1 ms` instead of waking
on socket readability; and (5) on integrated-memory GPUs
(`CU_DEVICE_ATTRIBUTE_INTEGRATED`), disk-only offload scaled registered host
intake with concurrency (`2 * max_active * row_slots + 128`, up to `8.2 GiB`
needed on `Qwen3.8-27B-NVFP4` at `--max-concurrency 16`), carving GPU KV cache
out of shared RAM even though paged disk streaming stages at most two windows
(`2 * (64 + row_slots)` slots).
What
- Single-read raw open (`selene/src/disk.rs`): preserve `#504`'s v4 packed
`Header::read_metadata` open branch, and on raw v1-v3 `O_DIRECT` opens read
the 4 KiB header and expected checksum segment in one transfer when
`expected.tail_pages <= MAX_TAIL_PAGES` (`CHECKSUM_SCRATCH_BYTES = 1 MiB`),
falling back to a 4 KiB header-only read on failure while preserving retry
I/O errors, truncated-file checks, and shared scratch span helpers.
- Scoped parallel page hashing (`selene/src/disk.rs`): cache `parallel_cpus`
once at `Worker::new` and hash raw batches of >= `HASH_PARALLEL_MIN_PAGES`
(`4`) pages across `parallel_cpus.min(MAX_HASH_THREADS).min(buffers.len())`
`std::thread::scope` threads (`MAX_HASH_THREADS = 4`) when `parallel_cpus >=
HASH_PARALLEL_MIN_CPUS` (`4`), with `0` idle helper threads, Linux
`SCHED_BATCH` inheritance via `clone`, inline recomputation on helper spawn
or unwind failure, and fault hooks folded into `Faults` under
`cfg(any(test, feature = "test-support"))` (zero test-only parameters on
shipped signatures).
- Bounded restore-first submission and wakeup (`disk_store.rs`,
`helios/src/server/runtime.rs`, `shard.rs`): order `Staged::pump_all` as
inbound restores, then outbound writes, then maintenance while submitting one
reserved maintenance job ahead of inbound and outbound after
`MAINTENANCE_DEFER_LIMIT` (`8`) consecutive passes where queued maintenance
lost free disk-queue space; poll `Worker::idle_wait` at `50 us` during
active/waiting inbound restores; and wake Unix disk peers via `libc::poll`
(`POLLIN`).
- Bounded integrated disk-only intake & `#589` unified-memory budget integration
(`selene/src/offload.rs`, `helios/src/offload/mod.rs`,
`helios/src/runtime_core/{memory,model}.rs`, `docs/prefix-cache-offload.md`):
pass explicit `PrepareInputs` (`max_active`, `input_staging`, `shard`,
`integrated`) into `headroom_with_inputs`, `headroom_with_inputs_for_budget`,
`prepare_with_inputs`, and `prepare_with_inputs_budget` (deleting unused
`prepare` and dead `core: &Path`), unify `disk_enabled()`, `headroom_inner`,
private `target_intake_slots`, and parameterless `Prepared::intake_warning()`
(`required_intake` + `sized_concurrency`), preserve `options.pool_only()` so a
degraded disk directory under `--prefix-cache-pool --prefix-cache-memory 0`
remains restore-only against `#589`'s `planned_offload_host`, and target
`intake_slots(layout, 1)` (`2 * (64 + row_slots)`) on integrated disk-only
hosts without shrink warnings across `#589`'s small-SoC headroom scaling,
explicit `--memory-limit` budgets, pre-planned post-KV `planned_offload_host`,
and `HOST_NUMA` split-mapping fallback while preserving `#504` lossless KV
compression. No core re-export or record-format change is required.
Result
Live `flare run` A/B on NVIDIA GB10 (SM121) measured `#497` standalone
(`cd5a366b`) against pre-`#504` `main` (`c0c4f798`) with `--prefix-cache-memory
0 --prefix-cache-disk /tmp/selene-disk` and default `--lossless-kv-compression
off` (the raw v3 `.ckpt` path, whose default GB10 disk-only execution is
unchanged by rebasing onto `ba3afb13` / `#589` because GB10 128 GiB exceeds the
16 GiB small-SoC threshold and disk-only intake targets the same two-window
floor; ingress-to-first-token TTFT; bandwidth is rank-0
`flare_host_cache_inbound_bytes_per_second`):
- `Qwen3.8-27B-NVFP4` (TP1, `--max-concurrency 16 --prefix-cache-disk-limit
40G`, 3 interleaved repeats): intake drops `7.3 GiB` (`1,877` slots, shrink
warning) -> `1.0 GiB` (`252` slots, `0` warnings), raising GPU KV cache `64.4
-> 71.6 GiB` (`+7.2 GiB` / `+235.5K` tokens); median single-restore bandwidth
and TTFT improve `7.05 -> 8.02 GB/s` (`348.0 -> 301.7 ms`, `-13.3%`; wall
`353.5 -> 306.5 ms`) at `30.0K` and `6.28 -> 8.68 GB/s` (`+38.2%`, `551.8 ->
447.6 ms`, `-18.9%`; wall `561.7 -> 455.4 ms`) at `61.1K`; `#497` standalone
8-way `61.1K` cold-restart burst mean median TTFT drops `8,156.1 -> 6,963.4
ms` (`-14.6%`, 2 interleaved repeats; combining this change with concurrent
ancestor-restore read coalescing in companion PR `#496` is unmeasured).
- Isolated `std::thread::scope` `xxh3` (`cd5a366b` with `MAX_HASH_THREADS = 1`
at `selene/src/disk.rs:157` and no other change vs unmodified `cd5a366b` with
`MAX_HASH_THREADS = 4`, 3 interleaved repeats on `Qwen3.8-27B-NVFP4`):
parallel hashing alone improves median TTFT `486.8 -> 447.6 ms` (`-8.1%`,
`7.73 -> 8.68 GB/s`, `+12.3%`, faster on all 3 repeats: `[447.6, 432.7,
451.2]` vs `[479.9, 557.5, 486.8] ms`) at `61.1K` and `322.4 -> 301.7 ms`
(`7.55 -> 8.02 GB/s`) at `30.0K`. `HASH_PARALLEL_MIN_PAGES = 4` and
`HASH_PARALLEL_MIN_CPUS = 4` assign at least one page per thread at the
4-thread cap and leave cores for serving threads on narrow hosts (not swept
separately).
- `Qwen3.8-Flash-Next` (TP1, `--max-concurrency 8 --prefix-cache-disk-limit
24G`, `cd5a366b` vs `c0c4f798`): intake drops `1.9 -> 0.3 GiB` (`2,288 -> 398`
slots), raising GPU KV cache `23.28 -> 24.98 GiB` (`+1.70 GiB` / `+127.0K`
tokens); bandwidth improves `5.67 -> 7.05 GB/s` (`372.1 -> 355.6 ms`) at
`30.0K` and `6.65 -> 8.35 GB/s` (`+25.6%`, `458.0 -> 413.8 ms`, `-9.7%`) at
`61.0K`; `#497` standalone 8-way burst median TTFT drops `3,327.5 -> 3,078.5
ms` (`-7.5%`).
- Expected interaction with `#589` (`ba3afb13`): on unified-memory GPUs with an
explicit `--memory-limit`, disk-only intake remains bounded at
`intake_slots(layout, 1)` so unlocked unified RAM expands GPU KV cache rather
than concurrency-scaled staging, while warm+disk (`--prefix-cache-memory > 0`)
and pool-only capture retain `#589`'s pre-planned host budget and small-SoC
scaling.
What it costs: up to three short-lived scoped `xxh3` helpers during >=4-page
raw batches (`0` idle helpers), `50 us` `Worker::idle_wait` polling during
active/waiting inbound restores (`969.9 -> 1,069.2 ms/s` `/proc/<pid>/stat`
server CPU across 8-way `Qwen3.8-27B-NVFP4` bursts: `+99.3 ms/s` / ~`0.10` of
20 Grace cores combined; the `50 us` poll's CPU share and latency contribution
are unisolated from scoped `xxh3` helpers), two-window serialization for
concurrent unique-prefix restores and outbound stores on integrated disk-only
hosts, and up to `8` passes of maintenance deferral.
Companion PR (#496, concurrent ancestor-restore open and window coalescing):
merge `#497` first, then rebase `#496` onto `main` so `Staged::pump_all` retains
`MAINTENANCE_DEFER_LIMIT = 8` (submitting one reserved maintenance job first
after `8` deferred passes) and runs `#496`'s private `host_inbound` and shared
`pump_device_inbound` queues ahead of `outbound` and `maintenance`.
Evidence
- Rebased crate and Python checks over `origin/main` (`ba3afb13`, `#589`) on
x86_64 Linux (`O_DIRECT` + `io_uring`): `selene --features test-support`
(`514` lib + `1` `mixed_codec_root` integration passed, `0` warnings; also
`cargo check --release` without `test-support`, `0` warnings), `selene-manager
--features test-support --test client --test offload` (`85 + 2` passed, `0`
warnings), `helios --features runtime-core,server --lib -- offload::
runtime_core::memory::tests runtime_core::model::tests
server::runtime::phase_tests` (`144` passed, `14` GPU-only ignored, `0`
warnings in touched files, covering `#497` + `#589` small-SoC,
`--memory-limit`, and degraded-disk restore-only pool coexistence), and
`pytest tests/preparation/test_core_boundary.py
tests/test_design_review_hook.py` (`22` passed).
- Prior SM121 GPU unit and live checks (at `cd5a366b`, `--lossless-kv-compression
off`): `helios` `offload::` (`FLARE_RUN_CUDA_TESTS=1 --include-ignored`, `21`
single-GPU SM121 tests passed; `split_pools` requires 2 local GPUs);
corrupting a multi-page `.ckpt` payload on `Qwen3.8-27B-NVFP4` incremented
`fetch_failed_total` (`1`), launched `0` `restore` graphs, and recomputed
identical `top-5 logprobs` and tokens; under `--prefix-cache-disk-limit 6G`
(`4` concurrent restores + `3` fresh `30K` stores), disk bytes peaked at
`6.38 GB` (`<= 6 GiB`) and settled at `6.37 GB` with `0` `retry_abandoned`
and `0` `io_error` drops (`2` normal `end_of_chain` evictions); four
concurrent decode streams spilling checkpoints over 30 s on
`Qwen3.8-Flash-Next` had `0` errors (`100.0 -> 95.9 tok/s`).
- Not covered: live `--lossless-kv-compression` (`cpu`/`gpu`) serving,
post-rebase SM121 `flare run` re-measurement, live Jetson Orin GA10B /
`--memory-limit` GPU serving, isolated `50 us` `Worker::idle_wait` A/B,
`#496 + #497` combined serving, multi-host RoCE serving, 2-GPU `split_pools`,
discrete PCIe GPUs, Windows serving, and live warm-plus-disk
(`--prefix-cache-memory > 0`) or `PooledStore` HTTP serving (`CompositeStore`
+ `DiskStore` CUDA transfers were covered at `cd5a366b` in `helios`
`offload::`).
Discord: Dooner
Design-Signed-Off-By: Antigravity (Gemini 4); design-review=c3a9
Signed-off-by: FujitsuPolycom <87842395+FujitsuPolycom@users.noreply.github.com>
0 commit comments