Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 21 additions & 5 deletions docs/api.md
Original file line number Diff line number Diff line change
Expand Up @@ -344,7 +344,7 @@ without the `flare_` prefix, such as `input_decoded_images_total`.
| `host_hits` | Requests attached to a successfully restored host prefix | `flare_host_cache_hits_total` |
| `host_reused_tokens` | Successfully restored tokens beyond each request's admission GPU prefix | `flare_host_cache_reused_tokens_total` |
| `host_memory_records` | Checkpoint records in the host store's registered memory | `flare_host_cache_memory_records` |
| `host_disk_records` | Checkpoint records in the host store's record directory | `flare_host_cache_disk_records` |
| `host_disk_records` | Ready indexed checkpoint records in the host store's record directory | `flare_host_cache_disk_records` |
| `host_bytes_out` | Bytes copied from GPU checkpoints to the host store | `flare_host_cache_bytes_out_total` |
| `host_bytes_in` | Bytes copied from the host store into GPU pages and rows | `flare_host_cache_bytes_in_total` |
| `learned_drafter` | Boolean: the model has a learned drafter | none |
Expand Down Expand Up @@ -385,11 +385,27 @@ process's local disk tier, which other `flare_host_cache_` families label
that the manager also stored as roots. A `Present` outcome and
a disk-only store's local writes contribute zero. The gauge
`flare_host_cache_parked_records` counts complete DRAM copies awaiting disk
writes. `flare_host_cache_store_skipped_total` includes duplicates and
retries; it is not a dropped-record counter. Local checkpoint pool capacity is
writes. `flare_host_cache_store_skipped_total` includes duplicates, retries, and
unprofitable disk-only rejections; it is not a dropped-record counter, and
`flare_host_cache_store_reasons_total{reason}` breaks down synchronous non-queued
store outcomes (`inflight`, `slabs`, `queue`, `budget`, `oversize`, `present`,
`unprofitable`). Write-side profitability skips across tiers are exported by
`flare_host_cache_spill_skipped_unprofitable_total{tier}` and
`flare_host_cache_spill_skipped_unprofitable_bytes_total{tier}` (`tier="nvme"` or
`"pool"`), counting skipped write bytes (packed stored bytes when already
compressed in L1 DRAM, otherwise uncompressed tail-plus-row bytes). Local checkpoint pool capacity is
reported by `flare_host_cache_slots_in_use`, `flare_host_cache_slots_total`
(including automatic intake), and `flare_host_cache_intake_slots`. Used slots
include pages, row pieces, and staging allocations.
(including automatic intake when local disk is enabled), and
`flare_host_cache_intake_slots`. Used slots include pages, row pieces, and
staging allocations. On-disk storage separates ready indexed records and their logical lengths
(`flare_host_cache_disk_records` and `flare_host_cache_disk_bytes`) from
uncommitted reservations for parked or in-flight writes
(`flare_host_cache_disk_reserved_records` and
`flare_host_cache_disk_reserved_bytes`). Pooled deployments also export
`flare_host_cache_pool_inbound_bytes_per_second{level}` with `neighbour_gpu`,
`host_dram`, `host_nvme`, and `remote_nvme` source levels for the pool's source
ranking estimates, leaving `flare_host_cache_inbound_bytes_per_second` for the
local store's measured restore rate.

Dashboard DEPTH is the change in `verification_drafts` divided by the change in
`verification_rounds` over the sampling window. It averages each request's planned
Expand Down
177 changes: 133 additions & 44 deletions docs/prefix-cache-offload.md

Large diffs are not rendered by default.

31 changes: 23 additions & 8 deletions docs/runtime-core-design.md
Original file line number Diff line number Diff line change
Expand Up @@ -817,7 +817,7 @@ If those spans still exceed the mapping range, the planner groups KV pages in
successively wider bands derived from CUDA allocation granularity and bytes per
page, stopping as soon as the aggregate fits. It measures each geometry's handle
count before creating any GPU backing and keeps reductions in that count. If
even whole-plane grouping remains at or above the limit, startup fails
no searched grouping layout fits below the limit, startup fails
explicitly with the handle shortfall before creating GPU allocations. The
scheduler receives the actual intersection of each snapshot with its KV planes
as an enclosing page range. Wider bands can exclude more pages while a snapshot
Expand Down Expand Up @@ -845,11 +845,17 @@ checks do not constitute model-quality evaluation.

