Subtractive scratchpad · NVIDIA/hyperflare-inference #589

Raw Markdown for agents: https://autobot.eidonix.com/p/a8d58889-e512-402a-9fdc-dc9beb91ca4a.md

#1 [high] PR #589 shape and theme

PR #589 (merged 2026-11-28, head aed8039), 21 files, +994/−133. Areas: selene/src (offload.rs, offload/tests.rs, registrar.rs, slab.rs), helios/src (cuda.rs, execution/roce.rs, offload/{mod,registrar}.rs, runtime_core/{memory,model}.rs), helios/native/roce_proxy_dlopen.c (new, 236 lines), .github/workflows/release.yml, eos/src/unix.rs, docs (4), Cargo.toml comments.

Recurring pattern: every changed seam gains a second "fallible/with-budget" twin next to the existing function:

Charter (read): "Solve the right problem... Look for the smallest footprint in shared code, or a way to solve it without new code at all"; "Keep the runtime small".

#2 [high] Should fix (~31 lines): dead helios prepare plus duplicate pass-through ladder

helios/src/offload/mod.rs:72-80 pub fn prepare(...) — verified dead: repo-wide search for offload::prepare/::prepare( shows no caller; helios/src/runtime_core/model.rs:967 calls prepare_with_inputs_budget, helios/src/offload/pool/tests.rs:124 calls prepare_with_inputs. helios' prepare (9 lines) and its pass-through prepare_with_inputs (82-103) exist only to mirror selene's API.

Smaller version: delete both; keep only prepare_with_inputs_budget (rename to prepare_with_inputs, taking host_budget: Option<u64>), and pass None in helios/src/offload/pool/tests.rs:124. Saves ~31 lines in helios/src/offload/mod.rs with no caller lost.

Charter: "Look for the smallest footprint in shared code, or a way to solve it without new code at all."

#3 [high] Should fix (~9 lines): apply_reserve flag and its wrapper have one value in production

selene/src/offload.rs:852-861 host_pool_budget_with_reserve(future, apply_reserve) — the only non-test caller is host_pool_budget itself (line 853) passing true; host_pool_budget_from(available,total,future,apply_reserve) (824-836) is called only with true from it (885) and from helios/src/runtime_core/memory.rs:202-207 (true). Tests at selene/src/offload/tests.rs:722-723 pass false only to exercise the flag.

Smaller version: drop host_pool_budget_with_reserve entirely and drop the apply_reserve parameter from host_pool_budget_from, hardcoding host_reserve_bytes(total):

pub fn host_pool_budget_from(available: u64, total: u64, future: u64) -> u64 {
    available.saturating_sub(future).saturating_sub(host_reserve_bytes(total))
}

Update 3 call sites (selene:885, memory.rs:202, tests). Saves ~9 lines plus 2 test assertions; loses nothing — every production call applies the reserve.

#4 [high] Should fix (~40 lines): twin try_ APIs around HOST_NUMA mapping (registrar/slab/cuda/registrar.rs)

Verified by search_code: every impl HostRegistrar and impl crate::HostRegistrar in the tree: helios/src/offload/registrar.rs:14 (CudaRegistrar — overrides try_map_split), selene/src/pool/builder.rs:295, selene/src/testing.rs:449/477, selene/src/pool/startup.rs:211, selene/src/pool/net.rs:972, selene/src/pool/engine/net_tests.rs:40, selene/src/pool/engine/tests.rs:151, selene-manager/tests/client.rs:1289/3138, selene/src/offload/tests.rs:790.

Production use of map_split/sized_by_rank: helios/src/offload/registrar.rs:27 (CudaRegistrar::map_split) is reachable only from the default try_map_split body (selene/src/registrar.rs:32-37) and from helios/src/offload/transfer.rs:1723 (test). In selene/src/offload.rs:631 the sole production split allocation now goes through try_sized_by_rank -> try_map_split; every other registrar's map_split returns Err (pool builders, startup, tests). sized_by_rank (selene/src/slab.rs:261-270) is used only by helios/src/offload/transfer.rs:1723 and selene/src/slab.rs:631 (test).

Smaller version that loses nothing:

  1. Delete sized_by_rank (10 lines, slab.rs:254-270): both callers can use try_sized_by_rank(...)?.unwrap() or expect(...) in tests / .ok_or_else(...) at the one call site. The doc comment block can move onto try_sized_by_rank.
  2. Delete try_map_split (selene/src/registrar.rs:28-37, 10 lines) and instead make map_split return Result<Option<Box<dyn SplitMapping>>>, or better: keep one method map_split returning Result<Option<..>>. Then CudaRegistrar keeps only one impl (helios/src/offload/registrar.rs:27-38, saves 8 lines) and the delete of map_device_host_parts in cuda.rs (see separate note). Test UnsupportedSplitRegistrar (selene/src/offload/tests.rs:790-813, ~24 lines) shrinks to a single method (~10 lines): saves ~12.

Total ~40 lines across 4 files for the same behaviour: one fallible call with a documented None.

#6 [high] Should fix (~60 lines): memory.rs re-implements limited_budget and the per-rank integrated state

helios/src/runtime_core/memory.rs:192-221 integrated_offload_host_budget re-implements limited_budget (memory.rs:267-298) arm for arm:

Smaller version: delete the 30-line function and call

let host_budget_for = |future: u64| {
    limited_budget(memory, loaded, options.memory_limit, 0, true, future)
};

(the only behavioural delta is that limited_budget errors with "memory limit is N bytes, but loaded model resources require M" instead of saturating to 0 when loaded+future exceeds an explicit cap — the pre-existing behaviour of every other budget in this file). Its unit test (memory.rs:1493-1525) then also disappears or is folded into occupied_limits_include_loaded_resources_and_use_total_capacity (1527-1627). Saves ~30 lines of code + ~33 lines of test, and removes a fourth copy of the "explicit limit removes implicit reserves" rule.

Also memory.rs:646-683 integrated_state recomputes exactly what the per-rank loop at 877-909 computes: min free over integrated ranks, min total, fixed_bytes(core, true) summed over integrated ranks, plus embedding_host_bytes, and initial[i].free - free observed drop. Building Vec<(MemorySnapshot, u64, u64)> once before host_budget_for and reusing it in the loop removes ~30 lines of duplicated tuples.

Total for memory.rs: ~60 lines of code, ~30 of test.

#9 [high] Should fix (~52 lines): headroom_with_inputs_for_budget and prepare_with_inputs_budget duplicate their neighbours

Verified: headroom_with_inputs (selene/src/offload.rs:117-146) now only computes a default host budget and delegates to headroom_with_inputs_for_budget (151-206). Its production callers: selene/src/offload.rs:612 (the None arm of prepare_with_inputs_budget), and helios/src/runtime_core/memory.rs always uses _for_budget (memory.rs:833). Every other caller is a test (selene/src/offload/tests.rs:179-698, ~13 sites).

Smaller version: one function headroom_with_inputs(..., host_budget: Option<u64>); at the top

let host_budget = match host_budget {
    Some(b) => b,
    None if capture.is_some() => host_pool_budget(0)?,
    None if memory != 0 || disk => host_pool_budget(memory)?,
    None => 0,
};

i.e. the body of 117-146 folded into 151-206 with the two variables already computed there (memory, disk, capture are re-derived in both). Saves 30 lines in offload.rs and the match host_budget { Some => ..., None => ... } block at 603-619 shrinks to one call, and the 13 test call sites get a trailing None.

Same shape in the prepare chain: prepare (484-495) -> prepare_with_inputs (497-520) -> prepare_with_inputs_budget (523-534) is three public functions with the last two differing only by host_budget: Option<u64>. Collapse prepare_with_inputs/prepare_with_inputs_budget into one (host_budget: Option<u64>), keeping prepare as the 3-line convenience: saves 22 lines in selene/src/offload.rs plus the parallel 20-line duplicate in helios/src/offload/mod.rs (see the helios note).

#10 [high] Totals: ~250-280 of 994 added lines removable

Total added lines: +994/−133 over 21 files (per orientation packet). Removal estimate by finding (code + test lines):

  1. memory.rs: integrated_offload_host_budget duplicates limited_budget; integrated_state duplicates the per-rank integrated loop — ~60 code + ~33 test = ~93
  2. selene/offload.rs twin budget functions (headroom_with_inputs_for_budget + prepare_with_inputs_budget + prepare_with_inputs ladder) — ~52
  3. twin try_ APIs around HOST_NUMA (registrar::try_map_split, slab::try_sized_by_rank, sized_by_rank, CudaRegistrar::try_map_split, UnsupportedSplitRegistrar test) — ~40
  4. helios/offload/mod.rs dead prepare + pass-through ladder — ~31
  5. cuda.rs dead map_device_host_parts + redundant early-returns + doc — ~20
  6. roce_proxy_dlopen.c dead iova2 + duplicate init guard — ~18
  7. host_pool_budget_with_reserve / apply_reserve flag — ~11
  8. eos map_host fallback loop (portability hedge) — ~15 (low confidence, keep)
  9. duplicated scaling tests across selene/helios, prepare_with_inputs_budget re-test — ~20
  10. release.yml python GLIBC heredoc — ~12 (nit)

Sum of confident cuts ≈ 250-280 lines of the 994 added (~26-28%).

Verdict: the three fixes are real and evidenced (CUDA 12 UVA fallback; glibc 2.35 + lazy libibverbs; scaled host reserve + THP ordering), but each was implemented by adding a try_/_for_budget/_with_reserve twin beside the existing function and keeping both, leaving one branch reachable only from tests. Smaller version: one function per seam taking Option<u64> / returning Result<Option<..>>, and the existing limited_budget reused for the integrated offload host budget.

#11 [high] Research summary

Reviewed PR #589 (21 files, +994/−133) strictly for subtraction. All changed files and the code they supersede were read; findings are in the scratchpad with file/line citations and line estimates.

The three defects fixed are real and evidenced, but almost every fix was implemented by adding a twin beside the existing function and keeping both: try_map_device_host_parts/map_device_host_parts, map_split/try_map_split, sized_by_rank/try_sized_by_rank, headroom_with_inputs/_for_budget, prepare_with_inputs/_budget, host_pool_budget/_with_reserve. In each pair one member is reachable only from tests, or differs by a single Option<u64>/apply_reserve argument that has one value in production. Two of those twins (map_split, map_device_host_parts) are dead in production because the only split allocation now goes through try_map_split.

Largest cuts, ranked: integrated_offload_host_budget in helios/src/runtime_core/memory.rs re-implements the existing limited_budget arm for arm, and integrated_state recomputes what the per-rank loop below it computes (~93 lines incl. tests); the selene offload budget/prepare ladder (~52); the HOST_NUMA twin APIs across selene/src/{registrar,slab}.rs and helios/src/offload/registrar.rs (~40); the dead prepare plus duplicate pass-through in helios/src/offload/mod.rs (~31); cuda.rs (~20); the dlopen shim's dead ibv_reg_mr_iova2 path and caller-guaranteed init guard (~18); the apply_reserve flag (~11). Total confident removal ≈ 250–280 of the 994 added lines (~27%), with no behaviour lost.

Should-fix, not blocking: the change is smaller than it looks once the twins are collapsed into one function per seam.

#12 [high] Coverage: files examined with no cut, and their nits

Coverage record so the report can say every changed file was examined, with the verdict for the ones that yielded no real subtraction:

No finding is blocking: nothing here is unnecessary to the stated defects, but ~27% of the added lines are twin functions or duplicated arithmetic that a single function per seam would replace.

#5 [medium] Should fix (~20 lines): cuda map_device_host_parts + repeated early-return blocks

helios/src/cuda.rs:667-676 map_device_host_parts is only called from CudaRegistrar::map_split (helios/src/offload/registrar.rs:28), which is only reached via the default try_map_split body, i.e. never in production (see twin-API note). Deleting it (10 lines incl. doc) loses nothing once map_split returns Option directly, or map_split becomes try_map_device_host_parts(requests)?.ok_or_else(...) inline (3 lines).

Similarly helios/src/cuda.rs:532-537 is_host_numa_unsupported — four call sites, all in the same function, each with the same 4-line "call, test, early-return Ok(None), then driver.check": the repeated 4-line block could instead be one closure/helper applied to the status, but the clearer cut is that the four separate checks are one check too many: the same error can only arrive from cuMemCreate/cuMemSetAccess after the earlier calls succeeded; the cuDeviceGetAttribute and cuMemGetAllocationGranularity checks (cuda.rs:577-590) are redundant with the cuMemCreate check because the properties are only accepted when the location type is supported (a driver without HOST_NUMA VMM fails at the allocation itself, and the granularity query for an unsupported location type returns the same NOT_SUPPORTED error checked at line 587). Confidence: medium — recommend keeping the status on cuMemCreate/cuMemSetAccess only. Saves ~10 lines.

Also helios/src/cuda.rs:539-547: the long doc block now has to explain the Option contract in addition to the mapping contract (6 extra lines) — can be cut to 2 lines pointing at the caller's fallback.

#7 [medium] Should fix (~18 lines): roce_proxy_dlopen.c dead iova2 path and duplicate init guard

helios/native/roce_proxy_dlopen.c:

  1. Lines 108-115 + 184-193 (reg_mr_iova2 field, the optional IBVERBS_1.8 load, and the #ifdef IBV_ACCESS_OPTIONAL_RANGE branch in flare_ibv_reg_mr): the vendored proxy calls ibv_reg_mr in exactly two places (helios/native/roce_proxy.c:443-444, 560-561) with IBV_ACCESS_LOCAL_WRITE | IBV_ACCESS_REMOTE_WRITE — never IBV_ACCESS_OPTIONAL_RANGE. So the whole iova2 path is dead: struct ibv_mr* (*reg_mr_iova2)(...) (1), the optional-load block (5), the ifdef branch (8) → the trampoline becomes return flare_ibv.reg_mr(pd, addr, length, (int)access);. ~14 lines.
  2. Lines 157-163 flare_ibv_get_device_list re-runs roce_ensure_libibverbs(NULL, 0) and sets errno = ENOSYS. The only Rust caller, RoceTransport::open (helios/src/execution/roce.rs:191-195), already calls roce_ensure_libibverbs and returns an install-hint error before roce_create; roce_create is the only route to this trampoline and is only called from that function. Drop the guard (3 lines + errno branch) and the trampoline is a one-line tail call like its 16 siblings.
  3. The 17 one-line trampolines are required (they must not export ibv_*), so they stay. Total ~18 lines of 236 removable with no behaviour change on the one calling path.

#8 [medium] Nit list: smaller verified cuts

assert-rejected-memory branch in the vendored proxy calls ibv_reg_mr in exactly two places (roce_proxy.c:443, 560), both with IBV_ACCESS_LOCAL_WRITE|IBV_ACCESS_REMOTE_WRITE. So reg_mr_iova2/IBVERBS_1.8 optional load (roce_proxy_dlopen.c:46, 108-113, 184-192) is dead: ~14 lines.

flare_ibv_get_device_list's roce_ensure_libibverbs(NULL,0) + errno=ENOSYS (roce_proxy_dlopen.c:157-163) is guaranteed by RoceTransport::open (execution/roce.rs:191-195) before roce_create: 4 lines.

Selene host_pool_budget_with_reserve (offload.rs:852-861): only production value is true (from host_pool_budget itself); host_pool_budget_from's apply_reserve (offload.rs:824-836) only ever true in production (selene:885, memory.rs:202). Drop the flag and the wrapper: ~9 lines + 2 test assertions.

Helios map_device_host_parts (cuda.rs:667-676): only caller is CudaRegistrar::map_split (offload/registrar.rs:28), which is only reachable through the default try_map_split body — dead in production: 10 lines.

Helios prepare + prepare_with_inputs (offload/mod.rs:72-103): prepare has no callers anywhere (only prepare_with_inputs at pool/tests.rs:124 and prepare_with_inputs_budget at runtime_core/model.rs:967): 31 lines.

eos::map_host (unix.rs:85-119): MADV_POPULATE_WRITE is Linux 5.14+; older kernels return EINVAL, so the page-stride write_volatile loop is the fallback. Since kernel 5.14 predates glibc 2.35 (Ubuntu 22.04's 5.15), the cfg(not(linux)) arm and the populated fallback in practice never run on a supported target. 15 lines, but this is a deliberate portability hedge; low.

release.yml (whole 128-line job diff): the docker-in-docker rebuild is the only way to get glibc 2.35 from a 24.04 runner without a container job; the ELF/glibc python check adds 12 lines on top of the uv--container run which already proves it (the 22.04 smoke run fails if GLIBC > 2.35 is required). Dropping the readelf --version-info python heredoc (~12 lines) loses nothing that the 22.04 container run doesn't already prove; readelf -d | grep libibverbs.so (~4 lines) is likewise proven by neither container having libibverbs1 — but --version and --help don't dlopen, so only the DT_NEEDED grep is redundant-in-part. Suggest removing the 12-line python block as nit.

Duplicated tests: selene/src/offload/tests.rs:705-724 (host_pool_budget_scales_small_socs...) and helios/src/runtime_core/memory.rs:1485-1489 + 1493-1525 (integrated_gpus_keep... last assertion, integrated_offload_host_budget_matches...) assert the same 64 MiB/16 GiB scaling rule three times across two crates (~20 redundant lines). selene/src/offload/tests.rs:727-780 prepare_with_inputs_budget_avoids_post_kv_alloc_shrinkage re-tests intake slot arithmetic already covered by 670-704; keep one.

docs: prefix-cache-offload.md and release.md now restate release.yml step by step (release.md:70-79 ~10 lines) — acceptable, docs are the point.