Skip to content

fix(flare-cli,helios): release page cache with O_DIRECT peer serving, inherit orbit memory reserve, and log integrated MemInfo - #713

Open
jcartu wants to merge 1 commit into
NVIDIA:mainfrom
jcartu:fix/integrated-page-cache-and-orbit-reserve
Open

jcartu wants to merge 1 commit into
NVIDIA:mainfrom
jcartu:fix/integrated-page-cache-and-orbit-reserve

Conversation

@jcartu

@jcartu jcartu commented Dec 3, 2026

Copy link
Copy Markdown
Contributor

Refs #630

Summary

Release page cache on peer-serving and buffered I/O paths, and serve peers with O_DIRECT; live GB10 impact remains unmeasured. In addition, propagate [memory] reserve into flare orbit run (without clobbering saved persistent-group overrides) and surface Linux /proc/meminfo diagnostics on integrated-GPU cache planning and CUDA context-creation OOM failures.

Changes

  1. O_DIRECT peer serving and four missed release_page_cache sites

    • Re-exported flare_eos direct-I/O helpers (FileReadAt, allocate_aligned, direct_reopen, free_aligned) from helios/src/lib.rs.
    • Updated flare-cli/src/distribution.rs::serve_source to reopen files with direct_reopen on Unix and stream aligned 4 MiB chunks via a zero-initialized AlignedBuffer, matching cache::RangeReader byte-for-byte across unaligned offsets, multi-range requests, and unaligned EOF. After copy_ranges_direct (including on error), every served range is released with release_page_cache_range to evict any pre-existing page-cache pages or Linux >= 6.6 tmpfs pages. Falls back cleanly to buffered RangeReader + release_page_cache_range when O_DIRECT is unsupported or returns EINVAL (including mid-stream).
    • Added release_page_cache / release_page_cache_range at four missed buffered I/O call sites:
      • flare-cli/src/orbit/controller.rs (controller upload put loop)
      • flare-cli/src/core_cache.rs (AlreadyExists cached blob digest re-verification)
      • flare-cli/src/orbit/agent.rs (get, matching fetch)
      • helios/src/core/cache.rs (write_stream after sync_all, verify_file, hash_file, and non-Windows copy_file for both synced destination and source)
  2. [memory] reserve propagation in flare orbit run

    • Updated flare-cli/src/config.rs so Command::Orbit(OrbitCommand::Run) inherits self.memory.reserve as MemoryLimit::Reserve when --memory-limit is unset, matching Command::Run.
    • Tracked config-inherited --memory-limit in flare-cli/src/main.rs and merged options via merge_serving_options in flare-cli/src/orbit/controller.rs so restarting a --persistent group preserves its saved --memory-limit while explicit CLI --memory-limit still overrides it.
  3. Linux integrated-GPU /proc/meminfo diagnostics and cuCtxCreate OOM enrichment

    • Added CUDA_ERROR_OUT_OF_MEMORY (2) in helios/src/runtime_core/driver.rs and LinuxMemInfo { free, available, cached } parsing in helios/src/runtime_core/memory.rs.
    • On Linux integrated GPUs (rank.integrated), appended MemFree / MemAvailable / Cached to the Plan cache summary and emitted a stderr warning when KV sizing is limited by memory and MemAvailable - MemFree > 10 GiB.
    • On cuDevicePrimaryCtxRetain and cuCtxCreate_v2 CUDA_ERROR_OUT_OF_MEMORY failures on Linux integrated GPUs (helios/src/runtime_core/mod.rs), attached MemFree / MemAvailable / Cached to CudaError.description (plus a drop_caches hint when MemAvailable - MemFree > 4 GiB) while preserving the structured ExecutionError::Driver(CudaError { code: 2, .. }) error.

Verification

  • Release (--locked --release, Linux x86_64):
    • cargo test --locked --release --manifest-path flare-cli/Cargo.toml: 251 passed (225 bin + 9 cache_commands + 6 cli + 4 inspect + 7 unverified_payload), 0 failed, 3 ignored.
    • cargo test --locked --release --manifest-path helios/Cargo.toml --features runtime-core,server: 1948 passed (1886 lib + 62 integration), 0 failed, 86 ignored.
    • cargo test --locked --release --manifest-path flare/Cargo.toml: 255 passed (247 lib + 7 packed_canonical_download + 1 reference_workflows), 0 failed, 4 ignored.
  • Clippy & Formatting:
    • cargo clippy --locked --manifest-path flare-cli/Cargo.toml --all-targets: 0 errors/warnings on touched lines.
    • cargo clippy --locked --manifest-path helios/Cargo.toml --features runtime-core,server --all-targets: 0 errors/warnings on touched lines.
    • rustfmt --edition 2024 --check: clean on all touched lines across all 11 files.
    • .githooks/commit-msg: passed (design-review=2e5b).