Immutable snapshot capacity is bounded by borrowable KV backing and the prepared
virtual extent. At load, CUDA virtual mappings expose the same allocation chunks
through the page planes and the snapshot part of the continuation range. Small
interleaved runs of dense page planes keep each snapshot's conflicting page range
close to its byte cost. Planes whose allocation granules span more pages than a
row's byte cost remain dedicated to KV; the densest planes always participate.
Across ranks, the scheduler uses the union of conflicting ranges.
through the page planes and the snapshot part of the continuation range. Small interleaved runs of eligible page planes keep each snapshot's conflicting
page range close to its byte cost. Capacity planning and virtual mapping apply
identical plane eligibility: the densest planes always participate, planes whose
mapping granules span at most a row's ideal page cost participate, and when a
single row already spans at least two mapping-granule bands of the densest
planes, exact half-width planes (`largest == 2 * unit`) also participate.
Eligible plane chunks are ordered by descending logical-page interval midpoint so
half-width granules sit centered within the matching densest-plane band rather
than widening single-row conflict spans across adjacent bands; planes excluded by
these eligibility criteria remain dedicated to KV. Across ranks, the scheduler uses
the union of conflicting ranges.
Ranks loaded in separate processes must report identical cache capacities and
snapshot exclusions during the control-channel handshake; a mismatch rejects
startup before replay. Before cache allocation, hosts agree on the smallest row
Expand All @@ -860,8 +866,17 @@ alignment padding excludes no pages. Execution rows never alias KV pages.

