Correctness and contracts report · NVIDIA/hyperflare-inference #625

Raw Markdown for agents: https://autobot.eidonix.com/p/cbc6127e-b70b-492b-b4b3-94faaae03188.md

Correctness, Contracts & System-Level Consequences — PR #625 (f2d03bc)

Head reviewed: f2d03bc17d065a99f0216b9c5ed0902ff3ba8984, 7 files, +1621/−109, based on main 8da73911. Files read: eos/src/unix.rs (impl :1-828, tests :830-1354), selene/src/offload.rs, selene/src/offload/tests.rs:1090-1380, helios/src/offload/mod.rs, helios/src/runtime_core/model.rs:890-990, plus direct callers/contracts selene/src/slab.rs, selene/src/pool/shm.rs, selene/src/pool/net.rs, helios/src/startup.rs, eos/src/windows.rs, eos/src/lib.rs, tests/server/test_prefix_cache_offload.py, docs/design-review.md, AGENTS.md. No test suite could be run in this environment: every statement below comes from reading code and the diff.

Key findings

  1. Major — eos/src/unix.rs:695-700. The closing whole-range advice is decided by a single fell_back boolean, so the success path re-arms MADV_HUGEPAGE across a mapping this same function had deliberately set MADV_NOHUGEPAGE on for synchronous-compaction hosts, and the fallback path applies NOHUGEPAGE where the policy did not ask for it. The startup mitigation is startup-scoped only.
  2. Minor — selene/src/offload.rs:702-728. The measured span of PrepareTimings::slab_populate skips the failed split-by-rank probe on the split→contiguous fallback, so the new operator-facing durations do not reconcile with the phase and under-report the path they exist to explain (metric-span check).
  3. Minor — selene/src/offload.rs:706-736 / helios/src/runtime_core/model.rs:978 / helios/src/startup.rs:325-328. Progress labels are emitted before the work they name and Phase::detail retains only the last string, so a stalled monolithic populate shows a static detail — the PR's "live sub-step progress" claim is stronger than the code delivers for the dominant phase.
  4. Minor — eos/src/unix.rs:450-465, :749-755. THP policy is re-probed from sysfs//proc on every map_host call (including multi-host pool staging), is never recorded anywhere, and unknown sysfs silently routes to the heaviest mode.

Areas verified sound (stated plainly so downstream does not re-litigate them) are listed at the end, together with the Charter #210 position and open questions.


1. Major — one boolean decides the whole mapping's THP flag; the mitigation is undone at the closing madvise

File/line: eos/src/unix.rs:693-700 (fn populate_adaptive_with), with eos/src/unix.rs:604-606 and eos/src/unix.rs:259-263.

Quote (the defect):

    // All pages are populated writable; unify VMA flags across the whole mapping so Linux
    // merges all sub-VMAs back into one contiguous VMA.
    let final_advice = if fell_back {
        libc::MADV_NOHUGEPAGE
    } else {
        libc::MADV_HUGEPAGE
    };
    advise_range(base_ptr, bytes, final_advice);
    Ok(())

Quote (what it contradicts, same function, earlier):

    if fallback_needs_nohugepage {
        advise_range(base_ptr, bytes, libc::MADV_NOHUGEPAGE);
    }

fallback_needs_nohugepage is computed in select_population_mode at eos/src/unix.rs:259-263:

    let fallback_needs_nohugepage = matches!(enabled, ThpEnabled::Always | ThpEnabled::Unknown)
        || matches!(defrag, ThpDefrag::Always | ThpDefrag::Unknown);
    PopulationMode::AdaptiveHugepage {
        fallback_needs_nohugepage,
    }

Impact — success path (fell_back == false). The unsplit mapping was given MADV_NOHUGEPAGE at :604-606 precisely because default faults can synchronously compact on these hosts (defrag=always, or unreadable sysfs → ThpEnabled::Unknown/ThpDefrag::Unknown, e.g. a container without /sys/kernel/mm/transparent_hugepage, where select_population_mode also falls through to this branch). Line 700 then applies MADV_HUGEPAGE to [base_ptr, base_ptr + bytes), which clears VM_NOHUGEPAGE for the whole VMA. The slab lives for the entire serving session (the pool is prepared once at startup), so every later fault in that range — most importantly swap-in of a 48–119 GiB slab on a ~237 GiB host under pressure — re-enters do_huge_pmd_anonymous_page with GFP_TRANSHUGE/__GFP_DIRECT_RECLAIM: the same synchronous direct-reclaim and compaction behaviour #616 reports, relocated from startup into request-serving latency. The PR body advertises the mitigation for exactly these policies ("advising MADV_NOHUGEPAGE over the unsplit mapping first when default faults can synchronously compact") and does not disclose that the closing advice reverts it.