Disclosures / Limitations

  • All verification in this PR is CPU-only on Linux x86_64; no live GB10 run has been performed yet, so live GB10 impact remains unmeasured.
  • O_DIRECT peer serving drops kernel readahead in exchange for avoiding page-cache accumulation, and trailing release_page_cache_range calls evict any pre-existing cached pages (or tmpfs pages on Linux >= 6.6).
  • GB10 runtime behavior for CU_DEVICE_ATTRIBUTE_INTEGRATED and CUDA_ERROR_OUT_OF_MEMORY during context creation is unconfirmed on target hardware in this environment.

Discord: jcartu

… inherit orbit memory reserve, and log integrated MemInfo

Why

- On Linux unified-memory GPUs (such as GB10), CUDA allocations and context
  creation can respond to Linux `MemFree` rather than `MemAvailable` when
  tens of gigabytes of clean page cache accumulate from core distribution
  and buffered cache I/O (NVIDIA#630).
- `flare-cli`'s peer-serving path (`distribution::serve_source`) streamed
  core shards via buffered `RangeReader` before dropping page cache,
  leaving multi-GiB bursts in the page cache during transfer, and four
  buffered I/O sites across `flare-cli` and `helios` omitted
  `release_page_cache`.
- `flare orbit run` did not inherit `[memory] reserve` from host
  configuration (`config.rs`), unlike `flare run`, while persistent
  groups still needed their stored `--memory-limit` preserved unless
  overridden on the command line.
- When integrated-GPU cache planning was memory-limited or
  `cuDevicePrimaryCtxRetain` / `cuCtxCreate_v2` returned
  `CUDA_ERROR_OUT_OF_MEMORY`, diagnostics did not surface Linux
  `MemFree / MemAvailable / Cached` or hint when reclaimable page cache
  was likely blocking allocation.

What changed

- Direct peer serving and missed `release_page_cache` sites:
  - Re-exported `eos` direct-I/O helpers (`FileReadAt`, `allocate_aligned`,
    `direct_reopen`, `free_aligned`) from `helios/src/lib.rs`.
  - Updated `flare-cli/src/distribution.rs::serve_source` to reopen files
    with `direct_reopen` on Unix and stream 4 MiB aligned chunks from a
    zero-initialized `AlignedBuffer` (handling arbitrary unaligned offsets,
    multi-range requests, and unaligned EOF byte-for-byte identically to
    `cache::RangeReader`), always calling `release_page_cache_range` for
    every served range afterward (including on error) to evict any
    pre-existing or tmpfs cached pages, and falling back cleanly to
    buffered `RangeReader` + `release_page_cache_range` when `O_DIRECT` is
    unsupported or returns `EINVAL`.
  - Added `release_page_cache` / `release_page_cache_range` at the four
    missed buffered I/O sites: `flare-cli/src/orbit/controller.rs`,
    `flare-cli/src/core_cache.rs`, `flare-cli/src/orbit/agent.rs::get`,
    and `helios/src/core/cache.rs` (`write_stream`, `verify_file`,
    `hash_file`, and non-Windows `copy_file`).
- Orbit `[memory] reserve` propagation:
  - Inherited `self.memory.reserve` into `OrbitCommand::Run` in
    `flare-cli/src/config.rs` only when `--memory-limit` is unset.
  - Tracked config-inherited `--memory-limit` in `flare-cli/src/main.rs`
    and `flare-cli/src/orbit/controller.rs::merge_serving_options` so
    restarting a persistent group preserves its saved `--memory-limit`
    while explicit CLI `--memory-limit` still overrides it.
- Linux integrated-GPU `/proc/meminfo` diagnostics:
  - Added `LinuxMemInfo { free, available, cached }` parser and
    `CUDA_ERROR_OUT_OF_MEMORY` constant in `helios/src/runtime_core/`.
  - Appended `MemFree / MemAvailable / Cached` to the `Plan cache`
    summary on Linux integrated GPUs and emitted a warning when
    `MemAvailable - MemFree > 10 GiB` and KV sizing is limited by memory.
  - Enriched `cuDevicePrimaryCtxRetain` and `cuCtxCreate_v2`
    `CUDA_ERROR_OUT_OF_MEMORY` failures on Linux integrated GPUs with
    `MemFree / MemAvailable / Cached` (and a `drop_caches` hint when
    `MemAvailable - MemFree > 4 GiB`) while preserving the structured
    `ExecutionError::Driver(CudaError { code: 2, .. })` error.

Verification

- CPU-only verification on Linux x86_64 (no live GB10 run yet):
  - Verified `.githooks/commit-msg` passes on the staged diff and message.
  - `cargo test --locked --release --manifest-path flare-cli/Cargo.toml`:
    251 passed (225 bin + 9 cache_commands + 6 cli + 4 inspect + 7 unverified_payload), 0 failed, 3 ignored.
  - `cargo test --locked --release --manifest-path helios/Cargo.toml --features runtime-core,server`:
    1948 passed (1886 lib + 62 integration), 0 failed, 86 ignored.
  - `cargo test --locked --release --manifest-path flare/Cargo.toml`:
    255 passed (247 lib + 7 packed_canonical_download + 1 reference_workflows), 0 failed, 4 ignored.
  - `cargo clippy --locked` on `flare-cli --all-targets` and `helios --features runtime-core,server --all-targets`: 0 errors/warnings on touched lines.
  - `rustfmt --edition 2024 --check`: clean on all touched lines across all 11 files.

Design-Signed-Off-By: Antigravity (Gemini 3.1 Pro); design-review=2e5b
Signed-off-by: Joshua Cartu <jcartu@users.noreply.github.com>
@flare-autobot

Copy link
Copy Markdown
Collaborator

A case file has been opened for 713.
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:memory Memory budgets, allocation lifetimes, scratch sharing, and capacity. area:orbit Orbit host agents, orchestration, and package-cache management. enhancement New feature or request 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 3, 2026
@flare-autobot

Copy link
Copy Markdown
Collaborator

Autobot Review

Full Review · Value Proposition · Case File

Recommendation: Changes Requested

The O_DIRECT peer-serving rewrite, the four new page-cache release sites, the /proc/meminfo parser/enrichment, and the [memory] reserve inheritance are all correct on the read/write paths traced at 4efd9fd — the aligned-chunk arithmetic cannot overrun its buffer, the mid-stream EINVAL fallback is byte-exact, the release calls are unconditional, and the Windows/macOS cfg gating is complete. Two verified, non-hardware defects remain: the config-derived --memory-limit is written into the persisted --persistent group and then locked in by the very rule meant to protect saved values, and hash_file now evicts the page cache of a file the same import path immediately re-reads in full.

  • Blockers: 0 · Should fix: 2 · Subtract/Simplify: 5 · Nits: 5
Walkthrough
  • flare-cli/src/distribution.rs:1319-1336 replaces io::copy(RangeReader) in serve_source with copy_source_ranges: direct_reopen (:1328) → copy_ranges_direct (:1268-1317, 4 MiB AlignedBuffer, 4096 block, unaligned head/tail, EINTR retry, EINVAL → copy_ranges_buffered on the remainder at :1305-1311), then an unconditional per-range release_page_cache_range loop that runs even when the direct copy errored (:1330-1333).
  • New buffered-path releases: flare-cli/src/orbit/controller.rs:1464-1466 (controller upload put, release before result?), helios/src/core/cache.rs:4398 (write_stream post-sync_all), :4441/:4511 (verify_file/hash_file via let read = loop {..}; release; read?), :4772/:4774 (copy_file destination and source), flare-cli/src/core_cache.rs:450/455/505/562, flare-cli/src/orbit/agent.rs:2068.
  • flare-cli/src/config.rs:152-158 gives OrbitCommand::Run the same [memory] reserve → MemoryLimit::Reserve inheritance as Command::Run (:76-80); flare-cli/src/main.rs:537-540 records memory_limit_from_config from value_source != CommandLine; flare-cli/src/orbit/controller.rs:1967-1997 skips the config-inherited --memory-limit when the saved group already has one.
  • helios/src/runtime_core/memory.rs:35-140 adds LinuxMemInfo (strict MemFree:/MemAvailable:/Cached: kB parse with checked_mul), append_integrated_meminfo (appends the triple to Plan cache, returns a warning above a 10 GiB reclaimable gap) wired at :1256-1268 for any integrated rank, and enrich_integrated_ctx_oom (4 GiB drop_caches hint) wired at helios/src/runtime_core/mod.rs:375-388 around both cuDevicePrimaryCtxRetain and cuCtxCreate_v2.
Merge Risk: Medium · up to 4efd9fd
Pre-merge checks: ✅ 2 passed · ⚠️ 2 warnings

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

Want a frontier second opinion? If these findings look noisy, request a one-time SuperAgent Review on 4efd9fd (~3–4 min; re-adjudicates existing findings without re-running discovery).

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:memory Memory budgets, allocation lifetimes, scratch sharing, and capacity. area:orbit Orbit host agents, orchestration, and package-cache management. enhancement New feature or request 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