Key points
- KV cache problem in LLMs: Transformer models store Key/Value pairs for every processed token to maintain context. Because output length is unknown ahead of time, traditional systems must pre-allocate contiguous memory per sequence. Over-allocating wastes memory; under-allocating triggers expensive reallocation. Fragmentation can waste 60–80% of GPU memory.
- Core idea — borrow OS virtual memory: The vLLM team adapted classical paging into the GPU. Memory is divided into fixed-size blocks (commonly 16 tokens per block). A per-sequence block table records the physical location of each block, so the GPU no longer needs contiguous space.
- Results: Near-100% GPU utilization, roughly 2× serving throughput on the same hardware, and elimination of internal/external fragmentation.
- Parallel sampling and copy-on-write: When multiple beams or samples share a common prompt prefix, they can share the same physical KV blocks. New blocks are allocated only when the sequences diverge — the same *copy-on-write* semantics used by operating systems.
- Engineering insight: PagedAttention does not change transformer math. It is a memory-management technique that reframes LLM serving as a systems problem with a 40-year-old solution.
Why it matters
PagedAttention turns the KV cache from a rigid, contiguous slab into a flexible collection of small pages. The block table acts as a lightweight directory, letting the attention kernel gather scattered blocks on the fly. This makes high-throughput LLM serving practical on commodity GPUs and underpins the vLLM inference engine.
Reference
Paper: Kwon et al., *Efficient Memory Management for Large Language Model Serving with PagedAttention* (SOSP 2023). Project: https://blog.vllm.ai/