Impact — fallback path (fell_back == true). MADV_NOHUGEPAGE is applied to the whole range even when fallback_needs_nohugepage == false, i.e. the configuration every benchmark in the PR description was measured under (enabled=madvise, defrag=madvise). Already-faulted PMDs survive MADV_NOHUGEPAGE, so no memory is lost and the single-VMA merge that cuMemHostRegister_v2/ibv_reg_mr depend on still holds — but khugepaged can never collapse the base-page tail of that mapping for its lifetime, and after an early fallback the tail is the majority of the mapping. This is the case visible in the PR's own evidence: FIXED_119G reports AnonHugePages=43,454 MiB together with VmFlags nh.

Concrete fix: key the closing advice on both facts —

let final_advice = if fell_back || fallback_needs_nohugepage {
    libc::MADV_NOHUGEPAGE
} else {
    libc::MADV_HUGEPAGE
};

Pre-faulted PMDs are preserved by MADV_NOHUGEPAGE, so the success path keeps its huge head, the uniform-advice/single-VMA property at :693-694 is preserved, and the fallback path stops withdrawing THP hints on hosts that never needed the withdrawal. Alternatively, degrade the closing call to per-sub-range advice that reproduces the intended final state, and assert it with the existing populate_linux_applies_eager_and_base_page_policies style VmFlags test extended to the defrag=always matrix cell (the tests currently assert EagerHugepage vs BasePages, not the adaptive-final-advice interaction — eos/src/unix.rs:835-1354).


2. Minor — slab_populate span excludes the failed split-by-rank probe (metric-span check)

File/line: selene/src/offload.rs:702-728.

