Final review report · NVIDIA/hyperflare-inference #699

Raw Markdown for agents: https://autobot.eidonix.com/p/67e35d49-f3f2-4254-9ca2-4cd2039bc697.md

Recommendation: Changes Requested

The core diagnosis and architectural placement are sound: on Linux, selene-manager preallocates /dev/shm/selene/<name>-<hash>/{arena,staging} via libc::fallocate (selene-manager/src/local.rs:583-602), which immediately deducts those pages from /proc/meminfo MemAvailable, causing Budget::approve (selene/src/pool/budget.rs:44-72) to double-count them against host RAM and integrated-GPU KV cache capacity. However, the PR cannot merge as-is because it breaks three existing Linux CI integration tests across selene-manager and helios that run against real /dev/shm tmpfs managers, and the new backed_shm_bytes syscall path has no direct test coverage or CI run on head 135633f.

Merge Risk

Level: Medium

Walkthrough

Pre-merge Checks

Blockers

  1. Breaks three existing Linux CI integration tests that attach to a real /dev/shm tmpfs manager
    • Where:
      • selene-manager/tests/builder.rs:79-115 (over_budget_startup_fails_before_registering_memory)
      • selene-manager/tests/offload.rs:13-71 (startup_fails_and_releases_registration_when_a_rank_rejects_the_pool)
      • helios/src/offload/pool/tests.rs:20-92 (peer_registration_budget_fails_startup)
    • Verified behavior & impact: All three tests run in .github/workflows/native-serving.yml:48-63 (not opened) on ubuntu-24.04 (where /dev/shm is tmpfs) and spawn selene_manager::testing::Manager::new(), which creates fallocated arena and staging files under /dev/shm/selene (selene-manager/src/local.rs:26,125,583-602). With this PR, backed_shm_bytes returns full arena_bytes/staging_bytes, making Budget::costs compute host == 0:
      1. In selene-manager/tests/builder.rs:83-112, the first subcase (Budget { host: Ok(0), devices: [(u64::MAX, false)] }) now succeeds (0 <= 0) instead of failing, panicking at .expect("an unapproved pool must fail startup") (builder.rs:101). The second subcase (devices: [(1, false)]) fails the assertion assert!(reason.contains("needs 16777216 host bytes")) (builder.rs:106) because Budget::approve now formats "needs 0 host bytes".
      2. In selene-manager/tests/offload.rs:34-64, the local_approved == false iteration passes Budget { host: Ok(0), devices: vec![(u64::MAX, false), (u64::MAX, true)] }. Because host == 0 <= 0, local registration is approved instead of rejected, panicking at assert_eq!(approved, local_approved) (offload.rs:44) and registering 2 regions instead of 0.
      3. In helios/src/offload/pool/tests.rs:46-90, rejection == 0 passes Budget { host: Ok(1), devices: [(u64::MAX, false)] } to a peer RankAgent, which also runs conn::register_memory_blocking (selene/src/pool/agent.rs:611). With host == 0 <= 1, the peer attaches instead of rejecting, panicking at result.err().expect("an unapproved peer must fail startup") (helios/src/offload/pool/tests.rs:88).
    • Fix: Update all three tests for the new preallocated-tmpfs contract (e.g., use a TCP/remote manager whose anonymous data-staging has backed_bytes == 0 when testing host-budget rejection, or assert device-budget rejection with "needs 0 host bytes" on local tmpfs while explicitly asserting that host: Ok(0) approves a preallocated local tmpfs pool). Run the full Linux test commands from .github/workflows/native-serving.yml:51-63 (not opened):
      cargo test --locked --release --manifest-path selene/Cargo.toml (not opened) --features test-support
      cargo test --locked --release --manifest-path selene-manager/Cargo.toml (not opened) --features test-support
      cargo test --locked --release --manifest-path helios/Cargo.toml (not opened) --features runtime-core,server
      

Should Fix

  1. Add direct test coverage for backed_shm_bytes and the register_memory → Budget integration path
    • Where: selene/src/pool/conn.rs:682-704, selene/src/pool/budget/tests.rs:93-187
    • Verified behavior & impact: The two new tests in selene/src/pool/budget/tests.rs hand-construct PlannedRegion values and only test Budget arithmetic; nothing directly tests backed_shm_bytes (tmpfs magic check, st_blocks * 512 calculation, clamp to declared_bytes, sparse/unallocated file, non-tmpfs fallback to 0, missing/NUL path fallback to 0) or asserts the resulting backed_bytes / charges through a real Manager.
    • Fix: Add Linux unit tests in selene/src/pool/conn.rs (under mod tests) covering backed_shm_bytes on a fallocated file in /dev/shm (guarded or checked for tmpfs), a sparse file (set_len without fallocate), a non-tmpfs path (returns 0), and missing/NUL paths (returns 0), alongside the updated live-manager integration tests in selene-manager/tests/builder.rs asserting that a preallocated local pool approves with host: Ok(0) and still rejects insufficient GPU budget.

Subtract / Simplify

  1. Remove redundant Option threading and unreachable default for shared_backed (selene/src/pool/conn.rs:774-780, 853-855)
    • shared_backed is shared.map(...), so Some iff shared is Some (and regions is Some iff shared is Some via lines 813-829). Computing let mut shared_backed = (0u64, 0u64); inside if let Some(shared) = shared { ... } removes the double-Some tuple match at line 780 and the dead .unwrap_or((0, 0)) at line 854.
  2. Drop redundant .min(bytes) inside saturating_sub (selene/src/pool/budget.rs:19)
    • bytes.saturating_sub(backed_bytes) is identical to bytes.saturating_sub(backed_bytes.min(bytes)) for all u64 values (and backed_shm_bytes already clamps at conn.rs:697). Update the comment at selene/src/pool/budget/tests.rs:155 accordingly.
  3. Deduplicate the (bytes, backed_bytes) mapping in selene/src/pool/budget/tests.rs:25, 48-52, 65, 109-113, 163-167
    • The identical plan.iter().map(|region| (region.bytes, region.backed_bytes)) closure is repeated five times (and lines 25 and 65 exceed 100 columns / rustfmt formatting). Extract a small helper fn costs(plan: &[PlannedRegion]) -> std::result::Result<(u64, u64), String> next to fn plan(...).

Nits

  1. Reconcile startup progress summary with registered-bytes log (selene/src/pool/builder.rs:246-249, selene/src/pool/conn.rs:865-870): conn.rs:866 prints registered 40.0 GiB of pool memory while PreparedPool::summary() (printed by helios/src/offload/pool.rs:20-22) will now print 0 host bytes · 83886080 device bytes per GPU for a preallocated local pool. Mentioning backed/additional bytes in summary() (e.g., 0 additional host bytes) avoids operator confusion.
  2. Single-fd fstatfs + metadata and swap note (selene/src/pool/conn.rs:682-699): Opening path once and calling libc::fstatfs(file.as_raw_fd(), &mut statfs) + file.metadata() avoids two separate path lookups (statfs(path) then metadata(path)). Worth noting in the doc comment that on swap-enabled hosts, st_blocks still includes swapped-out tmpfs pages that cuMemHostRegister_v2 (helios/src/cuda.rs:471) will fault back into RAM.
  3. Note the PlannedRegion/RegisteredRegion struct field addition in the PR body (selene/src/pool/startup.rs:21-46, re-exported at selene/src/pool/mod.rs:60): Acceptable for an unpublished workspace crate with all in-tree call sites updated, just worth mentioning clearly.

Dropped on verification