Skip to content

helios: parallelize engram loading and report startup progress - #696

Open
malventano wants to merge 1 commit into
NVIDIA:mainfrom
malventano:perf/helios-engram-load
Open

malventano wants to merge 1 commit into
NVIDIA:mainfrom
malventano:perf/helios-engram-load

Conversation

@malventano

Copy link
Copy Markdown
Contributor

Scope: RAM Engram startup loading and startup logging.

Why

Achieve SSD bandwidth parity between engram loads and the already fast weight loading. The weight path loads 293.9 GiB in 15.3s; Engram loads 188.8 GiB serially in 37.7s.

What

  • Parallel rank loads: prepare the four engram rank shards concurrently, then join in the original order. The final table layout and binding order are unchanged.
  • Retained read-only mapping: keep the populated memfd mapping, apply mprotect(PROT_READ), and seal it with F_SEAL_FUTURE_WRITE. This avoids the remap and second page-table population pass.
  • Optional transparent hugepages: request MADV_HUGEPAGE before filling. This reduces page-table and allocation work when shmem THP is available. With shmem_enabled=never it is a no-op and the tables remain 4 KiB-backed.
  • Engram progress logging: mirror the weights phase. Every 10s progress tick reports completed bytes out of the 188.8 GiB resident total, and the final line reports the resident size.
  • Startup total: print one final Startup complete. 38.4s line after the server is ready.

Results

Measured on a system with four SM120 GPUs and a three-drive Gen4 NVMe RAID0 XFS volume.

Change Engram time Gain
Baseline 37.7s
Parallel rank loads 19.2s -18.5s, 1.96x
Retained read-only mapping 15.1s -4.1s, 1.27x
THP first boot, fragmented memory 13.7s -1.4s from mapping-only
THP clean/defragmented memory 9.6s -28.1s total, 3.9x, -74.5%

Total startup:

  • Baseline phase time: 66.7s, about 67s wall
  • Final measured total: 38.4s
  • Gain: -28.3s absolute, 1.74x, -42.4%

The 9.6s result is the clean/defragmented state. A clean boot or freshly defragmented system should see 9.6s on its first THP load. A fragmented system may first land at 13.7s while the kernel compacts, then reach 9.6s on the next start.

Both phases report size on each 10s progress tick:

[ PENDING ] Load weights.  194.0 / 293.9 GiB  10.0s
[ PENDING ] Prepare embedding tables.  120.7 / 188.8 GiB  10.0s

A load shorter than 10s has no intermediate tick and reports only its final line.

Logging

These are small quality-of-life changes:

  • Engram progress matches weights with x / y GiB on each 10s tick.
  • The final engram line includes resident size.
  • Startup ends with one total elapsed line.
[    OK    ] Prepare embedding tables.  188.8 GiB · RAM  9.6s
[    OK    ] Start server.  http://0.0.0.0:8000  0.5s
[    OK    ] Startup complete.  38.4s

Evidence

Code paths:

  • helios/src/runtime_core/model.rs
  • helios/src/engram.rs
  • helios/src/engram/reader.rs
  • helios/src/startup.rs
  • flare-cli/src/main.rs
  • flare/src/controller.rs

Documentation:

  • docs/FLARE_START.md
  • docs/FLARE_PATCH_SERIES.md

Tests:

  • 18 engram reader tests passed.
  • 3 startup observation tests passed.
  • cargo check passed.
  • Full test suite was not run.

Future work

The resident reader uses synchronous 4 MiB pread calls. io_uring could reduce host submission overhead further, but this path is large sequential reads with low SSD IOPS, so this PR keeps the minimal change.

Limits

  • The results are sequential build measurements, not an isolated A/B for every stage.
  • THP depends on system shmem THP policy. advise is required for the hint to take effect.
  • The first THP boot on fragmented memory triggers one-time compaction.
  • F_SEAL_FUTURE_WRITE requires Linux 5.1+. The resident shared-mapping path already uses MADV_POPULATE_READ on Linux 5.14, so this does not raise the existing minimum.
  • No DiskReader, io_uring, row-cache, or NVMe read-path changes.

Preflight

  • Rebased onto main at cc0a49d2.
  • Mergebox rulesets require DCO and design sign-off; the commit carries both.
  • Kept the PR to the functional hunks only.
  • No unrelated formatting churn, test/non-Linux cleanup, system settings, or deployment files.

Discord: malventano

Why:
Engram preparation on the four-rank test system took 37.7s, including serial
rank loading and a second page-table population pass after remapping the sealed
memfd. This change brings the engram path closer to the existing weight-loading
throughput.

What:
- Load the independent engram rank shards concurrently and join them in group
  order so the resulting bindings are deterministic.
- Keep the populated read-only memfd mapping, seal it with
  F_SEAL_FUTURE_WRITE, and avoid the remap and MADV_POPULATE_READ pass.
- Request MADV_HUGEPAGE on the writable shmem mapping. The hint is optional and
  hosts with shmem THP disabled retain 4 KiB backing.
- Report resident bytes and x / y GiB on each 10s engram progress tick, then
  report the resident size on completion.
- Print a final wall-clock Startup complete line after the server is ready.

Result:
On the test system, engram preparation fell from 37.7s to 9.6s in the clean
state, a 28.1s and 3.9x improvement. Total startup fell from 66.7s to 38.4s, a
28.3s and 1.74x improvement. A fragmented first THP boot measured 13.7s while
the kernel compacted; subsequent clean starts reached 9.6s.

