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
28 changes: 22 additions & 6 deletions docs/prefix-cache-offload.md
Original file line number Diff line number Diff line change
Expand Up @@ -278,6 +278,7 @@ Its core operations are:
pub trait HostStore {
fn lookup(&mut self, history: &dyn History, resident: u64, before: u64) -> Option<HostHit>;
fn store(&mut self, checkpoint: &PublishedCheckpoint) -> Result<StoreOutcome>;
fn can_retry_slabs(&self, checkpoint: &PublishedCheckpoint) -> bool;
fn fetch(&mut self, hit: HostHit, ticket: InboundTicket) -> Result<()>;
fn poll(&mut self, events: &mut Vec<StoreEvent>) -> Result<()>;
fn stats(&self) -> StoreStats;
Expand All @@ -293,9 +294,18 @@ before reuse and is not announced to the pool until offered.
Compaction also offers a deferred branch point as its heir and refreshes
descendant offers with their new parent.
`Queued` holds one GPU pin until `Stored` or `Deferred`; `Present`
requires a committed local copy. `Retry` accepts no copy. The worker retains only
checkpoint IDs for retries after store progress and discards IDs that have left
the GPU cache. `Deferred` releases the copy pin and schedules the same retry when
requires a committed local copy. `Retry` accepts no copy. The worker retains
each deferred checkpoint ID with its last `StoreReason` for retries after store
progress and discards IDs that have left the GPU cache. Before re-submitting a
non-fresh publication deferred for `StoreReason::Slabs`, the worker checks
`can_retry_slabs` (default `true`; `CompositeStore` returns `false` while disk
spills are saturated at `MAX_SPILLS`, already cover the shortfall, or are under
an `ENOSPC` backoff) and skips pinning or calling `store` when it returns
`false`, while fresh publications bypass the gate. Repeated identical `Retry`
outcomes do not mark worker progress, so the worker parks instead of spinning;
`ENOSPC` disk-write failures do not advance store progress, and `CompositeStore`
advances progress once when the 50 ms backoff expires so waiting retries resume.
`Deferred` releases the copy pin and schedules the same retry when
a queued publication cannot obtain host capacity. A failed transfer releases its
pin without retrying. GPU eviction prefers probationary (un-reused) checkpoints
before reuse-protected checkpoints, ordering victims within each tier by
Expand Down Expand Up @@ -1423,14 +1433,20 @@ same completion events the store produces.
A host offer announces the GPU holding and starts its first host copy;
GPU eviction sends its eviction notice and never starts a late copy.
- **Retention metrics.** `flare_host_cache_held_total{tier}` counts record
holding events. `flare_host_cache_dropped_total{tier,reason}` counts local
holding events; when `CompositeStore` already has `MAX_SPILLS` writes in
flight, `store` skips re-invoking spill selection so `dram` holding events
accumulate on progress-gated `poll` maintenance ticks (including each 50 ms
`ENOSPC` backoff expiry) rather than once per rejected publication.
`flare_host_cache_dropped_total{tier,reason}` counts local
end-of-chain, oversized publication, terminal I/O and pool refusal drops
(`end_of_chain`, `oversize`, `io_error`, `pool_refused`). Pool refusal drops
include invalid or oversized puts and budget or in-flight refusals after one
retry. Tiers are `dram` and `nvme`. The `parked_records` count is
exported as `flare_host_cache_parked_records`, a gauge.
`flare_host_cache_store_skipped_total` counts publications that started no
copy, including duplicates and retries.
`flare_host_cache_store_skipped_total` counts publications that reached
`store` and started no copy, including duplicates and retries; deferred
`Slabs` retries skipped by `can_retry_slabs` before entering `store` do not
increment `store_skipped_total` or `store_reasons_total`.
`flare_host_cache_root_records_total{tier,reason}` and
`flare_host_cache_root_pages_total{tier,reason}` count root records and their pages.
`flare_host_cache_deeper_link_records_total{tier}` and
Expand Down
123 changes: 100 additions & 23 deletions helios/src/server/runtime.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
*/

use std::{
collections::{HashMap, VecDeque},
collections::{HashMap, HashSet, VecDeque, hash_map::Entry},
sync::{
Arc, Condvar, Mutex,
atomic::{AtomicBool, Ordering},
Expand Down Expand Up @@ -2825,7 +2825,7 @@ impl<'a> Worker<'a> {
let Some(store) = self.store.as_mut() else {
return Ok(false);
};
use flare_selene::{StoreEvent, StoreOutcome};
use flare_selene::{PublishedCheckpoint, StoreEvent, StoreOutcome, StoreReason};
let mut events = Vec::new();
store.poll(&mut events)?;
let mut progress = !events.is_empty();
Expand Down Expand Up @@ -2907,17 +2907,68 @@ impl<'a> Worker<'a> {
incoming.blocked = None;
}
}
struct PendingStore {
publication: PublishedCheckpoint,
prior_retry: Option<StoreReason>,
fresh: bool,
}
struct Pending {
list: Vec<PendingStore>,
at: HashMap<crate::cache::CheckpointId, usize>,
}
impl Pending {
fn new() -> Self {
Self {
list: Vec::new(),
at: HashMap::new(),
}
}

fn claim(
&mut self,
publication: PublishedCheckpoint,
prior_retry: Option<StoreReason>,
fresh: bool,
) {
match self.at.entry(publication.id) {
Entry::Vacant(entry) => {
entry.insert(self.list.len());
self.list.push(PendingStore {
publication,
prior_retry,
fresh,
});
}
Entry::Occupied(entry) => {
let pending = &mut self.list[*entry.get()];
pending.publication = publication;
pending.fresh |= fresh;
if prior_retry.is_some() {
pending.prior_retry = prior_retry;
}
}
}
}
}

let current_progress = store.stats().progress;
let retry = current_progress != self.store_progress;
self.store_progress = current_progress;
let mut publications = self.scheduler.take_publications();
let retry_ids = self.deferred_stores.clone();
let mut pending = Pending::new();
for publication in self.scheduler.take_publications() {
pending.claim(publication, None, true);
}
let mut waiting = Vec::new();
let mut seen_waiting = HashSet::new();
for (id, reason) in self.deferred_stores.drain(..) {
if let Some(&idx) = pending.at.get(&id) {
pending.list[idx].prior_retry = Some(reason);
continue;
}
if let Some(publication) = self.scheduler.publication(id) {
if retry {
publications.push(publication);
} else {
pending.claim(publication, Some(reason), false);
} else if seen_waiting.insert(id) {
waiting.push((id, reason));
}
} else {
Expand All @@ -2936,28 +2987,49 @@ impl<'a> Worker<'a> {
let retry_copyouts = retry || progress || self.copyout_resources != Some(resources);
self.copyout_resources = Some(resources);
let deferred_copyouts = std::mem::take(&mut self.deferred_copyouts);
for id in &deferred_copyouts {
if !publications.iter().any(|publication| publication.id == *id) {
if let Some(publication) = self.scheduler.publication(*id) {
if retry_copyouts {
publications.push(publication);
} else {
self.deferred_copyouts.push(*id);
}
let prev_deferred_copyouts: HashSet<crate::cache::CheckpointId> =
deferred_copyouts.iter().copied().collect();
let mut seen_copyouts = HashSet::new();
for id in deferred_copyouts {
if !pending.at.contains_key(&id)
&& !seen_waiting.contains(&id)
&& let Some(publication) = self.scheduler.publication(id)
{
if retry_copyouts {
pending.claim(publication, None, false);
} else if seen_copyouts.insert(id) {
self.deferred_copyouts.push(id);
}
}
}
for publication in publications {
for PendingStore {
publication,
prior_retry,
fresh,
} in pending.list
{
if !fresh
&& prior_retry == Some(StoreReason::Slabs)
&& !store.can_retry_slabs(&publication)
{
if seen_waiting.insert(publication.id) {
waiting.push((publication.id, StoreReason::Slabs));
}
continue;
}
let next = next_admission(&self.scheduler, &self.parked, &self.pending);
if !self.scheduler.export_fits(publication.id, next) {
if !deferred_copyouts.contains(&publication.id) {
self.metrics.copyout_headroom_deferrals.fetch_add(1, Ordering::Relaxed);
if !prev_deferred_copyouts.contains(&publication.id) {
self.metrics
.copyout_headroom_deferrals
.fetch_add(1, Ordering::Relaxed);
progress = true;
}
self.deferred_copyouts.push(publication.id);
if seen_copyouts.insert(publication.id) {
self.deferred_copyouts.push(publication.id);
}
continue;
}
progress = true;
self.scheduler.pin_checkpoint(publication.id)?;
let outcome = store.store(&publication);
if self.scheduler.submitted_reoffer(
Expand Down Expand Up @@ -2985,23 +3057,28 @@ impl<'a> Worker<'a> {
if let Ok(outcome) = outcome {
self.metrics.host_store_outcome(outcome);
match outcome {
StoreOutcome::Queued => {},
StoreOutcome::Queued | StoreOutcome::Present | StoreOutcome::Oversize => {
progress = true;
}
StoreOutcome::Retry(reason) => {
if !waiting.iter().any(|(id, _)| *id == publication.id) {
if prior_retry != Some(reason) {
progress = true;
}
if seen_waiting.insert(publication.id) {
waiting.push((publication.id, reason));
}
continue;
}
_ => {}
}
if outcome == StoreOutcome::Oversize {
self.metrics.host_retry_abandoned[4].fetch_add(1, Ordering::Relaxed);
} else if retry_ids.iter().any(|(id, _)| *id == publication.id) {
} else if prior_retry.is_some() {
self.metrics
.host_retry_success
.fetch_add(1, Ordering::Relaxed);
}
} else {
progress = true;
self.metrics.host_retry_abandoned[5].fetch_add(1, Ordering::Relaxed);
}
}
Expand Down
Loading