#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:
- helios/src/cuda.rs: try_map_device_host_parts + map_device_host_parts
- selene/src/registrar.rs: map_split + try_map_split
- selene/src/slab.rs: sized_by_rank + try_sized_by_rank
- selene/src/offload.rs: headroom_with_inputs + headroom_with_inputs_for_budget; prepare_with_inputs + prepare_with_inputs_budget
- helios/src/offload/mod.rs: prepare + prepare_with_inputs + prepare_with_inputs_budget (three pass-throughs)
- selene/src/offload.rs: host_pool_budget + host_pool_budget_with_reserve(future, apply_reserve) where the only in-repo call passes true.
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:
- Delete
sized_by_rank(10 lines, slab.rs:254-270): both callers can usetry_sized_by_rank(...)?.unwrap()orexpect(...)in tests /.ok_or_else(...)at the one call site. The doc comment block can move ontotry_sized_by_rank. - Delete
try_map_split(selene/src/registrar.rs:28-37, 10 lines) and instead makemap_splitreturnResult<Option<Box<dyn SplitMapping>>>, or better: keep one methodmap_splitreturningResult<Option<..>>. ThenCudaRegistrarkeeps only one impl (helios/src/offload/registrar.rs:27-38, saves 8 lines) and the delete ofmap_device_host_partsin cuda.rs (see separate note). TestUnsupportedSplitRegistrar(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:
- None:
host_pool_budget_from(free, total, future, true)==budget(free.min(total), total, 0, true, false)minusfuture(budget subtractshost_reserve_bytes(total)and, withexplicit_limit=false, no user headroom). - Reserve(r):
free.min(total) - r - future== limited_budget with headroom=r, explicit_limit=true. - Bytes/Fraction:
physical.min(cap - (loaded+future))== limited_budget'savailable.min(remaining)exactly.
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):
- memory.rs: integrated_offload_host_budget duplicates limited_budget; integrated_state duplicates the per-rank integrated loop — ~60 code + ~33 test = ~93
- selene/offload.rs twin budget functions (headroom_with_inputs_for_budget + prepare_with_inputs_budget + prepare_with_inputs ladder) — ~52
- 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
- helios/offload/mod.rs dead
prepare+ pass-through ladder — ~31 - cuda.rs dead map_device_host_parts + redundant early-returns + doc — ~20
- roce_proxy_dlopen.c dead iova2 + duplicate init guard — ~18
- host_pool_budget_with_reserve / apply_reserve flag — ~11
- eos map_host fallback loop (portability hedge) — ~15 (low confidence, keep)
- duplicated scaling tests across selene/helios, prepare_with_inputs_budget re-test — ~20
- 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:
- helios/build.rs (+2/−1): compiles roce_proxy_dlopen.c, links
dl+pthread, dropsibverbs. Exactly right; no cut. - helios/Cargo.toml, flare/Cargo.toml, flare-cli/Cargo.toml (+6/−6): comment-only edits. Nit: the aarch64 target comment and the feature comment both restate "loads libibverbs.so.1 lazily at run time" (3 copies of the same sentence across 3 manifests + docs). One clause would do; ~4 comment lines. Note
helios/Cargo.toml:28-29still says therdmafeature "links libibverbs" — stale after this change if the rdma path also stops hard-linking (selene/src/Cargo.toml:18rdma = ["dep:ibverbs-sys"], i.e. it still links); not a subtraction, just noting the sentence is now inconsistent with line 26. - helios/src/execution/roce.rs (+14/−4): the
roce_ensure_libibverbspreflight (191-195) is needed once per open; the 14-line test at 510-525 exercises both branches and is the only evidence the install hint works. Keep. Nit only: it reuses the samemessagebuffer thatroce_createthen overwrites, which is fine. - helios/src/runtime_core/model.rs (+10/−4): pure plumbing of
planned_offload_hostthroughallocate_caches->prepare_offload->prepare_with_inputs_budget. Required by the double-subtraction fix; no independent cut beyond theprepare_with_inputs_budgetmerge. - eos/src/unix.rs (+60/−1): the fix is 5 lines (MAP_POPULATE removed, MADV_HUGEPAGE kept); the rest is the
MADV_POPULATE_WRITEprobe + page-stride fallback (15) and a 44-line test whose /proc/self/smaps VMA-slicing logic is ~25 lines of nestedfind/position/takefor onehgflag assertion. Simpler test: read/proc/self/smapsand assert the block starting atformat!("{address:x}-")containsVmFlags:withhgbefore the next blank-line-terminated block — the current code computes byte offsets it never needs. Nit ~15 lines. - .github/workflows/release.yml (+54/−28): examined in full. Building in
ubuntu:22.04is the only way to get glibc 2.35 from a 24.04 runner without a container job, so the docker-in-docker step is not removable. Thereadelf --version-infopython heredoc (96-107, ~12 lines) asserts what theubuntu:22.04smoke run at 110-121 already proves (the binary would fail to start there), so it is redundant; theDT_NEEDEDgrep (92-95) is not, because--version/--helpnever callroce_ensure_libibverbs. Nit ~12 lines. - docs/release.md (+11/−7), docs/multi-host.md (+4/−4), docs/runtime-core-design.md (+2/−2), docs/prefix-cache-offload.md (+17/−7): accurate statements of the new behaviour; release.md now narrates release.yml step by step (~10 lines) but that is what the doc is for. No 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:
- Lines 108-115 + 184-193 (
reg_mr_iova2field, the optionalIBVERBS_1.8load, and the#ifdef IBV_ACCESS_OPTIONAL_RANGEbranch inflare_ibv_reg_mr): the vendored proxy callsibv_reg_mrin exactly two places (helios/native/roce_proxy.c:443-444, 560-561) withIBV_ACCESS_LOCAL_WRITE | IBV_ACCESS_REMOTE_WRITE— neverIBV_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 becomesreturn flare_ibv.reg_mr(pd, addr, length, (int)access);. ~14 lines. - Lines 157-163
flare_ibv_get_device_listre-runsroce_ensure_libibverbs(NULL, 0)and setserrno = ENOSYS. The only Rust caller,RoceTransport::open(helios/src/execution/roce.rs:191-195), already callsroce_ensure_libibverbsand returns an install-hint error beforeroce_create;roce_createis 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. - 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.