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
- Major —
eos/src/unix.rs:695-700. The closing whole-range advice is decided by a singlefell_backboolean, so the success path re-armsMADV_HUGEPAGEacross a mapping this same function had deliberately setMADV_NOHUGEPAGEon for synchronous-compaction hosts, and the fallback path appliesNOHUGEPAGEwhere the policy did not ask for it. The startup mitigation is startup-scoped only. - Minor —
selene/src/offload.rs:702-728. The measured span ofPrepareTimings::slab_populateskips 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). - 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 andPhase::detailretains 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. - Minor —
eos/src/unix.rs:450-465,:749-755. THP policy is re-probed from sysfs//procon everymap_hostcall (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).
- Re-probe cost.
detect_thp_policyruns permap_hostcall, andpopulate_linux(:723-731) additionally reads/proc/self/status,/proc/buddyinfoand/proc/vmstatper adaptive chunk. Linux callers includeSlabPool::new(selene/src/slab.rs:164) and multi-host pool staging throughRegion::anonymous←Staging::new(selene/src/pool/shm.rs:74-86,selene/src/pool/net.rs:95). Nothing on the serving request path callsmap_host, so this is not a hot-path claim — it is merely repeated, unlogged file I/O. - Snapshot semantics. The mode (and the
/proc/buddyinfobound) is fixed at allocation, but the resulting VMA flags persist for the process lifetime, so a slab allocated while order-9 blocks happen to be plentiful is frozen into the eager-scale path for the rest of the run even if memory fragments afterwards (see finding 1 for the consequence). - Observability. The selected
PopulationMode,fallback_needs_nohugepage, and theUnknown→adaptive fallthrough are never recorded in logs or in the otherwise-extendedPrepared::summary(), so an operator cannot tell which of the four modes a given slab took. Since the PR's framing is operator diagnosis of #616 andsummary()is already being extended (selene/src/offload.rs:415-475), one mode token there would make the behaviour auditable at negligible cost.
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
- No UB, no double
munmap.MappingGuard(eos/src/unix.rs:139-181) is neitherCopynorClone,commitusesmem::forget, andmap_host_with(:737-747) returns onlyguard.commit();unmap_hostremains the only other release path (callersselene/src/slab.rs:446,selene/src/pool/shm.rs:148,helios/src/cuda.rs:1624,1766). RAII unmap on population error is correct. bytes == 0 → EINVALregresses no caller (eos/src/unix.rs:741-743):region_bytesalready rejected zero slots (selene/src/slab.rs:53-56) andRegion::anonymousalready rejected zero bytes (selene/src/pool/shm.rs:75-77).- Errno policy is correct and declared.
EINTRretried; volatile page-strided fallback only onEINVAL/ENOSYS; all other errnos propagated (eos/src/unix.rs:511-537) and surfaced asinvalid("allocate host slots: …")(selene/src/slab.rs:164-165). This is a behaviour change frommain(which fell back to volatile writes on any non-zero return) — declared in the PR body, and better: an over-large--prefix-cache-memorynow aborts startup instead of returning a lazily-populated mapping that is OOM-killed later. Side effect worth naming: that fatal path has no in-repo end-to-end test. - Single-VMA geometry holds. The whole-range
madviseat:700is the documented mechanism for the merge, and pre-faulted PMDs surviveMADV_NOHUGEPAGE, so "1 VMA,AnonHugePages>0,VmFlags nh" in the PR evidence is consistent with the code. summary()compatibility. The rewritten format (selene/src/offload.rs:415-475) is byte-identical for thedisabledcase (returns beforePreparedexists) and for both restore-only branches (:445-451), asserted atselene/src/offload/tests.rs:1317-1379and:1063-1102; the parenthetical clauses keep the previous comma layout. The four new tests do assert the new text (tests.rs:1192,:1249,:1308) including restore-only unchanged (:1348,:1375).- Phase label / stage contract unchanged.
progress.phase("Prepare host prefix cache", None)(helios/src/runtime_core/model.rs:934) still resolves throughStartupStage::from_label,phase.finishstill receives the summary (:980), and the disabled path returns before the phase (:931-933), sotests/server/test_prefix_cache_offload.py:135still holds. - API surface additive.
helios/src/offload/mod.rs:72-120preservesprepare_with_inputsandprepare_with_inputs_budgetwithpub fnparity againstselene::offload:562-592;Preparedgained a field only. Timings allocation is lazy on the disabled/restore-only paths (PrepareTimings::default()atselene/src/offload.rs:684,Instant::now()only inside the three instrumented branches). - Windows parity.
eos/src/windows.rsis untouched and already prefaults per page; the new helper set is#[cfg(unix)]-only viaeos/src/lib.rs:9-12. No#[cfg]gap introduced. - No protobuf/wire/captured-graph/model-core/ABI change.
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
- Which CI job actually failed on the pre-rebase head
9639e57(the Autobot Review blocker) and whether it passes onf2d03bc— the strong hypothesis is the pre-existingPython CPU testsfailure fixed by #624/8da73911, now the base, but no job log was accessible. - Does the fatal non-
EINVAL/ENOSYSpopulate path behave correctly end-to-end (over-large--prefix-cache-memoryaborting startup)? The code path exists and is right, but nothing in the repo exercises it. - What is the cost of the post-fallback whole-range
MADV_NOHUGEPAGEon a slab with a genuine huge-page head? TheFIXED_119Grun (43,454 MiBAnonHugePages,VmFlags nh) is exactly that case and the repository cannot bound the loss. - Do the 15 ms/50 ms latency floors, 1 GiB/s and 256 MiB/s rates, and the two-consecutive-
compact_stallconfirmation generalise beyond the two reported hosts (one two-NUMA x86_64, one ARM64 GB10)?
Could not be found / not done
- No test execution was possible in this environment; every statement is from reading the code and diff.
selene/src/offload/tests.rs:1-1090(the older fixtures the four new tests build on) was not read line by line.- No benchmark script, raw log, or profiler output backing the 4.15x claim exists in the diff.