place: the caching layer -- hot VRAM cache, deposits, copyless relabels

Routing-aware reads leave a routed expert's bytes on the drive when the
pass routes nothing to it, but the reads that DO happen still have two
wasteful fates: they land in a per-pass buffer thrown away at the next
layer, and they cross the link even when the same bytes already sit in a
host pool slot that just went cold. This commit gives both bytes
somewhere to stay.

The hot VRAM cache: a routed expert whose read heat ranks past the
admission bar lands in a shadow slab slot and stays there. The slot is
its address from then on, until heat evicts it -- eviction is a copyless
relabel (back to Tier::SSD, publish null); the container is ground
truth. The planner budgets the shadow slots for it (per-class on_disk
count); the mover admits (Kind::Admit), evicts, and retires the
admissions.

Deposits: a free pool slot takes the O_DIRECT read directly -- the
read's destination IS the slot -- and the unit becomes a pool unit the
GEMM reads zero-copy, with heat promoting it at PCIe speed later. Its
demotion is a copyless drop (the slot still holds the bytes). A full
pool evicts its coldest unrouted unit by relabel, copyless, and the
freed slot feeds the next deposit.

The counters follow the traffic: the file stager's family is renamed
file_* -> ssd_* (ssd_layers, ssd_units, ssd_read_bytes, ssd_preads,
ssd_read_ns, ssd_wait_ns) beside the existing ssd_reads/ssd_bytes, and
the new legs are counted (ssd_staging_bytes, ssd_promotions and
ssd_promoted_bytes, ssd_deposits and ssd_deposit_bytes, pool_evictions).
The dashboard's expert plane gains the matching staging, promotions and
deposits rows, and --weights-disk-tier's help text names the tier.

Measured on GLM-5.3-Flash TP2 (2x Radeon R9700), 250-token essay at
temp 0: 5.49 tok/s at ~104 GiB of SSD reads per run, against main's
2.05 tok/s at ~378 GiB.

Assisted-by: GLM-5.3-Flash
This commit is contained in:
overchop authored and StillDeadcode committed 2026-10-30 15:02:09 +01:00
1 parent 9efdd00c4c
commit 8da043c246
13 files changed
+485 -73

No files matched your search

+35
View File
@@ -82,6 +82,15 @@ struct HeatParams {
* `hot >= cold*hysteresis + 1.5`, which against a zero-heat victim is two tokens agreeing in
* one dispatch; a warmup only delays convergence. */
int warmup_dispatches = 0;
/* The hot VRAM cache's admission bar: the heat at which the file stager
* may read a routed expert into a slab slot permanently instead of its per-pass buffer.
* Absolute, not relative to a victim: admission happens when the unit is read anyway, and the
* shadow slots are the budget. A value near min_gain (1.5) admits anything routed twice
* lately and churns; 8 is roughly two consistently-routed steps of the verify union at
* MTP-d3, well above an occasional expert's credit of one or two. Eviction is free (the
* container is ground truth), so the cost of an admission mistake is one future re-read. */
float admit_heat = 8.0f;
};
/* A promotion and its matching demotion. The mover issues two transfers, but they are decided
@@ -249,6 +258,28 @@ public:
}
bool busy(int32_t unit) const { return busy_[(size_t)unit] != 0; }
/* ---- the hot VRAM cache ----------------------------------------------
*
* A unit the file stager admitted keeps heat's history and, while resident, joins the
* demotion ranking as an evictable victim — but never the promotion ranking: its admission
* is the stager's own decision (it is read anyway; the slot is the only extra cost), and
* once evicted it has no address to promote from (the container, read by the stager).
*
* set_evictable marks a unit the mover has admitted or may admit. admit_hot is the
* admission test: heat past the bar and not already in flight. */
void set_evictable(int32_t unit, bool evictable);
/* A deposit's plan says Tier::SSD -- non-movable --
* but its pool slot makes it a PCIe-speed promotion candidate all the same. The deposit
* flips movability here, keeping the plan's word for everything else. */
void set_movable(int32_t unit, bool movable);
bool evictable(int32_t unit) const { return evictable_[(size_t)unit] != 0; }
bool admit_hot(int32_t unit) const {
return enabled_ && unit >= 0 && (size_t)unit < tier_.size() &&
tier_[(size_t)unit] == Tier::SSD && !busy_[(size_t)unit] &&
pos_[(size_t)unit] >= 0 &&
heat_[(size_t)pos_[(size_t)unit]] >= params_.admit_heat;
}
/* The best swap available, or false when the guards refuse. */
bool pick(Swap* out) const;
@@ -317,6 +348,10 @@ private:
* lock-free and the mirror one byte per unit. */
TierMirror tier_pub_;
std::vector<uint8_t> busy_;
/* Per unit, whether heat may rank it as a demotion victim though the plan called it
* unmovable: the mover admitted it into the hot VRAM cache. Never a
* promotion candidate: with no pool slot, only the stager can bring the unit back. */
std::vector<uint8_t> evictable_;
std::vector<uint8_t> movable_;
/* --expert-pin-top: a decode-hot resident the planner pinned is never a demotion candidate,
* even where a later pass made its unit movable again. */