Each request carries KV state that grows as tokens are generated, but the server does not know the final answer length at admission. The earlier systems evaluated in the PagedAttention paper reserved one contiguous region for the maximum sequence length. That reserved capacity could remain unused while other requests waited for memory.
PagedAttention, introduced by Kwon et al. with vLLM at SOSP 2023, replaced that reservation with the trick operating systems use for RAM: fixed-size pages handed out on demand. This guide explains blocks and block tables, sharing and copy-on-write, where the design costs you, and why block-level KV management makes prefix caching and KV cache offloading practical.
What is PagedAttention?
PagedAttention is an attention algorithm and KV cache memory-management technique, introduced by Kwon et al. with the vLLM serving engine at SOSP 2023. It splits each request’s KV cache into fixed-size blocks that can sit anywhere in GPU memory and tracks them with a block table, borrowing virtual memory and paging from operating systems.
Much of the gain comes from allocating memory as requests need it. Paged attention changes where keys and values live without changing the attention calculation. That distinction is central to Efficient Memory Management for Large Language Model Serving with PagedAttention, the original vLLM paper. You will also see the technique spelled “paged attention” or “page attention”.
Why contiguous KV cache allocation wastes GPU memory
The KV cache holds earlier tokens’ keys and values so decode can use them without recomputing them. In the original OPT-13B example, that state occupied 800 KB per token and up to 1.6 GB per request. A request-level allocation policy therefore has a substantial effect on how many requests fit.
Reserving one contiguous region for the maximum possible sequence length commits memory before the server knows how much a request will use. Picture a server without PagedAttention, capped at 4,096 tokens per request. A 400-token support question gets a 200-token answer: it uses 600 slots, but the other 3,496 remain reserved throughout the request. Shorter requests can’t borrow that unused capacity while they wait.
That reservation policy loses capacity in three different ways:
| Waste | What it is | When you find out |
|---|---|---|
| Reserved slots | Space held for tokens not generated yet | Used eventually, blocked meanwhile |
| Internal fragmentation | Space for the maximum possible length that the request never fills | Only after the request finishes |
| External fragmentation | Gaps the allocator leaves between differently sized chunks | Before serving; never used for generated tokens |
Kwon et al.’s profiling found that actual token state occupied only 20.4% to 38.2% of the KV memory in the earlier systems they measured. The rest couldn’t contribute to batching more work. Compaction could address gaps, but moving such large caches during latency-sensitive serving was impractical in their assessment.
How PagedAttention works: blocks, block tables, and the OS analogy
KV blocks: fixed-size pages of keys and values
Paged attention divides a sequence’s KV state into equal-size blocks, each with capacity for a fixed number of tokens. The original implementation maintained blocks and tables separately for each attention head and layer. Its 16-token default balanced two costs: very small blocks underuse GPU parallelism, while large blocks leave more unused space at the end of a sequence.
Logical blocks, physical blocks, and the block table
A request sees its cache as a run of logical blocks filled left to right. The block table, a per-request lookup table, maps each one to a physical block anywhere in GPU memory and records how many slots are filled. At prefill, the engine reserves only the blocks the prompt needs; the paper’s example maps logical blocks 0 and 1 to physical blocks 7 and 1. During decode, a new physical block is allocated only when the last one is full, which is demand paging in miniature.
Why unused space stays in the final block
A sequence fills its blocks in order, leaving unused capacity only in its final block. Equal-size physical blocks also avoid the gaps caused by differently sized contiguous allocations. Rerun the support question with 16-token blocks: 600 tokens occupy 37 full blocks plus 8 slots in a 38th. Only 8 slots remain unused, instead of the 3,496 held by a worst-case reservation.
In vLLM’s June 2023 launch report, earlier systems wasted 60% to 80% of memory while PagedAttention’s waste was under 4%. These are launch-blog figures, distinct from the paper’s profiling results.
How the attention kernel reads scattered blocks
Attention can read scattered blocks without changing the result. The kernel uses the request’s block table to locate each portion of KV state, computes scores between the query and that block’s keys, and combines those scores with the values. The calculation spans the same tokens; address lookup replaces the requirement that their cached state occupy one contiguous region.
In the OS analogy, each request owns a logical address space for its tokens, while the engine decides where the corresponding KV blocks occupy physical memory. The block table connects the two.
| Operating system concept | PagedAttention equivalent |
|---|---|
| Page | KV block holding a fixed number of tokens |
| Page frame | Physical KV block in GPU memory |
| Page table | Block table, one per request |
| Process | Request (sequence) |
| Byte | Token |
| Demand paging | New block allocated only when the last one fills |
| Copy-on-write on fork | Block-level copy-on-write when a shared block is written |
| Swapping to disk | Swapping a preempted request’s blocks to CPU memory |
Two samples from one 40-token prompt share its first two physical blocks at reference count 2; when sample A1 writes into the shared third block, it gets a copy first. Concept adapted from Kwon et al., SOSP 2023.

