All glossary terms

Serving

Paged attention

KV cache memory managed in small blocks instead of one slab per request, the way an operating system pages RAM. Wasted reservations become room for more users.

Naive serving reserves the worst case: for every accepted request, memory for the longest context you allow, held from arrival to finish. Actual conversations are much shorter than the maximum most of the time, so a large share of reserved cache is simply idle while a request lives, and a tenth request gets rejected even though most of the memory is unused.

Paged attention applies the classic OS solution. Cut the cache into fixed-size blocks (say 16 tokens each) and give a request as many blocks as it currently needs, adding more as its context grows. Sequences of the same conversation can also sit in non-contiguous blocks, because attention gathers from a block table instead of assuming one contiguous slab.

The waste stops being tens of percent of a worst-case reservation and becomes at most one block per sequence. That is the whole idea, and it is why serving stacks built on this approach accept far more concurrent users on the same memory. The number to remember is utilization: reserved versus actually in use.

The block table also has to be managed, which adds bookkeeping and fragmentation questions of its own. In interviews the useful framing is the analogy: paged attention is virtual memory for the KV cache, and the same trade (more utilization, more pointer chasing) appeared there first.

A worked example

Ten requests, each reserving its worst case of 4,096 tokens of KV cache up front, on a model whose cache costs 160 KiB per token (40 layers, fp16). 16-token blocks are available.

  1. Worst-case reservation: 4,096 x 160 KiB = 640 MiB per request, 6.25 GiB for all ten.
  2. The conversations actually average 1,200 tokens: 1,200 x 160 KiB = 187.5 MiB in real use.
  3. Utilization: 187.5 / 640 = 29 percent. Of the 6.25 GiB reserved, about 4.4 GiB does nothing.
  4. With 16-token blocks the tail waste is at most 15 unused slots x 160 KiB = about 2.3 MiB per request instead of hundreds of MiB.

Paged blocks turn a 29 percent-utilized slab into near-full utilization, so the same memory hosts several times more concurrent users.

Where this shows up

Test yourself

Related terms