Recommendation: Changes Requested
The core diagnosis and architectural placement are sound: on Linux, selene-manager preallocates /dev/shm/selene/<name>-<hash>/{arena,staging} via libc::fallocate (selene-manager/src/local.rs:583-602), which immediately deducts those pages from /proc/meminfo MemAvailable, causing Budget::approve (selene/src/pool/budget.rs:44-72) to double-count them against host RAM and integrated-GPU KV cache capacity. However, the PR cannot merge as-is because it breaks three existing Linux CI integration tests across selene-manager and helios that run against real /dev/shm tmpfs managers, and the new backed_shm_bytes syscall path has no direct test coverage or CI run on head 135633f.
Merge Risk
Level: Medium
- Blast radius: Changes startup admission accounting (
Budget::costs,register_memory,PreparedPool::registration_costs) for bothPoolClient(selene/src/pool/conn.rs:643) and peerRankAgent(selene/src/pool/agent.rs:611) whenever attaching to a local Linuxselene-manageron tmpfs/dev/shm. Steady-state serving hot paths, wire protocol, and non-Linux builds are unaffected (runs once at startup insidetokio::task::spawn_blocking). - Immediate CI breakage: No CI checks have run on
135633f, and the author only rancargo test -p flare-selene pool::budget; three existing integration tests in.github/workflows/native-serving.yml(not opened) (selene-managerandheliossuites onubuntu-24.04) will fail immediately because they passhost: Ok(0)orhost: Ok(1)against a live/dev/shmManager. - Swap caveat: On Linux hosts with swap enabled,
st_blocks * 512still counts swapped-out tmpfs pages that are no longer deducted fromMemAvailable, whereascuMemHostRegister_v2(helios/src/cuda.rs:471) pins and faults them back into RAM.
Walkthrough
selene/src/pool/startup.rs:21-46: Addspub backed_bytes: u64toRegisteredRegionandPlannedRegionto separate already-backed shared-memory bytes from newly required host RAM.selene/src/pool/conn.rs:678-704: Adds Linux-onlybacked_shm_bytes(path, declared_bytes), verifyinglibc::TMPFS_MAGICvialibc::statfsand returningmetadata.blocks().saturating_mul(512).min(declared_bytes)(failing closed to0on errors, non-tmpfs, or non-Linux targets).selene/src/pool/conn.rs:774-864: Populatesbacked_bytesfrombacked_shm_bytesfor localarenaandstagingplanned/registered regions, and0for anonymous remotedata-staging.selene/src/pool/budget.rs:15-48&selene/src/pool/builder.rs:239-245: UpdatesBudget::costsandPreparedPool::registration_coststo accept(bytes, backed_bytes), charging host memory only forbytes.saturating_sub(backed_bytes.min(bytes))while keeping fullbytes.div_ceil(512)per-GPU registration metadata charges andself.hosterror propagation.selene/src/pool/budget/tests.rs:93-187: Updates existingPlannedRegionfixtures withbacked_bytes: 0and adds two unit tests for fully and partially backed regions.
Pre-merge Checks
- [PASS] Security / malicious screen: No suspicious code, no new dependencies, no prompt-injection or credential/network anomalies;
backed_shm_bytesfails closed to0on invalid paths or syscall errors. - [PASS] Charter & value fit: Directly serves the charter goal of sharing prefix-cache checkpoints via Selene without adding flags, dependencies, or model-specific logic, and lands at the right architectural layer (
PlannedRegion/Budget::costsafterHelloreveals local vs. remote regions). - [WARN] Related / duplicate / conflict check: Clean against
main(no duplicate fix), but large open PR #674 by the area owner (yatesdr) also touchesselene/src/pool/conn.rsandselene/src/pool/builder.rs; coordinate merge ordering. - [WARN] Tests & verification evidence: No CI run on
135633f; author validation ran onlycargo test -p flare-selene pool::budget, missing three broken integration tests inselene-manager/heliosand leavingbacked_shm_bytesunexecuted by any test.
Blockers
- Breaks three existing Linux CI integration tests that attach to a real
/dev/shmtmpfs manager- Where:
selene-manager/tests/builder.rs:79-115(over_budget_startup_fails_before_registering_memory)selene-manager/tests/offload.rs:13-71(startup_fails_and_releases_registration_when_a_rank_rejects_the_pool)helios/src/offload/pool/tests.rs:20-92(peer_registration_budget_fails_startup)
- Verified behavior & impact: All three tests run in
.github/workflows/native-serving.yml:48-63(not opened) onubuntu-24.04(where/dev/shmis tmpfs) and spawnselene_manager::testing::Manager::new(), which createsfallocatedarenaandstagingfiles under/dev/shm/selene(selene-manager/src/local.rs:26,125,583-602). With this PR,backed_shm_bytesreturns fullarena_bytes/staging_bytes, makingBudget::costscomputehost == 0:- In
selene-manager/tests/builder.rs:83-112, the first subcase (Budget { host: Ok(0), devices: [(u64::MAX, false)] }) now succeeds (0 <= 0) instead of failing, panicking at.expect("an unapproved pool must fail startup")(builder.rs:101). The second subcase (devices: [(1, false)]) fails the assertionassert!(reason.contains("needs 16777216 host bytes"))(builder.rs:106) becauseBudget::approvenow formats"needs 0 host bytes". - In
selene-manager/tests/offload.rs:34-64, thelocal_approved == falseiteration passesBudget { host: Ok(0), devices: vec![(u64::MAX, false), (u64::MAX, true)] }. Becausehost == 0 <= 0, local registration is approved instead of rejected, panicking atassert_eq!(approved, local_approved)(offload.rs:44) and registering 2 regions instead of 0. - In
helios/src/offload/pool/tests.rs:46-90,rejection == 0passesBudget { host: Ok(1), devices: [(u64::MAX, false)] }to a peerRankAgent, which also runsconn::register_memory_blocking(selene/src/pool/agent.rs:611). Withhost == 0 <= 1, the peer attaches instead of rejecting, panicking atresult.err().expect("an unapproved peer must fail startup")(helios/src/offload/pool/tests.rs:88).
- In
- Fix: Update all three tests for the new preallocated-tmpfs contract (e.g., use a TCP/remote manager whose anonymous
data-staginghasbacked_bytes == 0when testing host-budget rejection, or assert device-budget rejection with"needs 0 host bytes"on local tmpfs while explicitly asserting thathost: Ok(0)approves a preallocated local tmpfs pool). Run the full Linux test commands from.github/workflows/native-serving.yml:51-63(not opened):cargo test --locked --release --manifest-path selene/Cargo.toml (not opened) --features test-support cargo test --locked --release --manifest-path selene-manager/Cargo.toml (not opened) --features test-support cargo test --locked --release --manifest-path helios/Cargo.toml (not opened) --features runtime-core,server
- Where:
Should Fix
- Add direct test coverage for
backed_shm_bytesand theregister_memory→Budgetintegration path- Where:
selene/src/pool/conn.rs:682-704,selene/src/pool/budget/tests.rs:93-187 - Verified behavior & impact: The two new tests in
selene/src/pool/budget/tests.rshand-constructPlannedRegionvalues and only testBudgetarithmetic; nothing directly testsbacked_shm_bytes(tmpfs magic check,st_blocks * 512calculation, clamp todeclared_bytes, sparse/unallocated file, non-tmpfs fallback to0, missing/NUL path fallback to0) or asserts the resultingbacked_bytes/chargesthrough a realManager. - Fix: Add Linux unit tests in
selene/src/pool/conn.rs(undermod tests) coveringbacked_shm_byteson afallocated file in/dev/shm(guarded or checked for tmpfs), a sparse file (set_lenwithoutfallocate), a non-tmpfs path (returns0), and missing/NUL paths (returns0), alongside the updated live-manager integration tests inselene-manager/tests/builder.rsasserting that a preallocated local pool approves withhost: Ok(0)and still rejects insufficient GPU budget.
- Where:
Subtract / Simplify
- Remove redundant
Optionthreading and unreachable default forshared_backed(selene/src/pool/conn.rs:774-780, 853-855)shared_backedisshared.map(...), soSomeiffsharedisSome(andregionsisSomeiffsharedisSomevia lines 813-829). Computinglet mut shared_backed = (0u64, 0u64);insideif let Some(shared) = shared { ... }removes the double-Sometuple match at line 780 and the dead.unwrap_or((0, 0))at line 854.
- Drop redundant
.min(bytes)insidesaturating_sub(selene/src/pool/budget.rs:19)bytes.saturating_sub(backed_bytes)is identical tobytes.saturating_sub(backed_bytes.min(bytes))for allu64values (andbacked_shm_bytesalready clamps atconn.rs:697). Update the comment atselene/src/pool/budget/tests.rs:155accordingly.
- Deduplicate the
(bytes, backed_bytes)mapping inselene/src/pool/budget/tests.rs:25, 48-52, 65, 109-113, 163-167- The identical
plan.iter().map(|region| (region.bytes, region.backed_bytes))closure is repeated five times (and lines 25 and 65 exceed 100 columns / rustfmt formatting). Extract a small helperfn costs(plan: &[PlannedRegion]) -> std::result::Result<(u64, u64), String>next tofn plan(...).
- The identical
Nits
- Reconcile startup progress summary with registered-bytes log (
selene/src/pool/builder.rs:246-249,selene/src/pool/conn.rs:865-870):conn.rs:866printsregistered 40.0 GiB of pool memorywhilePreparedPool::summary()(printed byhelios/src/offload/pool.rs:20-22) will now print0 host bytes · 83886080 device bytes per GPUfor a preallocated local pool. Mentioning backed/additional bytes insummary()(e.g.,0 additional host bytes) avoids operator confusion. - Single-fd
fstatfs+metadataand swap note (selene/src/pool/conn.rs:682-699): Openingpathonce and callinglibc::fstatfs(file.as_raw_fd(), &mut statfs)+file.metadata()avoids two separate path lookups (statfs(path)thenmetadata(path)). Worth noting in the doc comment that on swap-enabled hosts,st_blocksstill includes swapped-out tmpfs pages thatcuMemHostRegister_v2(helios/src/cuda.rs:471) will fault back into RAM. - Note the
PlannedRegion/RegisteredRegionstruct field addition in the PR body (selene/src/pool/startup.rs:21-46, re-exported atselene/src/pool/mod.rs:60): Acceptable for an unpublished workspace crate with all in-tree call sites updated, just worth mentioning clearly.
Dropped on verification
- Dropped upstream claim ("No in-tree caller or integration test for the approval path"): False.
helios/src/offload/pool.rs:21callsstartup.start_pool,helios/src/runtime_core/memory.rs:986-1028constructsPoolBuilderand consumescharges, and three in-tree integration tests (selene-manager/tests/builder.rs,selene-manager/tests/offload.rs,helios/src/offload/pool/tests.rs) exercise the real approval path againstManager(and break under this PR). - Dropped upstream Major claim ("Zeroing host bytes removes
arena + stagingfrom integrated/unified GPU physical budgets and contradictsdocs/runtime-core-design.md/docs/cli-design.md"): False. Tracinghelios/src/runtime_core/memory.rs:236-238, 649-653, 888-939, 1022-1027confirms that on Linux integrated GPUs,availableis already computed from LinuxMemAvailable, which already excludes preallocated/dev/shmtmpfs. Before PR #699,Budget::chargessubtractedarena + staginga second time from integrated-GPU KV cache capacity; zeroinghostrestores accurate single-counting (and explicit--memory-limitstill remains capped by physicalMemAvailablevialimited_budgetatmemory.rs:280-297). - Dropped upstream layer concern ("Should
host_pool_budgetinselene/src/offload.rs:923-985be changed instead?"): Incorrect layer.host_pool_budgetruns before connecting toselene-manager(beforeHelloreveals whether the pool is local tmpfs or remotedata-stagingand its region sizes) and also sizes new local allocations (intake,capture_growth). Discounting already-backed shared regions inPlannedRegion/Budget::costsis the right layer. - Dropped upstream Major claim ("Pre-map
backed_shm_byteslets a stale/larger file bypass approval and fail atRegions::mapwith a worse error"): Speculative and mathematically invalid for a smaller file (st_blocks * 512on tmpfs cannot exceed page-roundedst_size). Approval is contracted to run before registration (selene/src/pool/startup.rs:35,selene-manager/tests/client.rs:1227), and a manager recreating regions mid-attach legitimately fails atRegions::map. - Dropped upstream Major claim ("Tmpfs
st_blocksis a reclaimable kernel estimate; retain an arbitrary charged fraction as margin"): Overstated on Linux semantics. Linux places tmpfs (Shmem) on the anonymous LRU rather than clean file page cache, soMemAvailabledoes not treat tmpfs as reclaimable;host_pool_budgetalready deductshost_reserve_bytes, andcuMemHostRegister_v2pins the mapped range at startup. Charging an arbitrary fraction would introduce a magic constant and re-introduce double-counting. (The narrower swap-enabledst_blocksnuance is logged under Merge Risk and Nits.) - Downgraded upstream Major claim ("Undeclared public source break on
PlannedRegion/RegisteredRegion"): Downgraded to a Nit becauseflare-seleneis an unpublished workspace crate (Charter Roadmap #6) and all in-tree call sites are updated. - Dropped upstream subtraction claim ("Delete duplicated
host: Errassertion atselene/src/pool/budget/tests.rs:133-141"): Kept. Unlike lines 82-90 (wherehost == 4097 > 0), lines 133-141 exercisehost == 0and guard against a naiveif host > 0short-circuit bypassingself.hosterror propagation.