Recommendation: Changes Requested
The core allocator rewrite in eos/src/unix.rs and startup timing/progress plumbing in selene and helios are technically sound, well-reasoned, and directly address the THP direct-compaction root cause reported in #616 (including preserving a single merged VMA via pre-anchored anon_vma and whole-range final madvise). However, CI failed on head 9639e57 (cause not retrievable from repo metadata), the Charter #210 served flare run verification gap is neither run nor recorded in docs/TODO.txt (AGENTS.md:57-59), and a couple of targeted NUMA/multi-tenant guard improvements plus a clean deduplication in selene/src/offload.rs should be resolved before merge.
Merge Risk
Level: Medium
- Shared allocator blast radius (
eos/src/unix.rs): Every host prefix-cache slab (selene/src/slab.rs:164), remote pool staging buffer (selene/src/pool/shm.rs:78), and CUDA host-registration test (helios/src/cuda.rs:1599 (not opened),1665) allocates througheos::map_host. The policy matrix, chunkedMADV_POPULATE_WRITE, RAIIMappingGuard, and single-VMA merge geometry are verified sound, but the Linux-specific adaptive heuristics have no runtime override and CI is currently failing on head9639e57. - Single-VMA & lifetime invariants preserved: Pre-anchoring one shared
anon_vmaon the unsplit mapping (eos/src/unix.rs:531-550) keeps peak VMA count bounded to at most 3 during the entire adaptive loop and collapses back to 1 VMA beforecuMemHostRegister_v2/ibv_reg_mr(eos/src/unix.rs:609-616).MappingGuard(:139-181) prevents leaked mappings on population errors. - Cross-PR overlap & observability: Open PRs #576 (
eos/src/unix.rs) and #323 (selene/src/offload.rs,selene/src/offload/tests.rs,helios/src/offload/mod.rs,helios/src/runtime_core/model.rs,docs/prefix-cache-offload.md) overlap on the same files andprepare_with_inputs*signature family.Prepared::summary()appends elapsed durations inside existing parenthetical clauses (selene/src/offload.rs:415-475); no in-repo test asserts the old text.
Walkthrough
eos/src/unix.rs:86-680: Rewritesmap_hostbehindmap_host_with+ RAIIMappingGuard(unmaps on population error, rejectsbytes == 0withEINVAL), retriesMADV_POPULATE_WRITEonEINTRwith volatile-write fallback only onEINVAL/ENOSYS, and adds Linux THP sysfs detection (enabled,defrag,hpage_pmd_sizewith 2/32/512 MiB portable defaults) selecting amongBasePages,EagerHugepage,KernelDefaultOpportunistic, andAdaptiveHugepage(growing PMD-aligned chunks up tomax(16 MiB, hpage_pmd_size),/proc/buddyinforeserve checks, chunk latency +/proc/vmstatcompact_stallfallback to 64 MiB base-page chunks, and final whole-rangemadviseVMA merge). Adds ~440 lines of unit and live/proc/self/smapstests (:769-1202).selene/src/offload.rs:328-480, 573-795: AddsPrepareTimings(slab_populate,cuda_register,disk_scan) toPrepared, addsprepare_with_inputs_budget_with_progress(..., on_step: impl FnMut(&str))while keeping existing entry points, instruments split allocation, split→contiguous fallback, contiguous populate/CUDA registration, and disk scanning, and appendsallocate/populate/register/scandurations toPrepared::summary().selene/src/offload/tests.rs:1107-1380: Adds four unit tests covering split-by-rank, split→contiguous fallback, contiguous+disk, and restore-only step sequences, timings, and summary strings.helios/src/offload/mod.rs:30-33, 82-120&helios/src/runtime_core/model.rs:966-980: Re-exportsPrepareTimings, forwardsprepare_with_inputs_budget_with_progress, and wires|step| phase.detail(step)intoNativeModel::prepare_offloadwithout changing thePrepare host prefix cachephase label orStartupStage.docs/prefix-cache-offload.md:516-535, 986-995: Documents the Linux THP policy-aware population and single-VMA merging (§2.5) and the live step details and per-step timings (§2.11).
Pre-merge Checks
- [PASS] Security / malicious screen: Read-only
/sys/kernel/mm/transparent_hugepage/*,/proc/buddyinfo, and/proc/vmstatreads plus standardmmap/madvise/munmapsyscalls; no new dependencies, env vars, network I/O, or unsafe external input handling. - [WARN] Charter & value fit: Directly addresses reproducible bug #616 (caused by #589) in the right layer without adding switches or model-specific logic, but lacks a served
flare runA/B measurement (Charter #210 /docs/design-review.md:109-115) and omits adocs/TODO.txtentry for unrun checks (AGENTS.md:57-59); also warrantseos/offload owner sign-off given the #589 dependency. - [WARN] Related / duplicate / conflict check: Not duplicated on
main(andselene-manager/src/arena.rs:93remains separate/out-of-scope); likely rebase/API coordination needed with open #576 (eos/src/unix.rs) and #323 (prepare_with_inputs*signatures and offload docs). - [WARN] Tests & verification evidence: Strong unit tests and standalone SM120/SM121 A/B + CUDA DMA checks are reported, but CI failed on head
9639e57and end-to-endflare run/tests/server/test_prefix_cache_offload.py(not opened) remain unrun.
Blockers
- Failing CI on head
9639e57: CI reported a failure on the current head across the applicable workflows (.github/workflows/native-serving.yml(not opened),.github/workflows/helios-lifecycle.yml(not opened)), and the failing job log is not available in the repository metadata. Fix: Inspect the failing CI leg, fix any regression (or re-run if it is the pre-existingselene-managera_freed_window_credit_is_granted_without_waiting_for_the_clocktiming flake), and verify all required checks pass on head before merge.
Should Fix
- Unrun served-workload A/B and missing
docs/TODO.txtentry (AGENTS.md:57-59,docs/design-review.md:109-115): The 128.56 s → 30.99 s and 68.46 s measurements are from a standaloneeos::map_host+cuMemHostRegister_v2harness; noflare runA/B againstmainwas run, and the PR adds nodocs/TODO.txtentry for the unrunflare run, live RDMAibv_reg_mr, or 16 KiB/64 KiB kernel checks. Fix: Either runflare run <exported-core> --prefix-cache-memory <size> --prefix-cache-disk <dir>againstmainunder THPenabled=madvise, defrag=madviseand include thePrepare host prefix cachetimings, or record the unrun end-to-endflare run, live RDMA, and non-4 KiB kernel checks indocs/TODO.txtperAGENTS.md:57-59. - Respect process NUMA memory restrictions when summing
/proc/buddyinfo(eos/src/unix.rs:272-328):parse_buddyinfo_free_hugepagessumsNormal/Movablefree huge pages across every NUMA node in/proc/buddyinfo. While summing across nodes is appropriate under unconstrainedMPOL_DEFAULT(where Linux ≥ 5.2 allocatesMADV_HUGEPAGEacross nodes in the fast path before compacting, so takingminacross nodes would wrongly disable THP on asymmetric-occupancy hosts), processes bound to a subset of nodes viacpuset.memsornumactl --membindsee unreachable remote nodes counted inpreferred_total. (The latency/compact_stallguard still bounds any stall to one chunk, so #616's 15-minute stall does not recur, but the upfront buddyinfo guard is bypassed.) Fix: Parse theNode N,id on each line and, when/proc/self/statusexposesMems_allowed_list, sum only allowed NUMA nodes (falling back to all nodes if unreadable), plus add a unit test for a filtered two-node fixture. - Avoid single-strike false fallback on system-wide
/proc/vmstat compact_stall(eos/src/unix.rs:572-595): Becausecompact_stallis host-wide, a single slow chunk (elapsedin(stall_floor, hard_ceiling], e.g., from brief scheduler contention during parallel multi-rank startup) coinciding with a+1compact_stallfrom an unrelated process triggersfell_back = true; break;and populates the entire remainder of a 100+ GiB slab with base pages. Fix: Require 2 consecutiveChunkStallCheck::CheckCompactStallhits with advancingcompact_stallbefore settingfell_back(keepingChunkStallCheck::Stalledabovehard_ceilingas an immediate 1-chunk breaker so real compaction stalls still exit in one chunk).
Subtract / Simplify
- Deduplicate the 9-line populate/register sequence (
selene/src/offload.rs:702-735): Lines713-723(Nonearm oftry_sized_by_rank) and725-735(elsearm) are byte-for-byte identical. Attempttry_sized_by_rankintolet split: Option<SlabPool>first, then share onematch split { Some(pool) => pool, None => { ... } }block (~−16 lines and a single source of truth for step labels and timer resets). - Consider dropping the pass-through
helios::offload::prepare_with_inputs_budgetwrapper (helios/src/offload/mod.rs:82-99): Its only caller in the workspace ishelios::offload::prepare_with_inputs(:79), sinceNativeModel::prepare_offload(helios/src/runtime_core/model.rs:966) moved toprepare_with_inputs_budget_with_progress. If preserving thepub fnsignature for external Rust consumers / parity withselene::offloadis intentional, keep it; otherwise pointprepare_with_inputsstraight toprepare_with_inputs_budget_with_progress(..., None, |_| {})and delete lines82-99.
Nits
eos/src/unix.rs:603-605: Whenfallback_needs_nohugepageistrue, line528already advisedMADV_NOHUGEPAGEon the entire unsplit mapping and the loop never advised[offset, bytes), so the secondadvise_range(tail_ptr, tail_len, libc::MADV_NOHUGEPAGE)beforepopulate_chunksis redundant.eos/src/unix.rs:621-632: Consider a brief unit test invokingpopulate_linuxdirectly with syntheticEagerHugepageandBasePagespolicies to assertVmFlags(hgvs absent) independently of the test host's sysfs settings.selene/src/offload.rs:333-336:PrepareTimings.slab_populatestores both split-by-rank allocation time (allocate) and contiguous population time (populate); splitting intoslab_allocateandslab_populate(or renaming toslab_ready) would make programmatic consumers self-describing.docs/prefix-cache-offload.md:519-522: "prefaulted writable in bounded chunks" appears before "On Linux", whereaseos/src/windows.rs:179-183still prefaults in one page-strided loop; clarify that bounded chunking applies on Unix (eos/src/unix.rs:673-678). Also note in the PR description's compatibility section thatPrepared::summary()appends timing tokens to existing parenthetical clauses and that 64 MiB chunking applies across all Unix modes.- Out of scope for this PR (follow-up):
selene-manager/src/arena.rs:93still issues an unconditionalmadvise(MADV_HUGEPAGE)and may warrant a separate follow-up ordocs/TODO.txtnote.
Dropped on verification
- Dropped — "Reversed error handling makes transient
ENOMEMunder fragmented memory abort startup instead of degrading to volatile writes" (Correctness Finding C): Verified factually incorrect against Linux VM semantics.MADV_POPULATE_WRITEnever returnsENOMEMdue to THP fragmentation (Linux's fault handler transparently falls back to 4 KiB base pages);ENOMEMoccurs only on genuine physical memory or cgroup exhaustion. Onmain, ignoringENOMEMand executingwrite_volatile(0)(main:eos/src/unix.rs:106-116) faulted straight into the OOM killer (SIGKILL) instead of degrading. ReturningErrand unmapping viaMappingGuard(eos/src/unix.rs:173-180, 445-453) is a concrete improvement and is explicitly stated in "What Changed". - Dropped — "Single-VMA
/proc/self/smapstest assertions flake when a concurrent test creates an adjacent mapping" (Correctness Finding E): Verified false ineos/src/unix.rs:789-811.parse_smaps_intersecting_vmaschecks strict half-open interval overlap (vma.start < end && vma.end > start), so adjacent VMAs (vma.end == startorvma.start == end) never intersect, and no concurrent thread can map inside[address, address + bytes)while the test owns the mapping. - Dropped — "Unix/Windows
bytes == 0contract divergence and missing Windows chunking" (Correctness Finding D): Verified low-signal/inaccurate.eos/src/windows.rs:167-176callsVirtualAlloc(NULL, 0, ...), which already returnsNULLwithERROR_INVALID_PARAMETER, and Windows's page-strided user-space write loop does not hold a monolithic LinuxMADV_POPULATE_WRITEkernelmmap_lock; the minor doc phrasing point is kept as a Nit. - Dropped — "Whole-range
MADV_NOHUGEPAGEafter mid-slab fallback drops THP hints for the whole slab, head included" (Dossier Finding 3 / Correctness Finding B rider): Verified misleading. Linuxmadvise(MADV_NOHUGEPAGE)does not split already-populatedAnonHugePagesin the prefix (confirmed by the PR's smaps results) and Linux has nomadviseflag to resetVM_HUGEPAGEto neutral, so unifying the slab toMADV_NOHUGEPAGEis the right way to merge sub-VMAs into 1 VMA without causingkhugepagedto scan and compact the base-page tail. - Dropped — "4 KiB test pools perform ~5 extra
/sys+/procfile reads per call" (Dossier Finding 3 / Correctness §2): Overstated. For mappings smaller thanhpage_pmd_size,populate_adaptive_withexits immediately ateos/src/unix.rs:503-511without reading/proc/buddyinfoor/proc/vmstat(only the 3/syspolicy reads run, andmap_hostis not on the serving hot path). - Dropped — "Collapse
PopulationMode::BasePagesandKernelDefaultOpportunisticintoChunkedBasePagesand merge into fall-through" (Subtraction Rank 3): Verified flawed. The fall-through inselect_population_mode(eos/src/unix.rs:259-263) isAdaptiveHugepage, notBasePages, and calling(ThpEnabled::Always, ThpDefrag::Madvise | DeferPlusMadvise)ChunkedBasePageswould misstate its behavior (Linux allocates opportunistic huge pages there). Keeping the distinct variant documents the 24-cell decision table cleanly, and keepingThpPolicy.page_sizepreserves testability ofpopulate_linux. - Dropped — "Take
minacross NUMA nodes inparse_buddyinfo_free_hugepages" (Correctness Finding A proposed fix): Would regress two-NUMA workstations where one node holds model weights/embeddings (0 free huge pages) while the other has abundant free huge pages, forcing immediate base-page fallback at byte 0. Replaced in Should Fix #2 withMems_allowed_listfiltering.