paged-attention -- a KV cache in blocks, not slabs

A chat service has to keep, for every conversation it is holding open, the notes the model made while reading everything said so far. Give each conversation one solid stretch of memory big enough for the longest reply it might write and most of that stretch sits empty, while the leftovers between conversations are too small for anyone else to use. Handing out small fixed-size chunks instead means only the last chunk of a conversation is part-empty, and two people whose conversations opened with the same instructions can point at the very same chunks until their wording diverges. What it costs is bookkeeping: a lookup table per conversation saying where its chunks actually are.

Interactive page: why a serving runtime stores the KV cache in fixed-size blocks with a per-sequence block table, instead of one contiguous slab per sequence -- and how two sequences that start with the same prompt end up pointing at the same physical blocks. Anchor: J1 serving-time KV-cache memory management (the paged-attention / block-table idea popularized by vLLM), sitting on top of the kv-cache page's per-token cache math.

What it shows

Two strips over the same 96-cell memory pool, so the counter under each is directly comparable.

Interactions

TransportAuto-plays + loops a decode. Each step appends one token to one sequence; a new physical block is allocated only when the current one fills, and the step label says which.
Direct manipulationDrag the ◂▸ grip on the block-size bar (2 → 8 tokens) and drag a reservation boundary in the contiguous strip. The allocation, the block tables, the arrows and both waste counters recompute under your hand.
HoverAny pool cell → which sequence and logical position it holds, or "reserved by S*i*, empty", or free / fragmented tail. Any paged block → its owner, logical block and slot, its slack, or "free -- any sequence can take it". Any block-table entry → the physical block it points at and whether that block is shared.
Resize the problemSequence count (2-4), block size, reservation size, prefix sharing on/off.
A/B compareCoarse 8-token blocks vs fine 2-token blocks, side by side.
ChallengesDrive paged waste to ≤ 3 cells; get 2+ shared blocks.

Render tier

T1 (Canvas2D). The lesson is allocation topology, not pixel throughput -- a few hundred cells and a fan of arrows, so the floor tier teaches it and nothing is gained by reaching higher.

Wiring

layout.mount + controls (blocksize, seqs, reserve, share) + a step Transport whose compute simulates prefill and decode and snapshots the allocation after every token (lens[i], alloc[i][L] = physical block). Everything drawn with render.label/arrow + ctx, coloured with theme.js tokens only (categorical per sequence, T.violet for shared, T.bad hatching for waste), so it reads in light and dark. Headless hooks mirroring the drag state: ?blocksize=8&seqs=3&reserve=20&share=0, plus ?step=N, ?hover=x,y, ?play=1. Source: page.js.

Data

None fetched -- the allocation is simulated in-page from a fixed pool of 96 token slots, a deterministic free list, and per-sequence prompt lengths. Same numbers on every reload, no download, no weights.