Archived
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:
1 parent
7d392b0400
commit
4be0a34791
16 files changed
+205
-39
No files matched your search
+28
-2
@@ -44,6 +44,7 @@
|
||||
#include <memory>
|
||||
#include <string>
|
||||
#include <unordered_map>
|
||||
#include <unordered_set>
|
||||
#include <vector>
|
||||
|
||||
namespace rad {
|
||||
@@ -253,9 +254,24 @@ public:
|
||||
/* The off-device entries this prompt's chain would hit if restored, in order, from where
|
||||
* lookup stopped. The caller promotes them and looks up again; empty means the prefix ended
|
||||
* on a miss or token mismatch. Separate from lookup because lookup is const and has no
|
||||
* device; a promotion allocates blocks and runs a scatter between steps. */
|
||||
* device; a promotion allocates blocks and runs a scatter between steps.
|
||||
*
|
||||
* `fit` is how many entries the pool can take. A longer chain is cut, and counted
|
||||
* (Stats::restore_cuts): with recurrent state at the deepest snapshot the shorter prefix
|
||||
* reaches, since the hit resumes there and blocks past it would come back for nothing;
|
||||
* without, at `fit`. */
|
||||
std::vector<BlockHash> restorable_from(const std::vector<int32_t>& tokens,
|
||||
const std::vector<MMContentKey>& mm) const;
|
||||
const std::vector<MMContentKey>& mm,
|
||||
int64_t fit = INT64_MAX) const;
|
||||
/* Entries a restore can place now: free blocks against the carve, the least over the cached
|
||||
* groups. Lent blocks count, since KVManager::reserve_blocks recalls the loan for them. */
|
||||
int64_t restore_room() const;
|
||||
/* Room for a restore of this prompt's chain: trim(), sparing the chain itself (its blocks
|
||||
* would only have to come back too) and every chain a waiting request holds (hold()), whose
|
||||
* next attempt would restore it again. Nothing is lost; the reserve's trim after the next
|
||||
* publish puts the pool's free quarter back. */
|
||||
int64_t trim_for(const std::vector<int32_t>& tokens, const std::vector<MMContentKey>& mm,
|
||||
int64_t n_blocks);
|
||||
|
||||
/* The tiers lost the bytes. Erases the entry without releasing blocks: an off-device entry
|
||||
* owns none, and its recorded ids now belong to other sequences. Installed as
|
||||
@@ -341,6 +357,8 @@ public:
|
||||
int64_t drops = 0;
|
||||
/* Entries and snapshots removed by --prefix-cache-ttl, from any tier. */
|
||||
int64_t expired = 0, ckpt_expired = 0;
|
||||
/* Restores from the host tier cut short because the pool could not hold the chain. */
|
||||
int64_t restore_cuts = 0;
|
||||
};
|
||||
const Stats& stats() const { return stats_; }
|
||||
|
||||
@@ -376,6 +394,9 @@ private:
|
||||
const std::vector<MMContentKey>& mm,
|
||||
int64_t n_blocks) const;
|
||||
void touch(const BlockHash& h, uint64_t now_ns) const;
|
||||
/* trim(), leaving the entries in `spare` (when given) where they are. */
|
||||
int64_t trim_sparing(int64_t n_blocks,
|
||||
const std::unordered_set<BlockHash, BlockHashHash>* spare);
|
||||
/* A live sequence also holds one of this entry's blocks, so releasing it frees nothing. */
|
||||
bool shared_with_live(const Entry& e) const;
|
||||
/* Whether `e` holds the block_size_ token ids at `src`, so a hash collision is a miss. */
|
||||
@@ -396,6 +417,11 @@ private:
|
||||
/* For the debug lines: whether `c` is its session's deepest snapshot, and seconds since a
|
||||
* monotonic stamp. */
|
||||
bool is_tip(const Ckpt& c) const;
|
||||
/* The deepest valid snapshot on the chain `hs` at or below `limit` tokens; end() if none.
|
||||
* Checkpoints sit on any block boundary (the interval or a prompt's tail), so this walks the
|
||||
* snapshots, a few hundred, rather than the chain's blocks. */
|
||||
std::unordered_map<BlockHash, Ckpt, BlockHashHash>::iterator
|
||||
deepest_ckpt(const std::vector<BlockHash>& hs, int64_t limit) const;
|
||||
static double idle_s(uint64_t used_ns);
|
||||
|
||||
KVManager* kv_ = nullptr;
|
||||
|
||||
Reference in new issue
Block a user