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

+16 -4
View File
@@ -746,26 +746,38 @@ int Planner::assign_expert_tiered(Plan* p) {
}
/* Slots used per class, which sizes the spares. A static plan reserves no shadow slots. */
std::vector<int64_t> resident(p->classes.size(), 0), staged(p->classes.size(), 0);
std::vector<int64_t> resident(p->classes.size(), 0), staged(p->classes.size(), 0),
on_disk(p->classes.size(), 0);
for (const MoveUnit& mu : p->units) {
if (mu.slab_class < 0) continue;
if (mu.movable && mu.tier == Tier::VRAM) ++resident[(size_t)mu.slab_class];
if (mu.tier == Tier::SSD) ++on_disk[(size_t)mu.slab_class];
/* The staging ring is slab memory too. finish() sizes it from the staged units,
* known only after the fill, so it is reserved the same two-pass way as the shadow
* slots. Routed file-tier units are excluded; the file stager has its own buffers. */
if (mu.site == Site::DeviceStaged && mu.access != RAD_ACCESS_CONDITIONAL)
++staged[(size_t)mu.slab_class];
}
/* The hot VRAM cache's budget: with file-tier units in a class, the shadow slots
* may be filled with hot experts — read a routed expert into a shadow slab slot
* permanently, instead of the stager's per-pass buffer, when heat says the expert
* keeps routing. Eviction is bookkeeping (the container is ground truth). The
* budget is the full shadow cap rather than the swap formula's resident/4 share.
* Bounded by the class's residents so the two-pass fill converges — a later pass
* with fewer residents reserves fewer — and charged to the weights budget through
* k.spare like any shadow slot. */
for (size_t c = 0; c < p->classes.size(); ++c) {
const int64_t ring = std::min<int64_t>(RAD_PLACE_STAGE_RING, staged[c]);
const int64_t shadow = (p->dynamic && resident[c] > 0)
? std::min<int64_t>(RAD_PLACE_SHADOW_SLOTS, std::max<int64_t>(1, resident[c] / 4))
: 0;
p->classes[c].n_shadow = shadow;
if (shadow + ring <= 0) continue;
const int64_t hot = (p->dynamic && on_disk[c] > 0 && resident[c] > 0)
? std::min<int64_t>(RAD_PLACE_SHADOW_SLOTS, resident[c]) : 0;
p->classes[c].n_shadow = std::max(shadow, hot);
if (p->classes[c].n_shadow + ring <= 0) continue;
/* Plus the slab's tail pad: a kernel assembling a packed code window from a wide read
* reads a few bytes past the last slot, which would fault at the allocation's end. */
k.spare += (shadow + ring) * p->classes[c].stride + RAD_ALIGN_UNIT;
k.spare += (p->classes[c].n_shadow + ring) * p->classes[c].stride + RAD_ALIGN_UNIT;
}
/* The file stager's two buffers, each the largest routed layer's file-tier units at the