Evidence:
- 18 engram reader tests passed.
- 3 startup observation tests passed.
- cargo check passed for helios, flare, and flare-cli.
- The full test suite was not run.
- Performance was measured on a four-SM120 system with a three-drive Gen4 NVMe
  RAID0 XFS volume. The results are sequential build measurements, not an
  isolated A/B for every stage.

Limits:
- THP depends on system shmem THP policy; advise is required for the hint to
  take effect.
- F_SEAL_FUTURE_WRITE requires Linux 5.1+. The resident shared-mapping path
  already uses MADV_POPULATE_READ on Linux 5.14, so this does not raise the
  existing minimum.
- No DiskReader, io_uring, row-cache, or NVMe read-path changes.

Design-Signed-Off-By: DSV4.1-Flash-1017; design-review=2e5b
Signed-off-by: malventano <malventano@users.noreply.github.com>
@flare-autobot

Copy link
Copy Markdown
Collaborator

A case file has been opened for 696.
Case File Intake Report

Future reviews will auto-run 90 minutes after code updates are pushed.

  • Re-review sooner: Call @flare-autobot after push.
  • Opt-out: Include #autobot:ignore in the PR or any comment.

@flare-autobot flare-autobot added area:engram Engram row gathering, disk I/O, and embedding-row caching. performance Performance, latency, throughput, or memory-efficiency investigation or improvement. triage:review Proposed change needs code review; this does not imply merge readiness. labels Dec 2, 2026
@flare-autobot

Copy link
Copy Markdown
Collaborator

Autobot Review

Full Review · Value Proposition · Case File

Recommendation: Changes Requested

The core optimizations—loading independent Engram shard groups concurrently and retaining the populated Linux memfd via mprotect(PROT_READ) + F_SEAL_FUTURE_WRITE—are technically sound and preserve deterministic table layout, binding order, CUDA context isolation, and cross-platform parity. However, the PR re-introduces an unconditional whole-mapping madvise(MADV_HUGEPAGE) that mirrors the exact THP compaction-stall hazard just retired by #625, and also has four concrete gaps to resolve: spurious 0.0 GiB progress on disk-only tables, an unimplemented claimed finish-line resident size, a spurious desktop WinUI stage emission in flare/src/controller.rs, and missing test/evidence/description hygiene.

  • Blockers: 1 · Should fix: 4 · Subtract/Simplify: 3 · Nits: 2
Walkthrough
  • helios/src/runtime_core/model.rs (+49/−19): Passes resident_bytes as the byte progress total for Prepare embedding tables (:840-842) and replaces the serial shard-group loop with thread::scope spawning one flare-engram-rank-{group} thread per deduplicated local rank group, joining handles in group order before the existing bindings.sort_by_key (:870-918).
  • helios/src/engram.rs (+4/−1) & helios/src/runtime_core/event_tests.rs (+1): Plumbs progress: Option<&Phase> through Shared::new to Reader::from_files_with_progress.
  • helios/src/engram/reader.rs (+114/−10): Adds unconditional madvise(MADV_HUGEPAGE) on writable Linux resident mappings (:184-192); splits sealing to add RESIDENT_FUTURE_SEALS (F_SEAL_FUTURE_WRITE) and lets has_resident_seals accept either seal set (:222-269, 444); retains the populated Linux mapping in Resident::initialize via mprotect(PROT_READ) + seal_resident_future instead of dropping and remapping (:404-424); adds Resident::load_with_progress and Reader::from_files_with_progress calling phase.advance_bytes per 4 MiB chunk (:272-320, 1352-1415).
  • helios/src/startup.rs (+38): Records StartupProgress.started at construction (:24, 163, 173), adds StartupProgress::complete() emitting [ OK ] Startup complete. X.Xs and publishing StartupStatus::Complete with StartupStage::Other (:215-236), and adds unit test complete_publishes_the_final_startup_total (:566-576).
  • flare-cli/src/main.rs (+2) & flare/src/controller.rs (+1): Calls progress.complete() after Start server finishes in serve (main.rs:668), serve_local (main.rs:737), and desktop Worker (controller.rs:2914).
Merge Risk: Medium · up to 24ff7e1
  • Shared Linux resident-table path (helios/src/engram/reader.rs): Every RAM-Engram (--embedding-table-storage ram), resident-scales (--embedding-table-resident-scales), and PreparedTables::load startup on Linux runs the new MADV_HUGEPAGE + mprotect(PROT_READ) + F_SEAL_FUTURE_WRITE path. Unconditional MADV_HUGEPAGE risks unbounded synchronous kernel compaction stalls on fragmented hosts under shmem_enabled=advise and defrag=madvise|defer+madvise|always.
  • Startup observability & desktop UI (helios/src/startup.rs, flare/src/controller.rs, helios/src/runtime_core/model.rs): Disk-only startups (the default storage mode) now render 0.0 GiB during Prepare embedding tables, and the desktop worker publishes StartupStage::Other right before mDNS advertisement while still in SessionState::Loading.
  • Unverified build/test status: No CI checks are attached to head 24ff7e1, and the author ran only 18 reader tests, 3 startup tests, and cargo check rather than the --release test suites across the modified crates (helios, flare, flare-cli).
Pre-merge checks: ✅ 1 passed · ⚠️ 3 warnings

Have your agent review the Full Review for complete verified findings, file:line citations, and suggested changes.

To opt out, include #autobot:ignore in your post or comment.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area:engram Engram row gathering, disk I/O, and embedding-row caching. performance Performance, latency, throughput, or memory-efficiency investigation or improvement. triage:review Proposed change needs code review; this does not imply merge readiness.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants