Before you start: words you need#
| Word | Plain meaning |
|---|---|
| Fragmentation | Memory that is allocated but unused. Internal: reserved inside one allocation but never filled. External: free gaps between allocations too small to use (22.e). |
| Paging / virtual memory | The operating-system idea of splitting memory into fixed-size pages, with a page table mapping each program’s logical pages to wherever they physically are (3.f). |
| KV block | vLLM’s page: the keys and values for a fixed number of tokens (16 by default) for one sequence. |
| Block table | Per-sequence list mapping logical block numbers to physical block numbers in GPU memory. |
| Copy-on-write | Several sequences share one physical block until one of them needs to change it; only then is it copied. |
| Parallel sampling / beam search | Generating several outputs from one prompt. Parallel sampling draws n independent answers; beam search keeps the k best partial answers. Both share the prompt’s KV cache. |
| Preemption | Pausing a running request to free its memory, then resuming it later by swapping its KV cache back from CPU memory or recomputing it. |
1. The paper#
- Title: “Efficient Memory Management for Large Language Model Serving with PagedAttention”
- Authors: Woosuk Kwon, Zhuohan Li, Siyuan Zhuang, Ying Sheng, Lianmin Zheng, Cody Hao Yu, Joseph E. Gonzalez, Hao Zhang, Ion Stoica (UC Berkeley, Stanford, UC San Diego)
- Venue: SOSP 2023 (ACM Symposium on Operating Systems Principles), Koblenz, October 2023.
- Links: arXiv:2309.06180 · DOI 10.1145/3600006.3613165 · code: vllm-project/vllm
The open-source vLLM project was released in June 2023, before the paper. Module 16 onward teaches the 2026 code base in depth; this lesson is about the original argument.
2. The problem#
Continuous batching (Orca, 30.g) lets a server change the batch every step. How big the batch can be is then set by how many requests’ KV caches fit in GPU memory (12.f). On a 13B model the KV cache for one 2048-token sequence is about 1.6 GB.
Existing systems stored each request’s KV cache in one contiguous chunk, reserved up front for
the maximum possible length (Orca reserved max_tokens; FasterTransformer reserved the model’s maximum
length). That wastes memory three ways:
- Reservation: slots for tokens not yet generated.
- Internal fragmentation: slots for tokens that will never be generated, because the request stops early.
- External fragmentation: gaps between chunks of different sizes.
The authors measured that only 20.4%–38.2% of KV cache memory held actual token state in existing systems. And contiguous chunks cannot be shared, so parallel sampling or beam search copy the prompt’s cache for every output.
3. The idea#
Do what operating systems do with RAM: page it.
- Split each sequence’s KV cache into fixed-size blocks (for example 16 tokens).
- Allocate physical blocks on demand, one at a time, as the sequence grows. Blocks need not be contiguous.
- Keep a block table per sequence that maps its logical blocks to physical blocks.
- Write an attention kernel — PagedAttention — that reads K and V through the block table.
Waste is limited to the unfilled part of each sequence’s last block. And because blocks are shared by reference, several sequences can point at the same prompt blocks, with reference counts and copy-on-write when one diverges.
flowchart LR
subgraph L["Logical KV of one request"]
l0["block 0"] --- l1["block 1"] --- l2["block 2 (partly full)"]
end
BT["Block table: 0→7, 1→1, 2→3"]
subgraph P["Physical KV blocks in GPU memory"]
p1["1"]
p3["3"]
p7["7"]
pf["free blocks"]
end
L --> BT --> P
class l0,l1,l2 neutral
class BT queue
class p1,p3,p7 memory
class pf io4. How it works#
- Block manager in the scheduler owns a pool of physical blocks on the GPU (and a CPU pool for swapping). Each step it allocates a new block for any sequence whose last block is full.
- Scheduler: first-come-first-served. When memory runs out, it preempts the most recent requests (all-or-nothing per sequence group) and later restores them by swapping blocks back from CPU or by recomputing their KV from the tokens. Recomputation was often faster for short sequences.
- Kernels: PagedAttention adapted FasterTransformer’s attention kernel to gather K and V through the block table. Also fused block-copy and block-write kernels.
- Sharing: parallel samples share the prompt’s blocks; beam candidates share most of their blocks and copy-on-write only when needed; requests with a common system prompt can map the same prefix blocks.
- Distributed: Megatron-style tensor parallelism (30.c); every GPU worker shares the same block table, with each holding its heads’ slice of every block.
- Block size trade-off: smaller blocks waste less memory but make the kernel slower; 16 was a good default.
5. Results#
Hardware: A100 GPUs on Google Cloud; OPT-13B, 66B and 175B and LLaMA-13B; traces built from ShareGPT (long conversations) and Alpaca (short instructions).
| Measure | Result |
|---|---|
| Throughput at similar latency, ShareGPT, vs Orca (Oracle) | 1.7×–2.7× higher request rate |
| Same, vs Orca (Max) | 2.7×–8× |
| vs FasterTransformer | up to 22× |
| Requests batched at once, OPT-13B, ShareGPT | 2.2× Orca (Oracle), 4.3× Orca (Max) |
| Memory saved by sharing, Alpaca | 6.1%–9.8% (parallel sampling), 37.6%–55.2% (beam search) |
| Attention kernel overhead from the block table | 20–26% slower than FasterTransformer’s kernel |
How to read the Orca numbers. Orca was not open source, so the authors built three versions of it inside their own system that differ only in how much they reserve: Oracle (knows each output length in advance — impossible in practice), Pow2 (reserves up to 2× the true length) and Max (reserves the maximum). “1.7×–2.7× over Orca (Oracle)” means paging beat even a perfect-knowledge reservation, because of fragmentation and sharing.
The kernel is slower in isolation; the system is much faster overall because the batch is bigger. That trade — a slightly slower kernel for a much better batch — is the paper’s central lesson.
6. What held up and what did not#
Held up
- Paged KV caches are universal. vLLM, SGLang, TensorRT-LLM, Hugging Face TGI (now archived), llama.cpp’s server and others all page KV memory. Attention kernels (FlashAttention, FlashInfer) all accept block tables.
- Blocks as the unit of everything. Prefix caching (12.m), KV offloading to CPU and SSD (14.k), and KV transfer between prefill and decode machines (14.j, 30.w) all move and hash blocks.
- vLLM itself became the most widely used open-source LLM engine, and a PyTorch Foundation project.
Did not, or changed
- Swapping lost to recomputation. vLLM’s V1 engine dropped swapping altogether; a preempted request is recomputed (17.c).
- Prefix sharing grew from the paper’s hand-specified shared prefixes into automatic, hash-based prefix caching, on by default in vLLM (17.f) — and into SGLang’s radix tree (30.r).
- The kernel overhead was engineered away. Modern paged kernels lose little or nothing to contiguous ones.
- One block type was not enough. Hybrid models (sliding window, linear attention, Mamba layers, MLA) need several kinds of cache; vLLM’s hybrid KV cache manager handles them (17.i).
- A counter-argument: vAttention (Prabhu et al., 2024) keeps the KV cache virtually contiguous with CUDA virtual-memory APIs, so unmodified kernels can be used. It is an alternative, not the mainstream.
7. Where it lives in 2026#
- Taught in depth: PagedAttention in 12.l; the vLLM block pool in 17.e, slot allocation in 17.g, cache sizing in 17.h, prefix caching in 17.f; why vLLM exists in 16.a.
- vLLM v0.32.0 (18 October 2026) is the latest stable release; the default block size is still 16 tokens, though some backends and hybrid models choose larger blocks.
Checked on 13 November 2026.
8. Questions#
- List the three kinds of KV memory waste in contiguous allocation.
- What is a block table, and how does the attention kernel use it?
- Why does paging make parallel sampling and beam search cheaper?
- The PagedAttention kernel was 20–26% slower, yet vLLM was 2–4× faster. Explain.
- What is “Orca (Oracle)”, and why does beating it matter?
- When memory runs out, what can the scheduler do? Which option is usually faster, and why?
- What does block size trade off?
9. Further reading#
- arXiv:2309.06180 — sections 3 and 4.
- Prabhu et al., “vAttention: Dynamic Memory Management for Serving LLMs without PagedAttention” (2024).
- vllm-project/vllm on GitHub.
- 12.l and Module 17 in this material.
- Next: StreamingLLM (30.p).