Key findings
The three defects are real and the fixes are evidenced, but almost every seam was fixed by adding a twin next to the existing function and keeping both. In each pair one member differs by a single Option<u64> / bool argument that has one value in production, or is reachable only from tests. Collapsing the twins into one function per seam is where the numbers are: about 250–280 of the 994 added lines (~27%) can go with no behaviour change.
Nothing is blocking — every changed file was read against its surrounding code, and no part of the change is unrelated to a stated defect. The verdict is "make it smaller first" because ~27% of it is duplicated arithmetic and pass-through.
Ranked by lines saved:
helios/src/runtime_core/memory.rs—integrated_offload_host_budgetduplicateslimited_budget;integrated_stateduplicates the per-rank loop — ~93 lines (incl. tests)selene/src/offload.rs—headroom_with_inputs/_for_budget,prepare_with_inputs/_budget— ~52- HOST_NUMA
try_twins acrossselene/src/{registrar,slab}.rs,helios/src/offload/registrar.rs,helios/src/cuda.rs— ~40 helios/src/offload/mod.rs— deadprepare+ duplicate pass-through ladder — ~31helios/src/cuda.rs— deadmap_device_host_parts+ repeated early-return blocks — ~20helios/native/roce_proxy_dlopen.c— dead iova2 path + caller-guaranteed init guard — ~18selene/src/offload.rs:852-861—host_pool_budget_with_reserveand theapply_reserveflag — ~11- Nits across
eos/src/unix.rs,.github/workflows/release.yml(not opened), tests, manifests — ~45 (mostly keep)
1. Should fix (~93 lines): helios/src/runtime_core/memory.rs re-implements limited_budget and its own per-rank loop
integrated_offload_host_budget, memory.rs:192-221 is limited_budget (same file, 267-298) arm for arm:
Nonearm →host_pool_budget_from(free, total, future, true)=budget(free.min(total), total, headroom, integrated, false) - futurewhenheadroomis 0, i.e. exactlylimited_budget(.., default_headroom = 0, integrated = true, future); both subtracthost_reserve_bytes(total)(selene/src/offload.rs:818-820) and nothing else.Reserve(r)arm →free.min(total) - r - future=limited_budgetwithdefault_headroom = r,limit.is_some() == true.Bytes/Fractionarm →physical.min(cap - (loaded + future))=limited_budget'savailable.min(remaining)exactly.
Smaller version: delete the 30-line function and call the existing one at the two use sites (memory.rs:833 and the plan path):
let host_budget_for = |future: u64| {
limited_budget(memory, loaded, options.memory_limit, 0, true, future)
};
The only behavioural delta is that limited_budget returns the established "memory limit is N bytes, but loaded model resources require M" error instead of silently saturating to 0 when loaded + future exceeds an explicit cap — the behaviour of every other budget in the file, and the pre-existing contract. Nothing is lost; a fourth copy of the "explicit limit removes implicit reserves" rule disappears.
Its test, integrated_offload_host_budget_matches_small_soc_scaling_and_explicit_limits (memory.rs:1493-1525, ~33 lines), then folds into occupied_limits_include_loaded_resources_and_use_total_capacity (1527-1627), which already covers the same arms through limited_budget.
integrated_state, memory.rs:646-683 recomputes 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 the observed initial[i].free - free drop. Building Vec<(MemorySnapshot, u64, u64)> once before host_budget_for and reusing it in the loop removes ~30 lines of duplicated tuple plumbing.
2. Should fix (~52 lines): selene/src/offload.rs budget and prepare ladders
headroom_with_inputs (offload.rs:117-146) now only derives a default host budget and delegates to headroom_with_inputs_for_budget (151-206), re-deriving memory/disk/capture that the callee computes again. Its production callers are just offload.rs:612 (the None arm of prepare_with_inputs_budget) and every other site is a test (selene/src/offload/tests.rs:179, 194, 206, 209, 214, 215, 223, 377, 383, 392, 397, 404, 434, 524, 698). helios/src/runtime_core/memory.rs:833 already uses only the _for_budget form.
Smaller version — one function with the default folded in at the top of the existing body:
pub fn headroom_with_inputs(&self, ..., host_budget: Option<u64>) -> Result<(u64, u64)> {
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,
};
// ... rest of the current _for_budget body
}
Saves ~30 lines, and the match host_budget { Some(..) => .., None => .. } block at offload.rs:603-619 shrinks to one call; the 15 test call sites gain a trailing None.
Same shape one screen down: prepare (484-495) → prepare_with_inputs (497-520) → prepare_with_inputs_budget (523-534) are three public functions where the last two differ only by host_budget: Option<u64>. Merge them into one (host_budget: Option<u64>), keep prepare as the 3-line convenience: ~22 lines.
3. Should fix (~40 lines): the HOST_NUMA try_ twins
The change adds a fallible twin at each of four places and keeps the infallible one:
HostRegistrar::try_map_split(selene/src/registrar.rs:32-37) — its default body is the only production caller ofmap_split, and the only override in the tree that does anything isCudaRegistrar(helios/src/offload/registrar.rs:27-38). Every other impl returns an error or is test-only: selene/src/pool/builder.rs:295 (not opened), selene/src/testing.rs:449 (not opened)/477, selene/src/pool/startup.rs:211 (not opened), selene/src/pool/net.rs:972 (not opened), selene/src/pool/engine/net_tests.rs:40 (not opened), selene/src/pool/engine/tests.rs:151 (not opened), selene-manager/tests/client.rs:1289/3138, selene/src/offload/tests.rs:790.SlabPool::sized_by_rank(selene/src/slab.rs:261-270) is now a wrapper overtry_sized_by_rank(191-...) whose only callers are helios/src/offload/transfer.rs:1723 (test) and selene/src/slab.rs:631 (test); production goes throughtry_sized_by_rankat selene/src/offload.rs:631.cuda::map_device_host_parts(helios/src/cuda.rs:667-676) is called only fromCudaRegistrar::map_split(offload/registrar.rs:28), which is only reachable from the defaulttry_map_splitbody.
Smaller version: one method per seam returning Result<Option<T>> — map_split, sized_by_rank, map_device_host_parts — with the None documented once. Saves ~30 lines across the four files, plus ~12 in UnsupportedSplitRegistrar (selene/src/offload/tests.rs:790-813, ~24 lines) which shrinks to a single method. Nothing is lost: the fallback decision stays at the one call site (selene/src/offload.rs:631) that needs it.
4. Should fix (~31 lines): helios/src/offload/mod.rs:72-103
pub fn prepare (72-80) has no caller anywhere in the tree; prepare_with_inputs (82-103) is a 22-line pass-through that pins host_budget = None. Callers: prepare_with_inputs_budget from helios/src/runtime_core/model.rs:967, and prepare_with_inputs from helios/src/offload/pool/tests.rs:124 — nothing else.
Delete prepare; delete prepare_with_inputs and pass None at pool/tests.rs:124 (one extra argument). Saves ~31 lines with no caller lost.
5. Should fix (~20 lines): helios/src/cuda.rs redundant HOST_NUMA checks and dead twin
After removing map_device_host_parts (finding 3), the remaining waste is the four separate is_host_numa_unsupported early-returns in the mapping path (cuda.rs:532-537 helper, four call sites inside the same function). The cuDeviceGetAttribute and cuMemGetAllocationGranularity checks (cuda.rs:577-590) are redundant with the cuMemCreate check: a driver without HOST_NUMA VMM fails at the allocation with the same CUDA_ERROR_INVALID_VALUE (1) / CUDA_ERROR_NOT_SUPPORTED (801) pair, and the granularity query for an unsupported location type returns that same NOT_SUPPORTED. Keeping the status check on cuMemCreate/cuMemSetAccess only saves ~10 lines and one 6-line doc block (cuda.rs:539-547) that currently explains the Option contract twice. (Medium confidence — this is the one cut that touches driver-error assumptions rather than pure duplication.)
6. Should fix (~18 lines): helios/native/roce_proxy_dlopen.c
- Lines 108-115, 184-193 plus the struct field at 46: the
ibv_reg_mr_iova2field and the optionalIBVERBS_1.8dlvsym. The vendored proxy callsibv_reg_mrin exactly two places (helios/native/roce_proxy.c:443-444 and 560-561) withIBV_ACCESS_LOCAL_WRITE | IBV_ACCESS_REMOTE_WRITEand neverIBV_ACCESS_OPTIONAL_RANGE, so the#ifdefbranch that routes to iova2 is unreachable. 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), has already calledroce_ensure_libibverbsand returned an install-hint error beforeroce_create, androce_createis the only route to this trampoline. Drop it and the function is a one-line tail call like its 16 siblings — ~4 lines.
The 17 one-line trampolines must stay (they exist so no ibv_* symbol is exported).
7. Should fix (~11 lines): apply_reserve has one value in production
host_pool_budget_with_reserve(future, apply_reserve) (selene/src/offload.rs:852-861 → 858-886) is called from exactly one non-test place, host_pool_budget (line 853), with true; host_pool_budget_from(available, total, future, apply_reserve) (824-836) is called only with true (offload.rs:885 and helios/src/runtime_core/memory.rs:202-207). Only two test assertions pass false (selene/src/offload/tests.rs:722-723) to exercise the flag.
Smaller version — delete the wrapper and the parameter, hardcode the reserve:
pub fn host_pool_budget_from(available: u64, total: u64, future: u64) -> u64 {
available.saturating_sub(future).saturating_sub(host_reserve_bytes(total))
}
Saves ~9 lines of code plus 2 test assertions, with 3 call sites updated. Every production caller applies the reserve, so nothing is lost; when the explicit-limit case needs no reserve it already goes through limited_budget's explicit_limit argument.
8. Nits (~45 lines, most of them keepers)
.github/workflows/release.yml:96-107(not opened) — thereadelf --version-infopython heredoc (~12 lines) asserts what theubuntu:22.04clean-container smoke run at 110-121 already proves: a binary needingGLIBC_2.36+cannot start there. TheDT_NEEDED | grep libibverbs.soat 92-95 is not redundant (--version/--helpnever callroce_ensure_libibverbs), so keep it. ~12 lines.eos/src/unix.rs:85-119— the fix itself is 5 lines (dropMAP_POPULATE,madvise(MADV_HUGEPAGE)first); theMADV_POPULATE_WRITEprobe + page-stridewrite_volatilefallback (~15 lines) is a deliberate portability hedge (Linux ≥5.14; Ubuntu 22.04 ships 5.15), so keep. The test's /proc/self/smaps VMA-slicing (~25 lines of nestedfind/position/take) computes byte offsets it never uses; asserting the block starting atformat!("{address:x}-")containshginVmFlags:is enough: ~15 lines.- Duplicated scaling assertions — the 64 MiB / 16 GiB rule is asserted three times: selene/src/offload/tests.rs:705-724, helios/src/runtime_core/memory.rs:1485-1489 and 1493-1525. The helios copy disappears with finding 1; the selene copy stays.
selene/src/offload/tests.rs:727-780(prepare_with_inputs_budget_avoids_post_kv_alloc_shrinkage) re-tests intake-slot arithmetic already covered at 670-704 — keep one. ~20 lines. helios/Cargo.toml,flare/Cargo.toml,flare-cli/Cargo.toml— comment-only edits; the sentence "loads libibverbs.so.1 lazily at run time" now appears three times across the manifests plus docs. One clause would do: ~4 comment lines. Separately,helios/Cargo.toml:28-29still says therdmafeature "links libibverbs", which reads inconsistently with the new build.rs (therocepath no longer does).- Docs (
release.md:70-79~10 lines,multi-host.md,runtime-core-design.md,prefix-cache-offload.md) — accurate statements of new behaviour;release.mdnarratesrelease.ymlstep by step, but that is what a release doc is for. No subtraction.
Left behind (code the change supersedes and should remove in the same change)
helios/src/offload/mod.rs:72-80—prepare, no callers.helios/src/cuda.rs:667-676—map_device_host_parts, no production caller.selene/src/slab.rs:261-270—sized_by_rank, test callers only.selene/src/offload/tests.rs:790-813—UnsupportedSplitRegistrarexists only to exercise thetry_twin.selene/src/offload.rs:484-495—prepare(selene's own three-argument convenience) has no in-repo caller; searchedoffload::prepare(across the tree and found none. Caveat: it is public crate API offlare_selene, so if it is meant for out-of-tree users that is a deliberate export — worth a decision rather than an automatic cut.selene/src/offload.rs:852-861—host_pool_budget_with_reserve, production caller set of size one.
Open questions / not verified
- Finding 5 rests on assuming a driver without HOST_NUMA VMM fails at
cuMemCreaterather than at the earlier attribute/granularity queries; no such driver was reachable here (GA10B/WDDM were explicitly untested in the PR: "Unrun checks: Nativeaarch64build ... live GPU tests on discrete CUDA 12.x / Jetson Orin GA10B / Windows WDDM"). If the earlier queries can fail first, keep one of the two remaining checks and drop only the other (~5 lines). - The
eosprefault fallback's real hit rate on supported kernels is unmeasured; kept as a hedge rather than a subtraction. - Not examined for subtraction:
helios/src/runtime_core/model.rs+10/−4 andhelios/src/execution/roce.rs+14/−4 (both are required plumbing for the budget passthrough and the install hint; their only waste is theprepare_with_inputs_budgetmerge already counted in findings 2 and 4).