Subtraction, Simplicity & Conventions review — PR #699
Key findings
The diff is lean. I read all five changed files plus the surrounding code (selene/src/pool/{budget,budget/tests,builder,conn,shm,startup,mod}.rs, selene/src/offload.rs:880-1010, eos/src/{lib,unix}.rs, selene-manager/src/local.rs, helios/src/offload/pool*.rs, selene/Cargo.toml) and AGENTS.md. No new flag, config key, environment variable, dependency, protobuf field, or dead code is introduced; libc was already a Selene dependency; Budget::costs' changed signature has all three call sites updated (budget.rs:45-48, builder.rs:239-245, tests). Nothing is left behind from the old shape.
Four simplifications are worth making, all local and none structural:
conn.rs:774-780,conn.rs:854(high) — theshared_backed: Option<(u64, u64)>threading carries an unreachable tuple-pattern arm and a never-takenunwrap_or((0, 0)); a plain(u64, u64)local removes both and ~5 lines.budget.rs:19(high) —backed_bytes.min(bytes)insidebytes.saturating_sub(...)is a no-op; the clamp is already applied bybacked_shm_bytesatconn.rs:697.budget/tests.rs(medium) — the identicalplan.iter().map(|region| (region.bytes, region.backed_bytes))closure is written out five times; one module-local helper collapses it.budget/tests.rs:133-141(medium) — thehost: Err("no memory observation")assertion is a verbatim repeat of the pre-existing one atbudget/tests.rs:82-90and cannot be affected bybacked_bytes.
I explicitly considered and cleared two tempting findings: relocating backed_shm_bytes into flare-eos, and deleting the non-Linux stub. Reasons below.
1. (high) conn.rs — the Option threading of backed bytes has a dead arm and a dead default
selene/src/pool/conn.rs:773-780:
let mut plan = Vec::new();
let shared_backed = shared.map(|shared| {
(
backed_shm_bytes(&shared.arena_path, shared.arena_bytes),
backed_shm_bytes(&shared.staging_path, shared.staging_bytes),
)
});
if let (Some(shared), Some((arena_backed, staging_backed))) = (shared, shared_backed) {
and selene/src/pool/conn.rs:853-854:
if let Some(regions) = ®ions {
let (arena_backed, staging_backed) = shared_backed.unwrap_or((0, 0));
shared_backed is Some exactly when shared is Some, because it is shared.map(...) and shared is Option<&T> (which is Copy, so both uses see the same value). So:
- the second half of the pattern,
Some((arena_backed, staging_backed)), can never beNonewhen the first half matched — an unreachable branch that the reader has to prove dead; unwrap_or((0, 0))is never taken:regionsisSomeonly viashared.map(...)atconn.rs:813-829, soshared.is_some()there.
Replace the three pieces with one plain local, computed inside the if let that already builds the two PlannedRegions:
let mut backed = (0u64, 0u64);
if let Some(shared) = shared {
backed = (
backed_shm_bytes(&shared.arena_path, shared.arena_bytes),
backed_shm_bytes(&shared.staging_path, shared.staging_bytes),
);
plan.extend([ /* the two PlannedRegion entries, unchanged, conn.rs:781-792 */ ]);
}
and at conn.rs:854:
let (arena_backed, staging_backed) = backed;
Net: removes one Option binding, one two-Some pattern, and one dead default; about five lines shorter, and the "backed values belong to the shared file pair" invariant stops being expressible in two shapes. Convention tie-in: AGENTS.md:188-193 rejects "fallback layers" and "unsupported abstractions… without a concrete requirement"; here the Option and its default are exactly a fallback that no input can reach.
2. (high) budget.rs:19 — the .min(bytes) clamp is redundant twice over
selene/src/pool/budget.rs:18-19:
regions.try_fold((0u64, 0u64), |(host, device), (bytes, backed_bytes)| {
let additional_host = bytes.saturating_sub(backed_bytes.min(bytes));
u64::saturating_sub already floors at zero, so backed_bytes.min(bytes) changes nothing:
backed <= bytes: both forms givebytes - backed;backed > bytes:mingives0, andsaturating_subalso gives0.
The clamp is also already enforced at the only production producer, selene/src/pool/conn.rs:697:
.map(|meta| meta.blocks().saturating_mul(512).min(declared_bytes))
Replace with:
let additional_host = bytes.saturating_sub(backed_bytes);
One expression, one mechanism to reason about; the hostile-input case is still safe. Knock-on to fix at the same time — selene/src/pool/budget/tests.rs:155:
bytes: 4 << 20,
backed_bytes: 8 << 20, // clamped to region.bytes
The comment names a clamp that, after the simplification, is doing no work; retarget it at saturating_sub ("backed beyond the region still charges zero"). The assertion at budget/tests.rs:168 (assert_eq!(host, 6 << 20);) passes unchanged either way.
3. (medium) budget/tests.rs — the (bytes, backed_bytes) mapping is duplicated five times
The same four-line closure appears at selene/src/pool/budget/tests.rs:25, :48-52, :65, :109-113, :163-167. Two of the five, verbatim:
// tests.rs:25
let (host, device) = Budget::costs(plan.iter().map(|region| (region.bytes, region.backed_bytes))).unwrap();
// tests.rs:109-113
let (host, device) = Budget::costs(
plan.iter()
.map(|region| (region.bytes, region.backed_bytes)),
)
.unwrap();
Every test in the module wants (host, device) from a plan, so the mapping is a fixture concern, not test logic. Add one module-local helper next to plan() at tests.rs:7:
fn costs(plan: &[PlannedRegion]) -> std::result::Result<(u64, u64), String> {
Budget::costs(plan.iter().map(|region| (region.bytes, region.backed_bytes)))
}
then let (host, device) = costs(&plan).unwrap(); at the four value sites and assert!(costs(&self::plan(u64::MAX, 1)).is_err()); at tests.rs:47-54. Saves roughly eight lines and, more importantly, keeps the pairing of bytes with backed_bytes in one place so a future field addition to PlannedRegion is a one-line test change rather than five.
Related formatting point, low priority: cargo fmt was not run on the head commit — tests.rs:25 is 106 columns and tests.rs:65 about 100, over rustfmt's 100-column width — and there is no CI check on 135633f to catch it. Trivial, but the reflow disappears for free with the helper.
4. (medium) budget/tests.rs:133-141 — duplicated host: Err assertion adds nothing
The tail of the new test, selene/src/pool/budget/tests.rs:133-141:
assert!(
Budget {
host: Err("no memory observation".into()),
devices: vec![(device, false)],
}
.approve(&plan)
.unwrap_err()
.contains("no memory observation")
);
is a verbatim repeat of the pre-existing assertion at selene/src/pool/budget/tests.rs:82-90 (same host: Err, same message, same .contains). It also cannot be affected by this PR's variable: Budget::approve reads self.host and returns the error at budget.rs:49-52 before any cost comparison, so backed_bytes never enters. Delete the block (~9 lines). Keep the sibling assertion at tests.rs:124-132 (GPU shortfall with host: Ok(25 GiB) below the 40 GiB pool): that one is new information, because it proves the zeroed host charge let the device charge be reached at all.
Reviewer note, not a deletion (out of this lens): tests.rs:123 assert_eq!(budget.charges(host, device), vec![device, device]); only restates host == 0 through charges, but it does pin the integrated-device consequence of budget.rs:30-42 (host.div_ceil(integrated)); it should be read as a statement of intent for unified-memory hosts rather than as coverage of new logic.
Considered and deliberately not reported
- Moving
backed_shm_bytesintoflare-eos.AGENTS.md:20-21does say "Theeos/crate holds the host operating-system operations that Helios and Selene use", so this looked like a convention violation. It is not: Selene already calls libc directly for crate-internal work (selene/src/pool/shm.rs:144-150libc::munmap;selene/src/testing.rs:431(not opened)libc::EINVAL), eos exposes nostatfs/TMPFS_MAGICsurface today (onlystatvfsineos/src/unix.rs:792-809), and exporting a single-caller helper would be precisely the "speculative generality" this lens is supposed to remove. Keep it local. - Deleting the
#[cfg(not(target_os = "linux"))]stub (conn.rs:701-704). Required, not speculative: Selene builds on Windows (selene/Cargo.tomlwindows-sys deps; see merged PR #171) and on macOS, wherelibc::TMPFS_MAGICdoes not exist. Removing it breaks those builds. - The extra
registered_regionparameter (conn.rs:706-717). Load-bearing forPreparedPool::registration_costs(builder.rs:239-245), which recomputes costs from registered regions; aDefaultwould not let it be dropped. Not removable without a larger redesign, which is out of scope for a memory-budget fix. registration_costsmapping atbuilder.rs:239-245. It is a one-linemapover the same tuple shape asBudget::costs; collapsing it intocostswould be possible but saves nothing meaningful and would hide thatregion.bytesisusizethere (as u64cast).- Documentation drift (
docs/cli-design.md:891(not opened),docs/runtime-core-design.md:768(not opened),helios/src/frontend/mod.rs:1400-1402(not opened)) — a documentation-scope gap, not a subtraction finding. - No new flags, knobs, env vars, deps, or protobuf fields exist in the diff to subtract.
AGENTS.md:452-455(no environment-selected behavior) is satisfied.
Open questions
- Whether the pool-budget exemption is the intended layer at all, versus teaching
host_pool_budget(selene/src/offload.rs:923-985) about tmpfs. That is a design question for the Correctness lens and the area owner (yatesdr), not a simplicity one — but if the maintainer decides the exemption belongs higher, findings 1-4 become moot because the diff shrinks to nothing in these files. - Whether the zeroed host charge on unified-memory hosts is intended;
budget.rs:30-42andtests.rs:123make the per-GPU charge shrink, which is a behaviour statement the description does not make. - No maintainer reaction of any kind exists on #699 (0 reviews, 0 comments, no labels, no CI on
135633f), so there is no signal on whether the reviewers would prefer the simplified forms above or consider them churn underAGENTS.md:188-193. - I could not date the surrounding code:
search_historyfails onselene/srcwithgit: error: Could not read c513e46…, so authorship/recency ofconn.rs/budget.rscame from the merged-PR record (allyatesdr) rather than commit history.