Memory sharing and copy-on-write
Two requests can reference one physical block while its contents stay identical. A reference count records how many sequences use it. Before one sequence writes into a shared block, the engine copies that block and updates the sequence’s table, leaving the other references intact. This is copy-on-write at block granularity, like separating a modified page after a process fork.
Parallel sampling is the simplest case. Ask for two completions of a 40-token prompt with 16-token blocks, and both samples map to the same three physical blocks: #5 and #11 are full, #2 holds the last 8 prompt tokens, and each has a reference count of 2. When sample A1 writes its first generated token into #2, the engine sees the count above 1 and copies #2 into a fresh block #8. It points A1’s table at #8 and drops #2’s count to 1. Sample A2 then writes into #2 directly.
Beam search uses the same bookkeeping as prefixes grow and branches diverge. A block is freed once no sequence references it; a write into a shared block copies only that block. New requests can also map logical blocks onto a predefined prefix’s cached physical blocks, with the partial final block protected by copy-on-write. Shared state stays shared until a write requires a private copy.
Savings depend on the workload. In Kwon et al.’s OPT-13B experiments with the Alpaca trace, block sharing saved 6.1% to 9.8% of memory for parallel sampling and 37.6% to 55.2% for beam search. On ShareGPT, with prompts averaging 8.4 times longer, the corresponding savings were 16.2% to 30.5% and 44.3% to 66.3%. Those are results for the paper’s workloads and decoding configurations.
What PagedAttention changed: throughput, vLLM, and wider adoption
Denser memory supports bigger batches. Kwon et al.’s original evaluation reported 2-4x higher throughput at comparable latency against FasterTransformer and Orca, with larger benefits for longer sequences, larger models, and more complex decoding. The setup used OPT-13B through OPT-175B and LLaMA-13B on NVIDIA A100 GPUs, ShareGPT and Alpaca traces, and the authors’ own Orca build. The launch blog’s up-to-24x result used a different baseline: Hugging Face Transformers, with LLaMA-7B on an A10G and LLaMA-13B on a 40 GB A100, using ShareGPT request lengths.
The design spread beyond vLLM, the serving engine built around PagedAttention. Hugging Face TGI adopted custom CUDA kernels from the vLLM project for its paged KV implementation. Li et al.’s 2024 serving survey identified paged KV management across TGI, vLLM, and TensorRT-LLM. That memory layout supports the scheduling and batching work above it.
The block-management idea persists as kernel implementations evolve. vLLM’s Paged Attention design page is historical and doesn’t describe the current code, so use it to understand the original approach rather than as a guide to today’s implementation.
PagedAttention vs. FlashAttention
They solve different problems, and engines can use both. FlashAttention (Dao et al., 2022) tiles the attention calculation to reduce transfers between GPU HBM and on-chip SRAM while computing exact attention. PagedAttention addresses the allocation and lookup of cached keys and values. One reduces data movement during computation; the other lets that state occupy separately allocated blocks.
| Question | FlashAttention | PagedAttention |
|---|---|---|
| What it optimizes | Data movement inside the attention computation | Allocation and addressing of KV cache memory |
| Main win | Fewer HBM reads and writes | Less wasted KV memory, larger batches, block sharing |
| Where it lives | The attention kernel | The engine’s block manager plus a block-reading kernel |
In the original vLLM implementation, prefill used conventional self-attention, with FlashAttention cited as an example; decode read cached KV blocks through PagedAttention. Later kernels combine these ideas too: FlashAttention added paged KV cache support in version 2.5, and FlashInfer’s kernels read cached state through a page table.
Limits and trade-offs
Block size costs you at both ends. Blocks that are too small leave GPU parallelism unused; blocks that are too large raise internal fragmentation and cut the odds of sharing. The paper’s best range was 16 to 128 tokens on ShareGPT but only 16 and 32 on Alpaca, where many sequences were shorter than a large block.
Indirection adds work to the attention kernel: table lookup, branches, and variable sequence lengths. In the original evaluation, its latency was 20% to 26% higher than FasterTransformer’s kernel; Kwon et al. considered that manageable because only the attention operator paid the overhead. vAttention (Prabhu et al., Microsoft Research India, ASPLOS 2025) takes a different route. It preserves a contiguous virtual KV layout and maps physical memory on demand through CUDA APIs, avoiding the need to adapt attention kernels to scattered blocks and maintain the same application-level block manager.
Paging also does not create memory. When blocks run out, the paper’s vLLM preempts requests, evicting all or none of a sequence’s blocks, and later restores them by swapping to CPU memory or recomputing. Swapping was costly with small blocks and roughly matched recomputation for block sizes of 16 to 64 tokens, and vLLM V1 defaults to recompute. Recomputed prefill is GPU work you already paid for once. For the remaining levers, see other ways to cut KV cache memory, like quantization and eviction.
From blocks to reuse: prefix caching and KV cache offloading
Fixed-size, addressable blocks made the KV cache something an engine can hash, look up, share, and copy out of GPU memory and back. Paging was built to stop waste while requests run; the same unit lets an engine keep blocks after a request ends.
Prefix caching inside vLLM
vLLM’s Automatic Prefix Caching keeps the KV blocks of processed requests and gives them to a new request with the same prefix, identifying each block by a hash of its tokens plus every token before it. It caches only full blocks and does not change model outputs. A hit raises the block’s reference count, the same bookkeeping the paper’s copy-on-write relied on, and cached blocks are evicted in LRU order when the allocator needs space. It is on by default in vLLM 0.31.0, the current release.
Offloading KV blocks beyond the GPU
The same release offloads KV cache to CPU when you set --kv-offloading-size, with a native or LMCache backend; it is off by default. LMCache, the open-source project our founders created, runs as a standalone daemon and moves KV caches into CPU memory, local storage, and remote backends for reuse across requests, sessions, and engine instances. It works in its own unit, 256-token chunks by default in multiprocess mode, not one vLLM block at a time.
We build Tensormesh Platform on LMCache. It is not a serving engine; it runs with vLLM on Kubernetes and manages three tiers to keep KV cache across GPU memory, host memory, and storage, with filesystem-backed storage as the largest. State saved outside a pod can be reused after it restarts, and cross-node sharing, listed as Preview in v1.0.0, lets one node retrieve compatible cached work from another. SGLang support is next.
Key takeaways
- PagedAttention is an allocator idea more than a kernel trick: fixed-size KV blocks, a block table per request, allocation on demand.
- Waste is bounded to one partly filled block per request instead of most of a worst-case reservation.
- Reference counts and block-level copy-on-write let samples, beams, and shared prefixes use one copy of their blocks.
- Block size, kernel indirection, and preemption are the costs; vAttention uses a contiguous virtual layout with physical memory mapped on demand.
- Block-level KV management is what makes prefix caching and offloading workable.
If your KV cache keeps getting evicted and rebuilt, look at keeping it beyond GPU memory: Tensormesh Platform does that for vLLM on Kubernetes. Our case for a persistent KV cache walks through the lifecycle.
Contact our team to discuss KV cache reuse in your vLLM deployment.
Frequently asked questions
What is PagedAttention in vLLM?
The memory design vLLM was built on: fixed-size KV blocks per request, mapped through a block table, with a new block allocated only when the last one fills. The code has moved past the paper’s kernels; the block model remains.
Who created PagedAttention?
Woosuk Kwon, Zhuohan Li, and colleagues, mostly at UC Berkeley, in “Efficient Memory Management for Large Language Model Serving with PagedAttention”, presented at SOSP 2023 with the vLLM engine.
What is the difference between PagedAttention and FlashAttention?
FlashAttention speeds up the attention computation by tiling it to cut GPU HBM traffic. PagedAttention manages where the KV cache lives and how it is allocated. They work at different layers, so one engine can use both.
What block size does vLLM use?
The paper sets the default at 16 tokens. vLLM 0.31.0 exposes it as
--block-size. Leave it unset, and vLLM starts at 16 but may switch to a size the selected attention backend prefers, logging the change when it does. Check the startup log for your deployment.Does PagedAttention change model outputs?
No. It changes where keys and values are stored, not what attention computes; the paper rewrites the same attention equation as a sum over blocks.
Is PagedAttention the same as prefix caching?
No. PagedAttention is the block layout and allocator. Prefix caching builds on it, hashing full blocks so a later request with the same prefix can reuse them instead of recomputing prefill.