Quote:

          let split = if directory.is_none()
              && effective.pool.is_none()
              && effective.compression == KvCompression::Off
          {
              on_step(&format!("allocating {size_label} split host slab"));
              let started = Instant::now();
              slab::SlabPool::try_sized_by_rank(&layout, bytes, intake, &contexts, registrar)?
                  .map(|pool| {
                      timings.slab_populate = Some(started.elapsed());
                      pool
                  })
          } else {
              None
          };
          let pool = match split {
              Some(pool) => pool,
              None => {
                  on_step(&format!("populating {size_label} host slab"));
                  let started = Instant::now();
                  let mut pool = slab::SlabPool::sized(&layout, bytes, intake)?;
                  timings.slab_populate = Some(started.elapsed());

Impact. When try_sized_by_rank returns Ok(None) (host without HOST_NUMA VMM split mapping — GA10B or Windows-style fallback, exercised by prepare_reports_split_fallback_to_contiguous_timings_and_steps at selene/src/offload/tests.rs:1197-1251), the second Instant starts only after the split attempt has already failed, and timings.slab_populate is overwritten with the contiguous populate time. The cost of the failed probe (a driver capability query plus a VMM reservation attempt) is therefore attributed to neither allocate (which is only emitted in the Some(pool) arm) nor populate. The new numbers in Prepared::summary() (selene/src/offload.rs:425-427) will not add up to the enclosing Prepare host prefix cache phase duration recorded by helios/src/startup.rs for helios/src/runtime_core/model.rs:934-980, which is precisely the diagnostic operators are being given for #616. This is the only place in the diff where a measured span shrinks relative to the surrounding scope.

Concrete fix. Start one Instant before the if and accumulate:

let started = Instant::now();
let split = ...;
...
timings.slab_populate = Some(timings.slab_populate.unwrap_or_default() + started.elapsed());

or record the split probe in a fourth field so allocate/populate/register/scan reconcile with phase elapsed. Either way add an assertion in the existing fallback test that slab_populate is measured from before the split attempt.


3. Minor — progress steps are pre-work labels, not progress; a stalled populate shows a static detail

Files/lines: selene/src/offload.rs:706, :719, :723, :736 → helios/src/runtime_core/model.rs:978 → helios/src/startup.rs:325-328.

Quote (label emitted before the work, selene/src/offload.rs:719-726):

                  on_step(&format!("populating {size_label} host slab"));
                  let started = Instant::now();
                  let mut pool = slab::SlabPool::sized(&layout, bytes, intake)?;
                  timings.slab_populate = Some(started.elapsed());
                  on_step(&format!("registering {size_label} host slab with CUDA"));
                  let started = Instant::now();
                  pool.register(registrar, context)?;

Quote (the sink keeps a single string):

    pub fn detail(&self, detail: impl Into<String>) {
        self.state.lock().unwrap().detail = detail.into();
        self.publish(StartupStatus::Running);
    }

Impact. Phase::detail overwrites one detail string with no progress persistence, and the redraw worker only samples state on a 10 s cadence while non-terminal (helios/src/startup.rs:250-266). Because every label is emitted before the work it names, the UI shows populating 119.0 GiB host slab for the whole duration of the populate — including the compaction stall the PR exists to shorten — and map_host/populate_chunks have no progress callback, so the ~1,900 64 MiB MADV_POPULATE_WRITE chunks produce no intermediate update. The PR description claims "Operators running flare run with large host prefix-cache slabs see live sub-step progress updates" and docs/prefix-cache-offload.md:990-996 repeats it; the code delivers four coarse phase-boundary labels. This is a claim-accuracy problem, not a wiring bug (the wiring at helios/src/runtime_core/model.rs:978 is correct), hence Minor.

Concrete fix. Emit labels on completion as well as start (e.g. on_step("populating …") before, on_step("populated … in X") after), and/or thread a byte-progress callback from populate_chunks into the existing Phase::advance_bytes (helios/src/startup.rs:303) so a stalled chunk advances a counter rather than leaving a static word.


4. Minor — THP policy re-probed on every allocation, never exposed, Unknown silently selects the adaptive path

File/line: eos/src/unix.rs:450-465 (detect_thp_policy), reached unconditionally from eos/src/unix.rs:749-755.

Quote:

pub fn map_host(bytes: usize) -> io::Result<usize> {
    map_host_with(bytes, |guard| {
        #[cfg(target_os = "linux")]
        {
            let policy = detect_thp_policy();
            populate_linux(guard, &policy)
        }

Impact (three small, related points).

Concrete fix: cache the policy once per process (OnceLock<ThpPolicy>), log the selected mode at startup, and add a short mode token to summary(). Low severity; no correctness consequence on its own.


Verified sound — do not re-open these

Charter & process

Charter #210 and docs/design-review.md:106-115 require actual served-workload measurements for a performance PR. The served flare run A/B is explicitly unrun (PR body: "not yet timed inside a live flare run launch"); the 128.56 s → 30.99 s (4.15x) and 57.19 s + 11.27 s figures are author-supplied standalone map_host + cuMemHostRegister_v2 numbers with no committed harness or raw log in the diff. The unrun work is now recorded in docs/TODO.txt:1-6, which satisfies AGENTS.md:57-58. So the mergeable unit is "allocator rewrite + timing plumbing with the served A/B deferred and tracked" — a maintainer call, not a code defect. Merge ordering matters: #628 (same author) and #621 also edit docs/prefix-cache-offload.md, and #576 is the only eos/src/unix.rs collision.

Open questions

  1. Which CI job actually failed on the pre-rebase head 9639e57 (the Autobot Review blocker) and whether it passes on f2d03bc — the strong hypothesis is the pre-existing Python CPU tests failure fixed by #624/8da73911, now the base, but no job log was accessible.
  2. Does the fatal non-EINVAL/ENOSYS populate path behave correctly end-to-end (over-large --prefix-cache-memory aborting startup)? The code path exists and is right, but nothing in the repo exercises it.
  3. What is the cost of the post-fallback whole-range MADV_NOHUGEPAGE on a slab with a genuine huge-page head? The FIXED_119G run (43,454 MiB AnonHugePages, VmFlags nh) is exactly that case and the repository cannot bound the loss.
  4. Do the 15 ms/50 ms latency floors, 1 GiB/s and 256 MiB/s rates, and the two-consecutive-compact_stall confirmation generalise beyond the two reported hosts (one two-NUMA x86_64, one ARM64 GB10)?

Could not be found / not done