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
4 changes: 4 additions & 0 deletions core/continuum-engine/fixtures/dyno/2026-11-13-restart.json
Original file line number Diff line number Diff line change
Expand Up @@ -36,5 +36,9 @@
"engine_page_lanes": {
"value": 1,
"receipt": "how many page saves/restores the pinned fork (cd2e16d87) runs at once: one. They are tasks on its single task loop (tools/server/server-queue.cpp:138-153 process_new_tasks; save at server-context.cpp:2809/2960, restore at 2996/3076). Measured: two restores the core issued at once after the 2026-11-14 00:18Z relaunch, Aris (00:18:13.016Z, ms=2573 engine_ms=1012 wait_ms=1561) and Benchy (00:18:13.925Z, ms=1930 engine_ms=906 wait_ms=1024): Benchy waited 1,024 ms, Aris's 1,012 ms in the engine"
},
"host_copy_bytes_per_ms": {
"value": 40558095,
"receipt": "host memcpy on the M5 (Apple M5 Pro, Mac17,9) while it served its residents, 2026-11-14T07:24:45Z: 268,435,456 B copied (python3 bytes(bytearray), one memcpy) best of 7 in 6.62 ms. What the fork's loop pays per byte once a page switch only copies state in or out (llama_state_seq_get_data / set_data on unified memory); the deployed engine's own copy_ms receipt replaces it"
}
}
1 change: 1 addition & 0 deletions core/continuum-engine/src/capacity/dyno.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
//! | 9 | boot during memory settle: a boot that remembered no resident launched at a reading taken while the stopped engine's memory came back (-c 2045, the M5 2026-11-13), and the grown plan was never applied | the boot's remembered residents -> `serving_daemon::launch::launch_pool`, `settle::launch_gate`, `floor_sized::floor_sized` | `continuum-serving` `serving_daemon/tests/dyno.rs` `boot_during_memory_settle` |
//! | 10 | a leased-in mind sized from a prompt size, not her requirement | not drivable yet: [`expected::MissingSeam::LeasedInRequirement`] (the grid seam) | as 9 |
//! | 11 | a restart re-prefills every mind (the M5 2026-11-13 23:45Z: the ledger restored nothing, every first act a full prefill), and the page store gave paged-out minds' pages to a volume other classes filled (29 in two hours) | the page store's `ColdPages::under` at the recorded pressure; save and restore costs from the engine's measured rates | `dyno/restart.rs` |
//! | 11b | a page switch holds the engine's one task loop for its disk IO: every slot's decode stalls for it and switches issued together wait for each other (the M5 2026-11-14 00:18:13Z: Benchy's restore waited 1,024 ms behind Aris's) | the engine's measured save/restore rates and the M5's host copy rate, the switch on the loop vs streamed (copy on the loop, IO on a worker) | `dyno/restart/stall.rs` |

pub mod conservation;
pub mod expected;
Expand Down
4 changes: 4 additions & 0 deletions core/continuum-engine/src/capacity/dyno/restart.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ use crate::inference::slots::{ColdPages, Ratio, StorePressure};

use super::recorded::Receipted;

mod stall;

/// The restart's data file, compiled in so a run needs no file system.
const RESTART_JSON: &str = include_str!("../../../fixtures/dyno/2026-11-13-restart.json");

Expand All @@ -33,6 +35,8 @@ pub(crate) struct RestartDay {
pub(crate) store_pressure: Receipted<RecordedPressure>,
/// How many page saves or restores the engine runs at once (the pinned fork: one).
pub(crate) engine_page_lanes: Receipted<usize>,
/// What copying a page's bytes in host memory costs (dyno 11b, [`stall`]).
pub(crate) host_copy_bytes_per_ms: Receipted<u64>,
}

/// When each job completes, issued all at once in order onto `lanes` engine lanes, each
Expand Down
154 changes: 154 additions & 0 deletions core/continuum-engine/src/capacity/dyno/restart/stall.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,154 @@
//! Dyno 11b: what a KV page switch costs the OTHER minds' decode. The pinned fork runs a whole
//! save or restore (the KV copy and the file IO) as one task on its single task loop, so every
//! slot's decode waits for it and switches issued together wait for each other (the M5
//! 2026-11-14 00:18:13Z: Benchy's restore waited 1,024 ms, Aris's 1,012 ms in the engine).
//! Streamed, the loop only copies the sequence's state out (`llama_state_seq_get_data`) or in
//! (`set_data`), a memcpy proportional to the bytes; the file write or read runs on a worker per
//! switch and its completion is an event back to the loop. Rates are the restart day's
//! receipts ([`RestartDay`]); the copy rate is the M5's host memcpy until the deployed engine's
//! `copy_ms` receipt replaces it.

use super::{completions, RestartDay};

/// Where the engine runs a page switch's work.
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub(crate) enum PageIo {
/// The pinned fork: the whole switch is one task on the loop.
OnTheLoop,
/// The loop copies the state in or out; the file IO runs on a worker per switch.
Streamed,
}

/// Which way a page moves.
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub(crate) enum Way {
Save,
Restore,
}

/// One switch the core issues: a mind's page of `tokens`, moving `way`.
#[derive(Debug, Clone, Copy)]
pub(crate) struct Switch {
pub(crate) way: Way,
pub(crate) tokens: u64,
}

/// What a set of switches issued at once costs.
#[derive(Debug, Clone, PartialEq, Eq)]
pub(crate) struct Stall {
/// How long every slot not being switched cannot decode: the loop's time inside switches.
pub(crate) decode_stall_ms: u64,
/// When each switch's receipt is sent, from the issue, in the order issued.
pub(crate) done_ms: Vec<u64>,
}

impl RestartDay {
/// The file IO of one switch at the engine's measured rate. The measured save rate includes
/// the copy the loop now does, so a streamed save's IO is over-counted by at most its copy.
fn io_ms(&self, s: Switch) -> u64 {
let rate = match s.way {
Way::Save => self.save_bytes_per_ms.value,
Way::Restore => self.restore_bytes_per_ms.value,
};
self.page_bytes(s.tokens) / rate
}

/// The loop's share of a streamed switch: its bytes at host memcpy, rounded up. The page's
/// bytes include its checkpoint sidecar; a restore only moves the sidecar's checkpoints into
/// the slot, so the restore's copy is an upper bound.
fn copy_ms(&self, s: Switch) -> u64 {
self.page_bytes(s.tokens).div_ceil(self.host_copy_bytes_per_ms.value)
}

/// `switches` issued at once onto an engine that runs them `io`. Streamed, each switch has its
/// own worker (the fork sizes the pool from its slots); the loop takes the copy steps one at a
/// time: a save's at its issue, a restore's when its read completes.
pub(crate) fn switches_at_once(&self, switches: &[Switch], io: PageIo) -> Stall {
match io {
PageIo::OnTheLoop => {
let jobs: Vec<u64> = switches.iter().map(|s| self.io_ms(*s)).collect();
Stall { decode_stall_ms: jobs.iter().sum(), done_ms: completions(&jobs, 1) }
}
PageIo::Streamed => {
let mut done_ms = vec![0u64; switches.len()];
let mut loop_free = 0u64;
for (i, s) in switches.iter().enumerate().filter(|(_, s)| s.way == Way::Save) {
loop_free += self.copy_ms(*s);
done_ms[i] = loop_free + self.io_ms(*s);
}
let mut reads: Vec<(u64, usize)> = switches
.iter()
.enumerate()
.filter(|(_, s)| s.way == Way::Restore)
.map(|(i, s)| (self.io_ms(*s), i))
.collect();
reads.sort_unstable();
for (read_done, i) in reads {
loop_free = loop_free.max(read_done) + self.copy_ms(switches[i]);
done_ms[i] = loop_free;
}
let decode_stall_ms = switches.iter().map(|s| self.copy_ms(*s)).sum();
Stall { decode_stall_ms, done_ms }
}
}
}
}

