kv tiers: a restore makes room the way pressure does, and a chain the pool cannot hold stops at a snapshot

A restore reserved only from the free list. The reserve's trim leaves a quarter of the pool free
after every publish, so a returning conversation larger than that came back as far as the free
list reached, and the lookup stopped at the first block still on the host. On GLM-5.3-Flash at
eight ranks, two conversations of 314K tokens in a 446,832-token pool: the second turn of the
first brought back exactly the 27,930 free blocks, hit 111,772 tokens, and on its hybrid state
resumed at the snapshot at 1,024, since geometric backoff keeps nothing between 1,024 and 131,072.
Its prefill took 84 s instead of under one.

PCBinding::restore_plan now makes room before the engine plans the restore, the same way
PCBinding::evict does for an admission: PrefixCache::trim_for drops entries whose host copy has
landed, the engine lands pending copies (flush_fn), and it drops again. It never erases one,
spares the restoring chain itself and every chain a waiting request holds, and like trim never
touches one a running sequence reads. The free quarter may go; the reserve's trim after the next
publish frees it again. One block table serves every rank, so the room rank 0's cache makes is
room on every rank, as with evict.

When the pool still cannot hold the chain, PrefixCache::restorable_from cuts it at the deepest
valid snapshot the shorter prefix reaches, so no block comes back past the point the hit resumes
from; without recurrent state it cuts where the room ends. TierExec::issue_restore keeps its own
cut as the backstop.

Both cuts are counted: radiance:prefix_restore_cuts_total for restores the pool could not hold
whole (/sessions moved.restore_cuts), and radiance:prefix_hit_cuts_total{reason="resumed_below"}
for admissions that resumed more than one checkpoint interval below their attention hit, which
hit_cut_tokens alone did not tell apart from many small tails (/stats and /sessions hit_cuts).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
NunzeandClaude Opus 5.5 authored and StillDeadcode committed 2026-10-21 15:24:20 +02:00
1 parent 7d392b0400
commit 4be0a34791
16 files changed
+205 -39

No files matched your search

+5 -4
View File
@@ -1479,13 +1479,14 @@ int Engine::serve(std::unique_ptr<StallWatch> watch) {
auto* b = static_cast<PCBinding<PrefixCache>*>(pc_iface_.get());
/* Called inside Scheduler::step() under its lock, which makes touching the cache and rank
* 0's manager safe; nothing here may call back into the scheduler. */
b->restore_fn = [this](const Request& req) {
b->restore_fn = [this, b](const Request& req) {
const uint64_t t0 = rad_mono_ns();
PrefixCache& pc = ranks_[0]->prefix;
std::vector<MMContentKey> mk;
media_keys(req, &mk, cvec_salt_for(req.sp.use_control_vector));
/* Room is made before anything is planned (PCBinding::restore_plan): a chain the free
* list cannot hold would otherwise come back only as far as it reaches. One block
* table serves every rank, so what rank 0's cache gives up is room on every rank. */
const std::vector<BlockHash> want =
pc.restorable_from(req.prompt, mk);
b->restore_plan(req, cvec_salt_for(req.sp.use_control_vector));
if (want.empty()) return;
/* The whole chain in one restore. With 4-token blocks a long conversation is tens of
* thousands of entries; batched, it is one launch per (group, layer) per staging batch