What problem does PagedAttention solve, and how does it work?
Type it the way you would explain it to an interviewer. A few sentences is enough; you can't break anything.
Model answer: the part to lead with
It solves KV-cache memory fragmentation. Pre-vLLM systems allocated each sequence's KV cache as one contiguous buffer sized for the maximum possible length (since output length is unknown in advance). That wastes memory three ways: internal fragmentation (a sequence that stops at 300 tokens reserved 2048), reservation waste (memory held for tokens not yet generated), and external fragmentation (variable-sized contiguous chunks leave unusable gaps). The vLLM paper measured that in prior systems only ~20-40% of KV memory held actual token state. Since KV memory caps batch size and batch size is throughput, this waste was directly throttling serving.
Full worked answer with diagram
It solves KV-cache memory fragmentation. Pre-vLLM systems allocated each sequence's KV cache as one contiguous buffer sized for the maximum possible length (since output length is unknown in advance). That wastes memory three ways: internal fragmentation (a sequence that stops at 300 tokens reserved 2048), reservation waste (memory held for tokens not yet generated), and external fragmentation (variable-sized contiguous chunks leave unusable gaps). The vLLM paper measured that in prior systems only ~20-40% of KV memory held actual token state. Since KV memory caps batch size and batch size is throughput, this waste was directly throttling serving.
PagedAttention applies the OS virtual-memory playbook: chop the KV cache into fixed-size blocks (e.g., 16 tokens each), allocate them on demand from a shared pool, and give each sequence a block table mapping logical positions → physical blocks. The attention kernel walks the block table, so blocks needn't be contiguous. Consequences:
- Waste collapses to at most one partially-filled block per sequence - near-100% utilization, so effective batch size (and throughput) jumps; the paper reported ~2-4× throughput over the prior state of the art.
- Sharing becomes trivial: multiple sequences can map the same physical blocks. Parallel sampling (n candidates from one prompt) and shared system-prompt prefixes are handled with block sharing + copy-on-write when a shared block would be written.
- Preemption is clean: under memory pressure the scheduler evicts a sequence's blocks (recompute or swap to CPU) and restores later.
The mental model to say out loud: virtual memory and paging for the KV cache - block table = page table, block = page, fragmentation fixed the same way OSes fixed it in the 1960s. Follow-on work (vLLM's prefix caching, SGLang's RadixAttention) builds cross-request reuse on top of this block abstraction.
Worth sketching. Draw two block tables pointing at one shared block and the sharing story tells itself, no paper needed for the analogy.
flowchart LR
S1["Seq A: shared system prompt<br/>then its own turns"] --> T1["Block table A"]
S2["Seq B: same system prompt"] --> T2["Block table B"]
T1 --> P0["Physical block 7"]
T1 --> P1["Physical block 12"]
T2 --> P0
T2 --> P9["Physical block 3"]
P0 --> POOL["Shared pool, copy-on-write<br/>if a shared block is written"]
What a good answer covers
- It solves KV-cache memory fragmentation
- Pre-vLLM systems allocated each sequence's KV cache as one contiguous buffer sized for the maximum…
- That wastes memory three ways
- The vLLM paper measured that in prior systems only ~20-40% of KV memory held actual token state
- Since KV memory caps batch size and batch size is throughput, this waste was directly throttling serving
Key terms: KV-cache memory fragmentation · PagedAttention · blocks · block table · Sharing becomes trivial · Preemption is clean
In the glossary: KV cache · vLLM · PagedAttention · Prefix caching · SGLang · RadixAttention
Interviewer follow-ups to expect
What's the cost of paging - why not make blocks 1 token each?
PagedAttention applies the OS virtual-memory playbook: chop the KV cache into fixed-size blocks (e.g., 16 tokens each), allocate them on demand from a shared pool, and give each sequence a block table mapping logical positions → physical blocks. The attention kernel walks the block table, so blocks needn't be contiguous. Consequences:
- Waste collapses to at most one partially-filled block per sequence - near-100% utilization, so effective batch size (and throughput) jumps; the paper reported ~2-4× throughput over the prior state of the art.
- Sharing becomes trivial: multiple sequences can map the same physical blocks. Parallel sampling (n candidates from one prompt) and shared system-prompt prefixes are handled with block sharing + copy-on-write when a shared block would be written.
- Preemption is clean: under memory pressure the scheduler evicts a sequence's blocks (recompute or swap to CPU) and restores later.
How does copy-on-write work for beam search or n-best sampling?
Worked answer from AI-Engineer-Interview-Questions by Om (MIT), reformatted for LLM Prep · answer text last updated 6 November 2026 · scoring and review schedule by LLM Prep