#[cfg(test)]
mod tests {
use super::*;

fn day() -> RestartDay {
RestartDay::load().expect("test: the recorded 2026-11-13 restart data parses")
}

fn saves(day: &RestartDay) -> Vec<Switch> {
day.contexts_tokens.value.iter().map(|&tokens| Switch { way: Way::Save, tokens }).collect()
}

// what this catches: a page save that holds the engine's loop for its disk write. The stop's
// checkpoint saves the four recorded residents at once: on the loop every other slot cannot
// decode for the ~13.5 s sum; streamed, the loop holds only the four copies (~0.2 s) and the
// last receipt arrives after the largest save plus the copies ahead of it (~5.0 s).
#[test]
fn four_saves_at_once_stall_decode_for_their_copies_not_their_writes() {
let day = day();
let before = day.switches_at_once(&saves(&day), PageIo::OnTheLoop);
let after = day.switches_at_once(&saves(&day), PageIo::Streamed);
assert!((13_000..=14_000).contains(&before.decode_stall_ms), "{before:?}");
assert!((150..=250).contains(&after.decode_stall_ms), "{after:?}");
assert!(after.decode_stall_ms * 50 < before.decode_stall_ms, "streamed stalls decode under a fiftieth: {after:?} vs {before:?}");
let last = after.done_ms.iter().max().copied().unwrap_or_default(); // unwrap_or_default: four saves were issued
assert!((4_900..=5_100).contains(&last), "the last receipt is the largest save plus the copies before it: {after:?}");
assert!(last < before.done_ms.iter().max().copied().unwrap_or_default() / 2); // unwrap_or_default: as above
}

// what this catches (the M5 2026-11-14 00:18:13Z): two restores issued together, the second
// waiting out the first in the engine (Benchy 1,024 ms behind Aris's 1,012 ms). Streamed, each
// mind waits for her own read and one set step (~1.0 s each), and the other slots' decode
// stalls ~70 ms instead of ~1.9 s.
#[test]
fn two_restores_issued_together_each_wait_only_for_their_own_read() {
let day = day();
let pair = [Switch { way: Way::Restore, tokens: 43_389 }, Switch { way: Way::Restore, tokens: 43_637 }];
let before = day.switches_at_once(&pair, PageIo::OnTheLoop);
let after = day.switches_at_once(&pair, PageIo::Streamed);
assert!((1_850..=1_950).contains(&before.done_ms[1]), "the second waits the first out: {before:?}");
assert!(after.done_ms.iter().all(|ms| (950..=1_050).contains(ms)), "{after:?}");
assert!((60..=80).contains(&after.decode_stall_ms), "{after:?}");
assert!(after.decode_stall_ms * 20 < before.decode_stall_ms, "{after:?} vs {before:?}");
}

// what this catches: a streamed save's receipt counted before its file exists. A switch's
// receipt is never earlier than its own IO, whatever else is in flight.
#[test]
fn no_receipt_precedes_its_own_io() {
let day = day();
let mut mixed = saves(&day);
mixed.push(Switch { way: Way::Restore, tokens: 43_389 });
let after = day.switches_at_once(&mixed, PageIo::Streamed);
for (s, done) in mixed.iter().zip(&after.done_ms) {
assert!(*done >= day.io_ms(*s) + day.copy_ms(*s), "{s:?} done at {done} ms");
}
}
}
17 changes: 10 additions & 7 deletions core/continuum-engine/src/inference/turn_admission.rs
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ pub use transient::admit_transient;
use transient::admit_transient_through;

