Case file: PR #699 — Avoid double-counting preallocated /dev/shm selene-manager regions against Linux MemAvailable
Open, "ready for review", base main, head 135633f, 5 files, +175/−12, no labels, no reviews, no comments, no CI checks on the head commit; opened and last updated 2026-12-02. Author ebfio, GitHub association FIRST_TIME_CONTRIBUTOR.
https://github.com/NVIDIA/hyperflare-inference/pull/699
Key findings (what a reader cannot learn from the description)
- The fix is correct about the manager's preallocation but wrong about where the double count lives at the top. This is a correction to my earlier working note:
selene-managerreally does preallocate withlibc::fallocate, verified inselene-manager/src/local.rs:582-602(create_region:O_NOFOLLOW|O_CLOEXEC,fchmod 0660,libc::fallocate(file.as_raw_fd(), 0, 0, size),EINTRretry atlocal.rs:604-613), and the manager reuses those files across restarts (Regions::Reuse,local.rs:615-620; length assertions atlocal.rs:942-949). So the diagnosis rests on real code. But theMemAvailablereader the body names as step 1 —host_pool_budget/host_pool_budget_with_reserve(selene/src/offload.rs:923-985, called atoffload.rs:170,181) — is untouched by the diff; the change instead exempts tmpfs-backed bytes inside the pool budget (selene/src/pool/budget.rs:15-28). Recorded as a fact about where the fix lands, not a verdict. - Undeclared source-breaking change.
PlannedRegionandRegisteredRegionare publicly re-exported (selene/src/pool/mod.rs:60) and each gains a requiredpub backed_bytes: u64(selene/src/pool/startup.rs:29-32,42-45); neither is#[non_exhaustive], so any out-of-tree constructor stops compiling. The body lists the field but not the break.registered_region()also gained a parameter (conn.rs:706-717) but ispub(crate). - Undeclared side effect on unified-memory hosts.
Budget::chargesapportionshost.div_ceil(integrated)to every integrated device (selene/src/pool/budget.rs:30-42). Zeroing host bytes for backed tmpfs therefore also removesarena+stagingfrom the per-GPU charge — while on a unified-memory host those tmpfs pages are the same physical RAM the GPU KV cache competes for. That is exactly the failing host in the report (494.5 GiB unified). The new test even pins the integrated path: devices[(device,false),(device,true)]assertcharges == [device, device](selene/src/pool/budget/tests.rs:118-124). - The only new syscall path is never executed.
backed_shm_bytes(conn.rs:678-704) has no test; the body says so ("they do not directly execute thestatfshelper or a fresh manager attachment reproduction"). The two new tests fabricatePlannedRegionvalues (budget/tests.rs:92-186); nothing coversregister_memory's decision to passarena_backed/staging_backed(conn.rs:774-793) orbuilder.rs'sregistration_costsmapping (builder.rs:239-245). - No in-tree caller or integration test for the approval path.
PoolBuilderappears only atselene/src/pool/builder.rs:61,82and its re-exportselene/src/pool/mod.rs:43;offload::Startup::start_pool(selene/src/offload.rs:994) has no call site anywhere;heliosonly re-exportsPoolOptions(helios/src/offload/mod.rs:28) and drivesStartup::attach/reset/binding(helios/src/runtime_core/model.rs:26,1002,1048,1089,1117). The path this PR changes has no in-repo end-to-end harness — consistent with the PR's own caveat. - Undeclared user-visible number change.
PreparedPool::summary()(builder.rs:246-249) and per-GPUcharges(builder.rs:188-193) now report smaller host bytes, while the startup lineregistered {:.1} GiB of pool memorystill prints the full byte sum (conn.rs:865-870). Nothing printsbacked_bytes, so the two figures no longer agree. - No linked issue, no prior report, no reviewers.
search_itemsfor the topic (backed_bytes tmpfs MemAvailable double count, and earlier shm/fallocate/budget phrasings) returns only #699.mainhas nobacked_bytesanywhere (searched at refmain), confirming the field is new. - Docs describing this budget are not updated:
docs/cli-design.md:891(not opened) ("MemAvailable instead."),docs/model-preparation.md:490(not opened),docs/runtime-core-design.md:768(not opened) — all still describe theMemAvailable-derived budget with no tmpfs exemption. - Two orientation leads resolved as not relevant (details under Related work): #674 shares only file proximity and incidentally-stemmed identifiers (
shared_backed,staging_backed,saturating_mul) but its scope is prefix-cache hit rate, L1 retention, NVMe I/O and snapshot packing; #475'sdeclared_bytesmatch is inignition/section names, unrelated.
The change
Plain terms: when an arena/staging file lives on tmpfs and has been fallocated, its pages are already physically committed and already missing from MemAvailable; charging their full size again against the pool budget rejects valid configs. The PR measures how much of each shared file is already backed and charges only the remainder.
Budget::costschanged fromimpl Iterator<Item = u64>toIterator<Item = (u64, u64)>, computingadditional_host = bytes.saturating_sub(backed_bytes.min(bytes))for the host term while leaving the device termbytes.div_ceil(512)unchanged; both "pool host/device bytes overflow" checks are kept (selene/src/pool/budget.rs:15-28).approvemaps(region.bytes, region.backed_bytes), sohost = Err(...)propagation and the per-GPUGPU {rank}error are unchanged (budget.rs:44-70).backed_shm_bytes(path, declared_bytes)(conn.rs:678-699): Linux-only;CString+libc::statfs, requiresf_type as u64 == libc::TMPFS_MAGIC as u64, thenmetadata(path).blocks().saturating_mul(512).min(declared_bytes); returns 0 for a NUL in the path, non-zerostatfs, non-tmpfs, ormetadatafailure. Non-Linux stub returns 0 (conn.rs:701-704), preserving old behaviour on Windows/macOS — relevant because Selene is built and tested on Windows too (#171, merged).register_memorycomputes both backed values up front fromshared.arena_path/staging_path(conn.rs:774-779), uses them in thePlannedRegionplan (conn.rs:780-793), passes0for remote anonymousdata-staging(conn.rs:794-800), and reuses them forRegisteredRegion(conn.rs:852-864).PreparedPool::registration_costsmaps(bytes, backed_bytes)(builder.rs:239-245), feedingsummary()andcharges(builder.rs:188-193,246-249).- Tests:
preallocated_shm_skips_host_double_count_but_keeps_device_charge(budget/tests.rs:92-142) asserts host = 0, device =(arena+staging)/512, that 25 GiB of budget now approves a 40 GiB pool, and that GPU shortfall (GPU 0) andhost: Errstill fail;partially_backed_shm_charges_only_unbacked_remainder(budget/tests.rs:144-186) asserts host = 6 MiB from a 16/4/2 MiB plan, thebacked > bytesclamp, and the off-by-one rejection. Existing tests gainedbacked_bytes: 0(budget/tests.rs:9-18,59-61). - Scope: no proto, CLI, config, docs, or
selene-managerchange; no new dependency (libcalready used, e.g.eos/src/unix.rs:88(not opened)).
Description vs. code details:
- The body says the reserve is "2 GiB + 5% MemTotal"; the code is
host_service_headroom_bytes(total) + total/20, where the service headroom ismin(2 GiB, total/32)and collapses to 64 MiB on ≤16 GiB hosts (selene/src/offload.rs:901-919). Immaterial to the bug; the description simplifies. - The body attributes
fallocatetoselene-manager/src/local.rs— verified (local.rs:582-602).
The why
The body reports a 494.5 GiB unified-memory host (230.2 GiB host weights, 128 GiB local --prefix-cache-memory, 32G arena + 8G staging, ~69 GiB real free after weights+pool) failing with the verbatim error:
Error: cannot attach the configured prefix cache pool: the pool's host memory (arena 34359738368 bytes, staging 8589934592 bytes) was not approved (needs 42949672960 host bytes and 83886080 device bytes per GPU; host budget has 27910736778 bytes left)
That string is exactly register_memory's wrapper (selene/src/pool/conn.rs:809-811) around Budget::approve's message (selene/src/pool/budget.rs:55); 83886080 = 42949672960/512 matches budget.rs:24, and 27910736778 ≈ 494.5 − 230.2 − 128 − 40 − reserve(~26.7). The report is therefore internally consistent with the code. Two-stage charging is visible: host_pool_budget reads MemAvailable and subtracts future plus reserve (offload.rs:923-985), then approve charges arena+staging again (budget.rs:44-72).
Demand: no issue, thread, or prior report is referenced, and none exists in the searchable window — the change is author-driven. Neither my notes nor the packet found a user asking for it.
Related work
From related_items(#699), every same-file PR is by yatesdr:
- #92 (merged) "Share prefix KV cache between instances and hosts through a selene pool manager" — 5 files in common, i.e. every file this PR touches; origin of the pool manager and budget machinery.
- #365 (merged) "Require pool attachment at startup and register pool memory off the I/O thread" — 3 in common (builder/conn/startup); direct ancestor of the
Approve/PlannedRegion/register_memorypath this PR extends. - #611 (merged) conn.rs hardening; #609 (merged) shared-region lifetimes; #376 (merged) pid-zero peers; #142 (merged) conn.rs; #455 (merged) builder.rs.
- #504/#492/#486/#477/#436 compression series touch builder.rs/conn.rs (not opened) but not budget accounting.
- #171 (merged) "Build and test Selene and Helios on Linux and Windows again" — why the non-Linux stub at
conn.rs:701-704matters.
Leads from the packet, now resolved:
- #674 (open, by
yatesdr, opened 2026-12-02 07:59, updated 23:34,+11418/−1237, 42 files, labels area:caching/area:memory/area:selene/performance/triage:review) is "improve prefix-cache hit rate, L1 retention, NVMe throughput, and GPU snapshot packing". Its body covers resident-aware lookup, L1 DRAM retention, NVMeO_DIRECT, eviction pricing — no mention of tmpfs preallocation,MemAvailable, double counting, or a host-budget exemption. The identifier matches (shared_backed,staging_backed,saturating_mul) are generic stems, not shared code. Relation: same files (conn.rs,builder.rs) and same subsystem, but not competing or stacked work. Practical note: it is a very large PR by the area owner opened the same day, so merge order onconn.rs/builder.rsdeserves a glance. - #646 (merged) matched
staging_backed, #477 (closed) matchedbacked_bytes, #475 (open, ignition CheckpointOverlay) matcheddeclared_bytes— all incidental identifier stems; #475 does not touch Rust or Selene at all. - Nothing found that #699 supersedes, undoes, or is superseded by.
Recent activity
Orientation packet: base main, head 135633f, opened and last updated 2026-12-02, "ready for review". "Commits on the default branch since this pull request branched (cc0a49d) touching its changed files: none" → not currently conflicting. Commit-level history for selene/src could not be read: search_history fails with git: error: Could not read c513e46a79f3b6ac510235aaf09bcf055b841958 / fatal: cannot simplify commit ef38cb93…; the same error underlies the packet's "not available" note and its "no commits in these areas in the last 180 days" line. So authors/recency of the surrounding code cannot be dated directly; the merged-PR record above (all yatesdr) is the substitute. Character of the change: a narrow late correction to a mature subsystem, not greenfield.
People
- Author
ebfio:FIRST_TIME_CONTRIBUTOR, 0 merged and 0 closed items in 180 days; three items, all 2026-12-02 — #699 (this), #698 (open) "Open host prefix store beforeRankExecutor::new()to avoidcuModuleLoadDatadeadlock with persistent…", #682 (open) "docs(preparation): document logindRemoveIPCrisk for unattended exports". All three sit on the same operational surface (large unified-memory hosts, startup memory,/dev/shmlifetime) — a coherent series from an operator, not a drive-by. Discord:ebfio. Verification host claimed: "Hades Linux aarch64 (kernel 6.17.0-1029-nvidia-64k)", consistent with the unified-memory report. - Area owner:
yatesdrshaped every file this PR touches (#92, #365, #609, #611). Has not commented or reviewed. - Charter-named priority contributors (
voipmonitor,original-el8,lukealonso) are not involved;ebfiois not among them.
Community
pr_comments → "No comments". No reviews, no inline comments, no reactions, no labels, no CI. Interest to date: the author only. Nothing in the PR body or code comments attempted to direct a reviewing agent; no prompt-injection content encountered.
Project fit
In favour: charter goal (line 24) "Store prefix-cache checkpoints in host memory and share them across Flare instances via Selene" — this is squarely on a stated goal, in the layer the charter assigns to Selene, and it helps unified-memory/compact hosts. The charter's four-part description rule (why / what changed / claimed result / evidence) is structurally satisfied.
Tension: the charter asks for real evidence and that bug fixes address the root cause. The body gives a mechanism-level root cause and a unit-test result, but no reproduction against a live manager and no before/after MemAvailable/Shmem measurement, and explicitly disclaims exercising statfs or a fresh attachment. The charter also says good ideas in the wrong place get declined (#404) — whether the pool-budget exemption is the right layer, versus teaching host_pool_budget (offload.rs:923-985) about tmpfs, is a reviewer judgement; recorded here as a fact about where the fix lands.
Docs not reconciled: docs/cli-design.md:891 (not opened), docs/model-preparation.md:490 (not opened), docs/runtime-core-design.md:768 (not opened), plus the in-tree restatement of the budget in helios/src/frontend/mod.rs:1400-1402 ("HOST_SERVICE_HEADROOM_BYTES (2 GiB) plus one twentieth of total memory"). A parallel consumer of the same global number, ignition/planning.py:128-131 (not opened) (integrated-GPU sizing off MemAvailable), is unaffected.
Claims and evidence
| Claim | Evidence |
|---|---|
selene-manager preallocates via libc::fallocate(fd,0,0,size) in local.rs |
Verified: selene-manager/src/local.rs:582-602 (create_region), retry helper local.rs:604-613, file-length assertions local.rs:942-949. |
tmpfs fallocate charges Shmem and deducts from MemAvailable immediately |
Stated as "verified against live /proc/meminfo"; the PR contains no log, script or datum. Consistent with kernel tmpfs semantics, unbacked in-repo. |
| The pool's 40 GiB is charged twice | Supported: the error string matches budget.rs:55 wrapped at conn.rs:809-811; both stages exist (offload.rs:923-985, then budget.rs:44-72). |
| Device registration metadata still charged in full | Verified: bytes.div_ceil(512) unchanged (budget.rs:24), asserted at budget/tests.rs:113. |
| Partial-backed / clamp behaviour | Verified by reading budget/tests.rs:144-186 and budget.rs:19 (backed_bytes.min(bytes)). |
statfs helper is conservative |
Code reading only: NUL path, statfs != 0, non-TMPFS_MAGIC, metadata failure all yield 0 (conn.rs:686-698). Never executed by a test. |
cargo test -p flare-selene pool::budget → 4 passed, 0 failed, 551 filtered out |
Author-reported from Hades aarch64; no CI check exists on 135633f to corroborate; covers only the budget module. |
"The Linux backed_shm_bytes branch compiled" |
Author-reported, no CI. |
| The reported error came from a manager-attached instance | No artifact; plausible from the message shape, unverified. |
Reach
Affected: operators of local selene-manager pools on Linux tmpfs /dev/shm (the configs this unblocks); hosts where /dev/shm is not tmpfs or a file is only partly backed — unchanged, conservative (0 → full charge); Windows/macOS Selene builds — no change (stub conn.rs:701-704); unified-memory hosts — per-GPU charges shrink because of Budget::charges (budget.rs:30-42); external consumers constructing PlannedRegion/RegisteredRegion — compile break; operator-visible output — summary() shrinks while registered {:.1} GiB of pool memory (conn.rs:865-870) still prints full bytes.
Not changed: any CLI flag or default (--prefix-cache-pool, --prefix-cache-pool-ca untouched), config keys, proto/wire, dependencies, deployment layout, or the MemAvailable reader itself.
Timing note: backed_shm_bytes stats the path and then reads metadata, so a manager that recreates its regions between the two calls (Regions::Recreate, generation change, local.rs:194-215) can only make the result smaller — the failure mode is conservative (old behaviour), not over-permissive.
Process
Open, ready for review (not draft); 0 reviews, 0 comments, no labels, no CI on 135633f; opened and last updated the same day (2026-12-02); first-time contributor; the de facto owner of all five files (yatesdr) has not responded.
Two things a decision needs: (a) the public-API break on PlannedRegion/RegisteredRegion (or a Default/#[non_exhaustive] mitigation); (b) the evidence gap — no execution of backed_shm_bytes, no in-tree caller of the approval path, no reproduction, no CI. Also worth noting for merge order: open #674 by the area owner rewrites large parts of selene/src/pool/conn.rs's neighbourhood and builder.rs consumers.
Open questions / not found
- Whether tmpfs
fallocateaccounting is measurable on the reporter's host as described: no raw data in the PR; aShmem/MemAvailablebefore-after capture would settle it. - Whether the same double count should be fixed at
host_pool_budget(offload.rs:923-985) instead of, or in addition to, the pool budget — not addressed anywhere in the PR or docs. - Whether the intended behaviour on unified-memory hosts is really "0 additional host charge" for tmpfs arena pages that the GPU KV cache also competes for — the description is silent; the new test pins the integrated-GPU shrink.
- Commit-level history of
selene/src(authorship/recency) — unavailable due to the git error above. - No maintainer reaction of any kind exists to gauge acceptance; the author's companion PRs #698 and #682 are similarly unreviewed and concern the same
/dev/shm/startup surface, so a decision on #699 may be worth taking together with those.