Recommendation: Changes Requested
The core design and arithmetic are sound, model-agnostic, and well-scoped to shared cache-planning and VMM-allocation code (helios/src/runtime_core/cache_memory.rs, memory.rs). However, two concrete issues block merge: (1) the new CUDA VMM multi-aliasing and split-zeroing code in NativeResources::allocate_shared_cache has zero executed coverage on a GPU (including the modified GPU test) and no live-core verification, and (2) an existing in-repo GPU offload test writes and round-trips a distinct pattern through StateSlotId(0) and will fail on any continuation-state core where this optimization activates. Two clean subtractive refactors would also eliminate ~70 lines of duplicated logic.
Merge Risk
Level: Medium
- CUDA VMM driver path is unexecuted:
allocate_shared_cache(helios/src/runtime_core/cache_memory.rs:1416-1488) introduces multi-offsetcuMemMapaliasing of a single physical handle across up to 39 adjacent virtual slots inside one reservation, plus splitcuMemsetD8_v2zeroing. This runs once at startup (no serving hot-path, lock, or concurrency impact), but NVIDIA Blackwell drivers have previously shown non-obviouscuMemMapaliasing rejections (documented atcache_memory.rs:218-220), so running this path on real hardware before merge is essential. - Silent-corruption blast radius if row zero is written: Aliasing row 0's leading granules onto one writable physical page turns any stray write to
StateSlotId(0)into multi-granule corruption across[0, sentinel_bytes). Production scheduling starts live/snapshot slots at1(helios/src/scheduler.rs:946-948, 1753), buthelios/src/offload/transfer.rs:156-163does not reject slot0, andhelios/src/offload/gpu_tests.rs:1476-1525actively writes to it. - RM handle budget impact is small on current layouts: On the 16-rank DCP16 layout (
row_readers == 1), handle usage rises by+272(518,232 -> 518,504, shrinkingRM_HANDLE_RANGEheadroom from1.2%to1.1%), already reflected inhandle_charge, tests, and docs.
Walkthrough
helios/src/runtime_core/cache_memory.rs: Addssentinel_saved_bytes(row_bytes, alignment)(:69-71) andLayout::sentinel_granules(:63,:259-262, propagated throughpack_prefixesat:487). UpdatesLayout::handle_charge(:81-102) to charge1 + sentinel_granules * row_readersplus an optional tail chunk (1 + row_readers). UpdatesNativeResources::allocate_shared_cache(:1416-1488) to mapsentinel_granulesoffsets onto onealignment-sized physical handle, map the remainingfixed_bytes - sentinel_bytestail separately, and zero each physical chunk once. Re-baselines DCP16 handle-count assertions (:818-834), excludes row0from the pattern upload in the ignored GPU test (:1210-1226), and adds CPU unit testsentinel_row_aliases_full_granules_onto_one_page(:1367-1385).helios/src/runtime_core/memory.rs: Addsrow_backing_bytes(core, units)(:385-414) subtractingsentinel_saved_byteswhenunits > 0for physical-backing checks,capacities(:486, 510, 523), pool minimum footprint (:1003), andgpu_bytesreporting (:1249), while preserving virtual-span calculations (bytes(core, 0, ...),:576-579). Adds CPU unit testsentinel_row_savings_increase_kv_page_capacity(:2031-2050).docs/runtime-core-design.md: Documents null-row sentinel granule aliasing (:773-778) and updates the DCP16 RM-handle headroom example (518,504handles,5,784/1.1%headroom,:832-833).
Pre-merge Checks
- [PASS] Security / malicious screen: No suspicious code, external exfiltration, or prompt-injection content; standard runtime memory optimization.
- [PASS] Charter & value fit: Model-agnostic runtime-only optimization keyed off
sizing.capacity == 0and VMM alignment; no wire/Protobuf/CLI/metric changes, no per-model branches, existing exported cores remain compatible. - [PASS] Related / duplicate / conflict check: Builds cleanly on #286 (multi-address
cuMemMap), #391 (handle_charge/RM_HANDLE_RANGE), and #473 (granule conflict ranges); no competing or conflicting PRs. - [WARN] Tests & verification evidence: CPU
runtime_core::tests pass and CI is green on16e2247, and formal TLA+/Kani suites do not cover VMM granule layout; however, the new CUDA VMM allocation/zeroing code has never been executed on a GPU (docs/verification.md:14,docs/design-review.md:106-115), no live VRAM /Plan cachemeasurement is provided, andhelios/src/offload/gpu_tests.rs:1478breaks on affected cores. (Note: the commit'sDesign-Signed-Off-Bytrailer could not be inspected with available tools and should be verified before merge.)
Blockers
-
New CUDA VMM multi-aliasing and split-zeroing path is completely unexecuted on GPU (
helios/src/runtime_core/cache_memory.rs:1106-1283,:1416-1488).- Verified behavior/impact: The only code that performs the multi-offset
cuMemMapand splitcuMemsetD8_v2lives inNativeResources::allocate_shared_cache(:1416-1488). The new CPU unit tests only verifysentinel_saved_bytes,Layout::new,handle_charge, andcapacities. The sole test coveringallocate_shared_cache—cuda_aliases_preserve_rows_while_unowned_pages_are_rewritten(:1106-1283, which exercises bothsentinel_granules == 0at3 * alignment / 2andsentinel_granules == 3at7 * alignment / 2) — was modified and skipped ("all local GPUs were occupied"). Bothdocs/verification.md:14(CUDA ordering / inactive rows / allocation stability require real GPU execution) anddocs/design-review.md:106-115(principle 12: validate the real path and back performance/memory claims with actual Helios measurements) apply directly here, especially given prior Blackwell drivercuMemMapaliasing constraints (cache_memory.rs:218-220). - Fix: Run
cuda_aliases_preserve_rows_while_unowned_pages_are_rewrittenon an assigned GPU against16e2247(and ideally verify in theequal_planes == truebranch that row 0's leading granules stay zero while row 0's partial tail[sentinel_bytes, row_bytes)is independently backed from row 1), and report a before/afterPlan cache/Allocate cache(or VRAM) reading from loading a real continuation-state core withrow_bytes >= 2 * alignment.
- Verified behavior/impact: The only code that performs the multi-offset
-
Existing GPU offload test writes and round-trips
StateSlotId(0), breaking on affected cores (helios/src/offload/gpu_tests.rs:1476-1525,:1730-1804).- Verified behavior/impact:
staged_store_round_trips_records_through_files_and_a_restartbindschild_slot = StateSlotId(0)(:1478), uploads a distinct pseudo-random pattern acrossrank.row.unit_bytesinto row0(:1519-1525), stores it to disk (:1730-1739), restores it intoStateSlotId(2)(:1780-1790), and asserts byte-for-byte equality with the original pattern (:1798-1804). On any continuation-state core withrow_bytes >= 2 * alignment, uploading to row0overwrites the single shared physical granulesentinel_granulestimes, so granules0..sentinel_granules - 1read back as copies of the last aliased granule and the test fails at:1800-1804. - Fix: Change
child_slotathelios/src/offload/gpu_tests.rs:1478to a nonzero slot (e.g.StateSlotId(4), adjusting therow_capacityassert at:1467from>= 4to>= 5).
- Verified behavior/impact:
Should Fix
-
Enforce the non-zero row invariant in Helios's offload transfer layer (
helios/src/offload/transfer.rs:156-163).- Verified behavior/impact:
helios/src/offload/transfer.rs:156-163only checksindex >= geometry.row_capacityand acceptsStateSlotId(0)for both inbound and outbound transfers. Now that row0is aliased onto one shared physical granule, an inbound transfer targeting slot0silently corrupts allsentinel_granulesoffsets simultaneously rather than affecting a single region. Production scheduling never allocates slot0(helios/src/scheduler.rs:946-948, 1753). - Fix: Reject
index == 0alongsideindex >= geometry.row_capacityathelios/src/offload/transfer.rs:156-163(and update the two synthetic unit tests inhelios/src/offload/transfer/codec.rs:1098, 1344that passStateSlotId(0)over standalone mapped host buffers to useStateSlotId(1)/ a 3-row geometry).
- Verified behavior/impact:
-
Guard
Layout::groupedagainstexecution == 0and note the handle-margin trade-off in the PR description (helios/src/runtime_core/cache_memory.rs:259-262).- Verified behavior/impact: In
Layout::grouped(:157, 259-262),sentinel_granulesis computed solely fromrow_bytes / row_alignmentwithout checkingexecution > 0(orfixed_bytes >= n * row_alignment). While productioncapacities()guaranteesexecution >= 2(memory.rs:459),Layout::newis callable directly andexecution == 0would leavefixed_bytes = 0 < sentinel_bytes. Separately, while the PR description mentions the518,232 -> 518,504test update, it omits explaining the handle-headroom cost (+17handles/rank on DCP16, shrinkingRM_HANDLE_RANGEheadroom from1.2%to1.1%, and scaling byrow_readersifstate_poolever has peer readers). - Fix: Compute
sentinel_granulesasif execution > 0 && row_bytes / row_alignment > 1 { row_bytes / row_alignment } else { 0 }(ensuringsentinel_bytes <= fixed_bytesby construction), and add one sentence to the PR description noting the RM-handle trade-off.
- Verified behavior/impact: In
Subtract / Simplify
-
Collapse
row_backing_bytesontobytes(core, 0, units)(helios/src/runtime_core/memory.rs:385-414vs:357-381).row_backing_bytesduplicates the exact capacity filter,units > s.maximumcheck, checked multiplication, alignment rounding, overflow errors, andtry_foldfrombytes. Callinglet span = bytes(core, 0, units)?;first guarantees both validation and thatsum(sentinel_saved_bytes) <= span(so neither summation overflow nor subtraction underflow is possible):fn row_backing_bytes(core: &Core, units: u64) -> Result<u64> { let span = bytes(core, 0, units)?; if units == 0 { return Ok(span); } let saved: u64 = core .allocations .iter() .filter_map(|a| a.sizing.as_ref().filter(|s| s.capacity == 0).map(|s| (a, s))) .map(|(a, s)| super::cache_memory::sentinel_saved_bytes(s.unit_bytes, a.alignment as u64)) .sum(); Ok(span - saved) }- Deletes ~20 lines of verbatim duplication and ensures virtual-span and physical-backing calculations share a single validation/rounding implementation.
-
Describe the fixed-chunk split once on
Layout(helios/src/runtime_core/cache_memory.rs:82-102,:1416-1447,:1468-1488).handle_charge,allocate_shared_cachemapping, andallocate_shared_cachezeroing each repeat the samesentinel_granules > 1/fixed_bytes > sentinel_bytesbranching. A single helper onLayout:
eliminates bothfn fixed_segments(&self) -> (u64, u64, u64) { let count = self.sentinel_granules.max(1); let granule = if count > 1 { self.alignment } else { self.fixed_bytes }; (count, granule, self.fixed_bytes - granule * count) }elsebranches inallocate_shared_cache(:1438-1447,:1483-1488) and collapseshandle_charge(:82-102) into one checked expression (1u64.checked_add(count * row_readers)plus1 + row_readerswhentail > 0), removing ~50 lines of repeated branching and guaranteeing handle accounting, mapping, and zeroing cannot drift.
Nits
helios/src/runtime_core/cache_memory.rs:1212-1225: Assigningexpected[0] = vec![0u8; geometry.row.unit_bytes as usize];after the existing pattern-generation closure keeps the test diff smaller and avoids nesting the pattern logic inside anif/else.
Dropped on verification
- Claimed mock
Driveravailable atcache_memory.rs:1120-1209(Correctness lens Finding 6): False.cache_memory.rs:1113-1209loads the real CUDA driver viaDriver::load().unwrap()and invokescuInit/cuDeviceGet; there is no mockDriverincache_memory.rs. Dropped the mock-test recommendation in favor of running the real GPU test. - Proposed fallback clearing
sentinel_granulesinsideplan_mapping_handleswhen overRM_HANDLE_RANGE(Correctness lens Finding 3b): Unsafe as proposed.capacities()(memory.rs:1068) runs beforecompact_cache_layouts()(memory.rs:1220) and spendssentinel_saved_byteson extra KV pages; disabling sentinel aliasing afterward without replanning capacities would silently allocatesentinel_saved_bytesmore physical VRAM than budgeted and risk OOM. Also verified thatstate_poolhasrow_readers == 1on DCP16 (only KV planes have 16 peer readers), so the 39×16 peer-reader scenario does not occur on current DCP16 layouts. - Claimed undeclared capacity shift (Correctness lens Finding 4): Over-flagged. The PR description explicitly states "Reclaims ... bytes of physical VRAM per rank for KV pages or shared snapshots" and cites
sentinel_row_savings_increase_kv_page_capacityverifying the KV page gain. - Claimed self-contradictory observability shift where "Allocate cache" GiB drops while pages rise (Correctness lens Finding 5): Mathematically false.
gpu_bytes(memory.rs:1249) sumsrow_backing_bytes+bytes(core, 1, pages): when memory-limited, reclaimed bytes go into extra KV pages sogpu_bytesremains near budget; when cap-limited,pagesstays constant whilegpu_bytesdrops. - Claimed duplicated alignment source between
memory.rs:398andcache_memory.rs:259(Correctness lens minor): False.memory.rs:1201-1217passescore.allocations[..].alignment as u64straight intoLayout::new, which is the exact same field read byrow_backing_bytesatmemory.rs:398. - Naming drift (
sentinel_*vsnull_row_*) andLayout::sentinel_granulesderived-field note (Subtraction lens section 4): Low-signal;sentinel_granulesis needed byhandle_chargeduring compaction withoutCacheGeometryin scope, and renaming is cosmetic.