pub(crate) use page_receipt::PageAction;
use page_receipt::{terminal_receipt, Terminal};
use page_receipt::{terminal_receipt, EngineWork, Terminal};
use page_liveness::{bounded_page_receipt, wait_while_engine_progresses, PageLiveness, Receipt};
#[cfg(test)]
use page_quote::read_quote;
Expand Down Expand Up @@ -917,9 +917,7 @@ async fn kv_page_action_with_capacity(
// its clock starts after a busy slot's deferral, so `ms - engine_ms` is the wait and
// engine_ms the load (card a40e1bbf; the 5090 2026-10-11: Kimi's restores took 6-7.5 min
// and nothing could say how much was waiting for the slot and how much was reading).
let (timing_field, bytes_field) = action.engine_fields();
let engine_ms = body.as_ref().and_then(|b| b["timings"][timing_field].as_f64().map(|ms| ms as u64));
let engine_bytes = body.as_ref().and_then(|b| b[bytes_field].as_u64());
let work = EngineWork::of(action, body.as_ref());
let outcome = match terminal_receipt(action, slot, &filename, status, body.as_ref()) {
Some(Terminal::Completed) => PageOutcome::Completed,
Some(Terminal::Rejected) => PageOutcome::Rejected,
Expand Down Expand Up @@ -968,11 +966,16 @@ async fn kv_page_action_with_capacity(
status = status as u64,
ms,
// absent when the engine gave no timing (an older engine, or no terminal body)
engine_ms = %engine_ms.map_or_else(|| "none".to_string(), |v| v.to_string()),
wait_ms = %engine_ms.map_or_else(|| "none".to_string(), |v| ms.saturating_sub(v).to_string()),
engine_ms = %EngineWork::shown(work.ms),
wait_ms = %EngineWork::shown(work.ms.map(|v| ms.saturating_sub(v))),
// the engine's loop (what other slots' decode waits for) and its IO worker (fork #118)
copy_ms = %EngineWork::shown(work.copy_ms),
io_ms = %EngineWork::shown(work.io_ms),
admit_ms = %EngineWork::shown(work.admit_ms),
io_bytes_in_flight = %EngineWork::shown(work.in_flight_bytes),
// the engine counts only the .bin; the sidecars (checkpoints, adapter vector) are read and
// written in the same timed switch, so they are named apart (BigMama on #4957)
slot_bytes = %engine_bytes.map_or_else(|| "none".to_string(), |v| v.to_string()),
slot_bytes = %EngineWork::shown(work.bytes),
sidecar_bytes = %crate::inference::slots::page_sidecar_bytes(&filename).map_or_else(|| "none".to_string(), |v| v.to_string()),
bound_ms = bound.as_millis() as u64,
node_p50_ms = p50_ms,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,14 +25,51 @@ impl PageAction {

/// The fork's own timing and byte fields for this switch's work (`timings.save_ms`,
/// `n_written` for a save; the read side for the rest).
pub(crate) fn engine_fields(self) -> (&'static str, &'static str) {
fn engine_fields(self) -> (&'static str, &'static str) {
match self {
Self::Save => ("save_ms", "n_written"),
Self::Restore | Self::Erase => ("restore_ms", "n_read"),
}
}
}

/// The engine's own account of a switch's work, each part absent when the engine gave none (an
/// older engine, or no terminal body). `ms` is its clock (it starts after a busy slot's deferral,
/// so the caller's elapsed minus `ms` is the wait); since fork #118 it splits into `copy_ms`, its
/// task loop's share (the state copied out or in: the only part other slots' decode waits for),
/// and `io_ms`, its IO worker's (the page files written or read, beside the decode); `admit_ms` is
/// its wait for the engine's page IO byte budget and `in_flight_bytes` what every switch held then.
#[derive(Debug, Clone, Copy, Default, PartialEq)]
pub(crate) struct EngineWork {
pub(crate) ms: Option<u64>,
pub(crate) bytes: Option<u64>,
pub(crate) copy_ms: Option<f64>,
pub(crate) io_ms: Option<f64>,
pub(crate) admit_ms: Option<f64>,
pub(crate) in_flight_bytes: Option<u64>,
}

impl EngineWork {
pub(crate) fn of(action: PageAction, body: Option<&serde_json::Value>) -> Self {
let Some(body) = body else { return Self::default() };
let (timing, bytes) = action.engine_fields();
let timings = &body["timings"];
Self {
ms: timings[timing].as_f64().map(|ms| ms as u64),
bytes: body[bytes].as_u64(),
copy_ms: timings["copy_ms"].as_f64(),
io_ms: timings["io_ms"].as_f64(),
admit_ms: timings["admit_ms"].as_f64(),
in_flight_bytes: body["page_io"]["io_bytes_in_flight"].as_u64(),
}
}

/// A part as a probe shows it: its value, or "none" when the engine gave none.
pub(crate) fn shown<T: std::fmt::Display>(part: Option<T>) -> String {
part.map_or_else(|| "none".to_string(), |v| v.to_string())
}
}

/// What a terminal receipt proved the engine did.
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub(crate) enum Terminal {
Expand Down Expand Up @@ -87,6 +124,24 @@ mod tests {
assert_eq!(terminal_receipt(PageAction::Erase, 3, "unused", 500, Some(&valid)), None);
}

// what this catches: the engine's split of a switch (its loop's copy, its worker's IO, fork
// #118) unread, so a live read cannot tell whether a slow switch stalled the other minds' decode
// or only its own disk; an older engine's receipt reads as "none", never as zero.
#[test]
fn engine_work_reads_the_loop_and_io_shares_and_none_from_an_older_engine() {
let streamed = json!({"id_slot": 1, "filename": "p", "n_restored": 84, "n_read": 4096,
"timings": {"restore_ms": 1026.4, "copy_ms": 35.2, "io_ms": 991.2, "admit_ms": 0.5},
"page_io": {"io_bytes": 9000, "io_bytes_in_flight": 9000, "io_budget_bytes": 0}});
let work = EngineWork::of(PageAction::Restore, Some(&streamed));
assert_eq!(work, EngineWork { ms: Some(1026), bytes: Some(4096), copy_ms: Some(35.2), io_ms: Some(991.2),
admit_ms: Some(0.5), in_flight_bytes: Some(9000) });
let older = json!({"id_slot": 1, "filename": "p", "n_saved": 84, "n_written": 4096, "timings": {"save_ms": 2253.0}});
let work = EngineWork::of(PageAction::Save, Some(&older));
assert_eq!((work.ms, work.copy_ms, work.io_ms, work.in_flight_bytes), (Some(2253), None, None, None));
assert_eq!(EngineWork::shown(work.copy_ms), "none");
assert_eq!(EngineWork::of(PageAction::Save, None), EngineWork::default());
}

#[test]
fn erase_support_does_not_weaken_save_or_restore_receipts() {
let erased = json!({"id_slot": 3, "n_erased": 10});
Expand Down
Loading