Admission reserves the request's KV pages. System, prompt, and terminal snapshots
acquire backing at their capture boundaries, evicting unpinned checkpoints when
needed. If active requests or transfers hold all suitable backing, optional
retention is skipped. An inbound host restore reserves both its row and pages
needed. Under page pressure (`need_pages > 0`), victim selection prioritizes
checkpoints that can release usable KV pages (leaf tail pages, or
snapshot-backing pages not held by any non-evictable owner) over rows whose
entire backing span is blocked by non-evictable owners. Among candidates with
equal page-release potential, selection preserves reuse protection and demand
recency, and within the same protection tier and recency epoch prefers
role-preserving single-child compactions that retain all cached KV pages in
their heir. When free KV pages already suffice and only a non-conflicting
snapshot row is needed, normal recency and protection eviction runs so a free
snapshot row is reclaimed without displacing hotter leaf pages. If active
requests or transfers hold all suitable backing, optional retention is skipped. An inbound host restore reserves both its row and pages
before transfer. A capacity-blocked restore waits while requests, transfers,
or fenced retirement may release backing and its accumulated wait plus estimated
transfer time remains below half the estimated prefill time it replaces. Wait-budget expiry
Expand Down
195 changes: 151 additions & 44 deletions helios/src/cache.rs
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@ pub struct Checkpoint {
ready: bool,
last_use: Fence,
child_count: usize,
only_child: Option<CheckpointId>,
direct_pins: u64,
pins: u64,
accessed: u64,
Expand Down Expand Up @@ -125,6 +126,12 @@ impl Checkpoint {
pub fn child_count(&self) -> usize {
self.child_count
}
pub(crate) fn only_child(&self) -> Option<CheckpointId> {
self.only_child
}
pub fn is_protected(&self) -> bool {
self.reused
}
}

#[derive(Clone, Debug, PartialEq, Eq)]
Expand Down Expand Up @@ -297,13 +304,18 @@ impl PrefixCheckpointCache {
}

pub(crate) fn single_child(&self, id: CheckpointId) -> Option<CheckpointId> {
if self.nodes.get(&id)?.child_count != 1 {
return None;
}
self.nodes
.values()
.find(|node| node.parent == Some(id))
.map(|node| node.id)
let node = self.nodes.get(&id)?;
debug_assert_eq!(
node.only_child,
(node.child_count == 1).then(|| {
self.nodes
.values()
.find(|child| child.parent == Some(id))
.map(|child| child.id)
.unwrap()
})
);
node.only_child
}

/// The GPU-ready checkpoint published under `prefix`, if any.
Expand Down Expand Up @@ -525,6 +537,7 @@ impl PrefixCheckpointCache {
ready,
last_use: proposal.ready_after,
child_count: 0,
only_child: None,
direct_pins: 0,
pins: 0,
accessed: use_epoch,
Expand All @@ -537,7 +550,13 @@ impl PrefixCheckpointCache {
self.owned_pages.extend(candidate_pages);
self.owned_snapshots.insert(proposal.snapshot.id);
if let Some(parent) = proposal.parent {
self.nodes.get_mut(&parent).unwrap().child_count += 1;
let parent_node = self.nodes.get_mut(&parent).unwrap();
parent_node.child_count += 1;
parent_node.only_child = if parent_node.child_count == 1 {
Some(id)
} else {
None
};
}
for ancestor in parent_chain {
let node = self.nodes.get_mut(&ancestor).unwrap();
Expand Down Expand Up @@ -641,7 +660,20 @@ impl PrefixCheckpointCache {
}
self.prefixes.remove(&node.prefix);
if let Some(parent) = node.parent {
self.nodes.get_mut(&parent).unwrap().child_count -= 1;
let new_count = {
let parent_node = self.nodes.get_mut(&parent).unwrap();
parent_node.child_count -= 1;
parent_node.child_count
};
let only_child = if new_count == 1 {
self.nodes
.values()
.find(|child| child.parent == Some(parent))
.map(|child| child.id)
} else {
None
};
self.nodes.get_mut(&parent).unwrap().only_child = only_child;
}
let retired = RetiredResources {
checkpoint: id,
Expand All @@ -664,15 +696,14 @@ impl PrefixCheckpointCache {
self.uncount(&node);
self.tail_pages += moved_pages;
let (heir, child_ready) = {
let child = self
.nodes
.values_mut()
.find(|child| child.parent == Some(id))
.unwrap();
let heir = node
.only_child
.expect("single-child ancestor must track its heir");
let child = self.nodes.get_mut(&heir).unwrap();
debug_assert_eq!(child.parent, Some(id));
debug_assert_eq!(node.direct_pins, 0);
debug_assert_eq!(node.child_count, 1);
debug_assert_eq!(node.pins, child.pins);
let heir = child.id;
let mut pages = node.tail_pages;
pages.append(&mut child.tail_pages);
child.tail_pages = pages;
Expand All @@ -681,6 +712,12 @@ impl PrefixCheckpointCache {
child.last_use = child.last_use.max(node.last_use).max(node.ready_after);
(heir, child.ready)
};
if let Some(parent) = node.parent {
let parent_node = self.nodes.get_mut(&parent).unwrap();
if parent_node.only_child == Some(id) {
parent_node.only_child = Some(heir);
}
}
if child_ready {
self.ready_tail_pages += moved_pages;
}
Expand Down Expand Up @@ -719,26 +756,7 @@ impl PrefixCheckpointCache {
})
}

/// Age-discounted protected token cost incurred if `node` is evicted by an optional capture
/// of `rank`. Role-preserving single-child compactions (`child.role >= node.role`, or
/// `node.role == Endpoint`) preserve all cached KV pages and reusable boundaries (0), and
/// evicting a non-root `Endpoint` leaf preserves its parent prefix (0). Evicting a
/// higher-role (`Anchor`, `Message`) leaf, a root leaf, or compacting a higher-role ancestor
/// into a strictly lower-role child charges `leaf_tokens / (1 + age)` where `age =
/// rank.use_epoch - node.accessed`.
fn protected_eviction_tokens(&self, node: &Checkpoint, rank: RetentionRank) -> u64 {
if node.child_count != 0 {
let child_preserves_role = self
.nodes
.values()
.find(|child| child.parent == Some(node.id))
.is_some_and(|child| child.role >= node.role);
if child_preserves_role || node.role == RetentionRole::Endpoint {
return 0;
}
} else if node.role == RetentionRole::Endpoint && node.parent.is_some() {
return 0;
}
fn age_discounted_protected_tokens(&self, node: &Checkpoint, rank: RetentionRank) -> u64 {
let parent_tokens = node
.parent
.and_then(|parent| self.nodes.get(&parent))
Expand All @@ -748,34 +766,108 @@ impl PrefixCheckpointCache {
leaf_tokens / age.saturating_add(1)
}

pub(crate) fn eviction_candidate_within_budget(
fn is_role_preserving(&self, node: &Checkpoint) -> bool {
node.child_count != 0
&& (node.role == RetentionRole::Endpoint
|| node
.only_child
.and_then(|child_id| self.nodes.get(&child_id))
.is_some_and(|child| child.role >= node.role))
}

fn eligible_eviction_candidates(
&self,
below: Option<RetentionRank>,
immediate: bool,
protected_token_budget: Option<u64>,
) -> Option<(CheckpointId, u64)> {
track_role_preserving: bool,
) -> impl Iterator<Item = (&Checkpoint, u64, bool)> {
self.eviction_candidates()
.filter(|node| {
.filter(move |node| {
below.is_none_or(|rank| {
(node.retention_rank(), node.id.value()) < (rank, self.next_id)
})
})
.filter(|node| !immediate || node.last_use.max(node.ready_after) <= self.completed)
.filter_map(|node| {
.filter(move |node| !immediate || node.last_use.max(node.ready_after) <= self.completed)
.filter_map(move |node| {
let role_preserving = track_role_preserving && self.is_role_preserving(node);
let cost = match (below, protected_token_budget) {
(Some(rank), Some(budget)) => {
let tokens = self.protected_eviction_tokens(node, rank);
let tokens = if role_preserving
|| (node.child_count == 0
&& node.role == RetentionRole::Endpoint
&& node.parent.is_some())
{
0
} else {
self.age_discounted_protected_tokens(node, rank)
};
if tokens > budget {
return None;
}
tokens
}
_ => 0,
};
Some((node, cost))
Some((node, cost, role_preserving))
})
.min_by_key(|(node, _)| self.eviction_key(node))
.map(|(node, cost)| (node.id, cost))
}

pub(crate) fn evictable_snapshots(
&self,
below: Option<RetentionRank>,
immediate: bool,
protected_token_budget: Option<u64>,
) -> impl Iterator<Item = SnapshotId> {
let track_role_preserving = below.is_some() && protected_token_budget.is_some();
self.eligible_eviction_candidates(
below,
immediate,
protected_token_budget,
track_role_preserving,
)
.map(|(node, _, _)| node.snapshot)
}

fn select_eviction_candidate<K: Ord>(
&self,
below: Option<RetentionRank>,
immediate: bool,
protected_token_budget: Option<u64>,
priority_uses_role_preserving: bool,
mut priority: impl FnMut(&Checkpoint, bool) -> K,
) -> Option<(CheckpointId, u64)> {
let track_role_preserving =
priority_uses_role_preserving || (below.is_some() && protected_token_budget.is_some());
self.eligible_eviction_candidates(
below,
immediate,
protected_token_budget,
track_role_preserving,
)
.min_by_key(|(node, _, role_preserving)| {
(priority(node, *role_preserving), self.eviction_key(node))
})
.map(|(node, cost, _)| (node.id, cost))
}

pub(crate) fn eviction_candidate_with_priority<K: Ord>(
&self,
below: Option<RetentionRank>,
immediate: bool,
protected_token_budget: Option<u64>,
priority: impl FnMut(&Checkpoint, bool) -> K,
) -> Option<(CheckpointId, u64)> {
self.select_eviction_candidate(below, immediate, protected_token_budget, true, priority)
}

pub(crate) fn eviction_candidate_within_budget(
&self,
below: Option<RetentionRank>,
immediate: bool,
protected_token_budget: Option<u64>,
) -> Option<(CheckpointId, u64)> {
self.select_eviction_candidate(below, immediate, protected_token_budget, false, |_, _| ())
}

pub(crate) fn eviction_candidate(
Expand Down Expand Up @@ -945,6 +1037,21 @@ impl PrefixCheckpointCache {
),
"cache counts drifted from the checkpoints they count"
);
#[cfg(test)]
for node in self.nodes.values() {
let expected = (node.child_count == 1).then(|| {
self.nodes
.values()
.find(|child| child.parent == Some(node.id))
.map(|child| child.id)
.expect("single-child checkpoint missing its child")
});
assert_eq!(
node.only_child, expected,
"only_child drifted for checkpoint {:?}",
node.id
);
}
CacheStats {
published_checkpoints: self.ready_checkpoints,
pending_checkpoints: self.unready_checkpoints,
Expand Down
1 change: 1 addition & 0 deletions helios/src/cache/lifecycle_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ impl Fixture {
ready: node.ready,
last_use: node.last_use,
child_count: node.child_count,
only_child: node.only_child,
direct_pins: node.direct_pins,
pins: node.pins,
accessed: node.accessed,
Expand Down
Loading
Loading