firehose> #llmops

KV Cache Fragmentation

Once you accept the KV Cache's memory-for-compute trade, the question becomes how to store a cache for many concurrent requests of wildly different, unknown-in-advance lengths. A naive serving stack answers by pre-allocating one contiguous VRAM block per request, sized to the maximum possible output length — reserving an entire hotel floor for a single guest. Three distinct wastes follow, and they are worth separating because they have different cures:

This taxonomy is the diagnosis that makes Paged Attention legible as the cure: paging attacks internal fragmentation (pages are 16 tokens, so the tail waste is bounded by a page), external fragmentation (pages need not be contiguous), and duplication (a block table lets two requests point at one physical page) with a single mechanism. The lesson generalizes past LLMs: fragmentation is what you get when you allocate for the worst case a request might reach rather than the size it has. Operating systems learned this in the 1960s.

Claims


Linked from