Skip to content

Snapshot aliasing admits only the largest cache plane, so a snapshot excludes ~3.16x its own page cost #451

Open

Description

@shieldstar

Summary

alias_plane admits a cache plane for snapshot-row aliasing only when it is the largest plane
or when the plane's granule count fits inside the row's page count. On the eight-plane geometry
below at 2 MiB granularity the second arm holds for no smaller plane: the three 18,432 B planes
need 114 granules, the three 4,352 B planes 482, and the 8,704 B plane 241, against 30 pages per
row. Exactly one plane is interleaved, the 36,864 B plane, which is the largest and is admitted
by the first arm; the other seven are laid out unaliased. The excluded-page counters this check
takes as input (99,959 excluded pages over 1,055 snapshots, 94.75 per snapshot) against the
row's own 30-page cost give 3.158, so an owned snapshot excludes about 3.16 times its row cost
in KV pages.

Environment

  • Upstream commit: 21a40f05409e8a1f199ee6d348d76a13456dab45
  • Build: Rust 1.94.1, cargo with --locked --offline, Linux arm64 (aarch64)
    (cargo test --features runtime-core --locked --offline --manifest-path helios/Cargo.toml)
  • No GPU needed: this reproduces the layout decision as a unit test

Steps to reproduce

From a clean checkout of the commit above:

  1. Add helios/src/runtime_core/cache_memory/tests/cache_alias_planes.rs with the module
    source below.
  2. Register it inside the mod tests block in helios/src/runtime_core/cache_memory.rs
    (opened at line 334, after use super::*; on line 335) with:
#[path = "cache_alias_planes.rs"]
mod cache_alias_planes;
  1. Run the three tests by full path:
cargo test --features runtime-core --locked --offline --manifest-path helios/Cargo.toml --lib \
  -- --list
cargo test --features runtime-core --locked --offline --manifest-path helios/Cargo.toml --lib \
  runtime_core::cache_memory::tests::cache_alias_planes::geometry -- --exact --nocapture --test-threads 1
cargo test --features runtime-core --locked --offline --manifest-path helios/Cargo.toml --lib \
  runtime_core::cache_memory::tests::cache_alias_planes::only_the_largest_plane_aliases -- --exact --nocapture --test-threads 1
cargo test --features runtime-core --locked --offline --manifest-path helios/Cargo.toml --lib \
  runtime_core::cache_memory::tests::cache_alias_planes::excluded_pages_are_3_2x_the_row -- --exact --nocapture --test-threads 1
step result
--list 1022 tests, three cache_alias_planes paths present
geometry pass (1 passed, 1021 filtered out)
only_the_largest_plane_aliases pass (1 passed, 1021 filtered out)
excluded_pages_are_3_2x_the_row pass (1 passed, 1021 filtered out)
/// 2 MiB alias granularity used by the snapshot pool.
const ALIGNMENT: u64 = 2 * 1024 * 1024;

/// One row (3,311,616 B) and the eight plane unit sizes: three 18,432 B, three 4,352 B,
/// one 36,864 B latent_page and one 8,704 B plane. Their sum is the page (113,920 B).
const ROW: u64 = 3_311_616;
const PLANES: [u64; 8] = [18_432, 18_432, 18_432, 4_352, 4_352, 4_352, 36_864, 8_704];

/// Excluded pages over checkpoints: 99,959 / 1,055.
const EXCLUDED_PAGES: f64 = 99_959.0;
const CHECKPOINTS: f64 = 1_055.0;

use super::alias_plane;

fn page_bytes() -> u64 {
    PLANES.iter().sum()
}

fn largest_plane() -> u64 {
    *PLANES.iter().max().unwrap()
}

#[test]
fn geometry() {
    let page = page_bytes();
    assert_eq!(page, 113_920, "page is the sum of the eight planes");
    assert_eq!(ROW.div_ceil(page), 30, "row.div_ceil(page) = 30");
    eprintln!(
        "ALIAS row={} page={} div_ceil={}",
        ROW,
        page,
        ROW.div_ceil(page)
    );
    for &plane in &PLANES {
        eprintln!(
            "ALIAS plane={} granules={} aliased={}",
            plane,
            ALIGNMENT.div_ceil(plane),
            alias_plane(plane, largest_plane(), ROW, page, ALIGNMENT)
        );
    }
}

#[test]
fn only_the_largest_plane_aliases() {
    let page = page_bytes();
    let largest = largest_plane();
    assert_eq!(largest, 36_864, "the largest plane is the 36,864 B latent_page");
    let aliased: Vec<u64> = PLANES
        .iter()
        .copied()
        .filter(|&unit| alias_plane(unit, largest, ROW, page, ALIGNMENT))
        .collect();
    assert_eq!(aliased, vec![36_864], "only one plane per row is aliasable");
    for plane in [18_432u64, 4_352, 8_704] {
        assert!(
            ALIGNMENT.div_ceil(plane) > ROW.div_ceil(page),
            "plane {plane} needs {} granules, the row's page cost is {}",
            ALIGNMENT.div_ceil(plane),
            ROW.div_ceil(page)
        );
    }
}

#[test]
fn excluded_pages_are_3_2x_the_row() {
    let own_pages = ROW.div_ceil(page_bytes());
    let excluded_pages = EXCLUDED_PAGES / CHECKPOINTS;
    let ratio = excluded_pages / own_pages as f64;
    eprintln!(
        "ALIAS excluded_pages={:.2} own_pages={} ratio={:.3}",
        excluded_pages, own_pages, ratio
    );
    assert!(
        (3.15..3.17).contains(&ratio),
        "about 3.2x its byte cost in KV pages, got {ratio:.3}"
    );
}

Actual

test runtime_core::cache_memory::tests::cache_alias_planes::geometry ... ALIAS row=3311616 page=113920 div_ceil=30
ALIAS plane=18432 granules=114 aliased=false
ALIAS plane=18432 granules=114 aliased=false
ALIAS plane=18432 granules=114 aliased=false
ALIAS plane=4352 granules=482 aliased=false
ALIAS plane=4352 granules=482 aliased=false
ALIAS plane=4352 granules=482 aliased=false
ALIAS plane=36864 granules=57 aliased=true
ALIAS plane=8704 granules=241 aliased=false
ok
test result: ok. 1 passed; 0 failed; 0 ignored; 0 measured; 1021 filtered out; finished in 0.00s
--
test runtime_core::cache_memory::tests::cache_alias_planes::only_the_largest_plane_aliases ... ok
test result: ok. 1 passed; 0 failed; 0 ignored; 0 measured; 1021 filtered out; finished in 0.00s
--
test runtime_core::cache_memory::tests::cache_alias_planes::excluded_pages_are_3_2x_the_row ... ALIAS excluded_pages=94.75 own_pages=30 ratio=3.158
ok
test result: ok. 1 passed; 0 failed; 0 ignored; 0 measured; 1021 filtered out; finished in 0.00s

Expected

Every plane whose granule count is small enough should be interleaved into the snapshots, so a
snapshot's excluded page count stays close to its own row cost instead of several times it.
alias_plane's own comment states that intent ("Borrow from planes whose granules span at most
a row's page cost, including the densest"), but the test compares the granule count with the
row's page count, and on this geometry that admits only the largest plane.

Source pointers

  • helios/src/runtime_core/cache_memory.rs:38-42 — alias_plane, decision at line 41:
    unit == largest || alignment.div_ceil(unit) <= row.div_ceil(page)
  • helios/src/runtime_core/cache_memory.rs:89-95 — the call site in Layout::unmerged
    passes p.unit_bytes, the largest plane, row_bytes, geometry.page_bytes() and the
    plane's alignment
  • selene/src/geometry.rs:58-60 — page_bytes() sums all plane unit_bytes, so the page is
    113,920 B here while one row is 3,311,616 B
  • helios/src/runtime_core/cache_memory.rs:83 — largest is the maximum plane unit_bytes
  • selene/src/geometry.rs:52-53 — snapshot_pages: "Ownership of a snapshot excludes every
    page in its range through GPU retirement"

Suggested fix

Either admit a plane when the rows its granules span can absorb the exclusion (compare the
granule count against the page cost of those rows, not of one row), or state in the comment
that at 2 MiB granularity only the densest plane can alias and derive the snapshot exclusion
from that single-plane layout. A regression test should pin which planes alias for this
eight-plane geometry.

Activity

  1. yatesdr commented on Nov 21, 2026

    @yatesdr
    Collaborator

    The arithmetic checks out at main 21a40f0, but the rule is deliberate and documented. alias_plane admits a plane only when its mapping granule spans no more pages than a row costs, and always admits the densest plane (helios/src/runtime_core/cache_memory.rs:38-42; docs/runtime-core-design.md, "Immutable snapshot capacity"). In this geometry only the densest plane qualifies, so a snapshot's conflicting range is about 3.1 times its byte cost (page bytes over the densest plane's unit).

    The cost is KV capacity and prefix retention, not correctness or client output: planes left out keep their dedicated backing. The design doc's "close to its byte cost" overstates it for this geometry. Whether admitting the wider planes would help is not established, because their granules widen each snapshot's conflict range. The third test in the issue divides two literals without calling Layout::new, so it cannot fail.

  2. added
    area:memory
    area:caching
    on Nov 21, 2026
  3. yatesdr commented on Dec 3, 2026

    @yatesdr
    Collaborator

    Addressed in #674 (helios/src/runtime_core/cache_memory.rs, docs/runtime-core-design.md):

    • plan_mapping_handles now admits exact half-width alias planes ordered by descending midpoint (alias_midpoints) with per-rank handle budgeting and a non-power-of-two fallback, rather than limiting admission to planes whose granule is at most one row cost.
    • Paired with pressure-aware GPU cache eviction (evict_for_pressure), measured SM120 results on DeepSeek-V4.1-Flash TP4 (24 prompts / 72 checkpoints) increased flare_snapshot_capacity from 1,946 to 4,864 (+2.50×) and cut flare_snapshot_backing_pages from 5,917 to 2,390 (-59.6%, freeing 3,527 KV pages / ~451K tokens).
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    area:cachingarea:memory

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions