Prior LLM serving engines wasted 61.8% to 79.6% of their GPU key-value (KV) cache memory even when running iteration-level continuous batching, stranding compute that could have served concurrent users. Because deep learning frameworks required tensors to occupy contiguous memory while autoregressive output lengths remain unknown until generation ends, serving systems pre-allocated worst-case memory slabs per request and could not share cached prefixes across sequences.

In 2023, Woosuk Kwon, Zhuohan Li, Siyuan Zhuang, Ying Sheng, Lianmin Zheng, Cody Hao Yu, Joseph E. Gonzalez, Hao Zhang, and Ion Stoica (UC Berkeley, Stanford, and UC San Diego) solved this bottleneck by importing virtual memory paging and copy-on-write from operating systems into the attention kernel itself. Their PagedAttention algorithm and vLLM serving engine split each sequence’s KV cache into fixed-size 16-token blocks stored anywhere in GPU DRAM, lifting effective KV-cache utilization to 96.3% and increasing serving throughput by 2x to 4x over FasterTransformer and Orca at matching latency without altering a single generated token.

  • Why KV cache sets the batch ceiling: Serving OPT-13B on a 40 GB NVIDIA A100 uses 26 GB (65%) for static weights and leaves 12 GB for KV cache; at 800 KB per token, a single 2,048-token sequence can demand 1.6 GB.
  • Near-zero fragmentation: Fixed-size pages eliminate external fragmentation and confine internal waste to the final partial block, turning 20.4% to 38.2% KV utilization in Orca baselines into 96.3% in vLLM.
  • Zero-copy branching and prefix reuse: Reference-counted physical blocks with copy-on-write cut KV memory by 6.1% to 30.5% in parallel sampling, 37.6% to 66.3% in beam search, and deliver 3.58x higher throughput on shared 5-shot prompts.
  • A measured kernel tradeoff: Block-table indirection makes the PagedAttention CUDA kernel 20% to 26% slower than FasterTransformer’s contiguous kernel, yet fitting 2.2x to 4.3x more batched requests yields massive net throughput gains.
Effective KV-cache usage vs. memory waste on OPT-13B (ShareGPT)
Orca (Max): pre-allocate 2,048 tokens20.4% used / 79.6% wasted
57.3% internal fragmentation, 13.3% future reservation, 8.9% external fragmentation.
Orca (Pow2): over-reserve up to 2x26.8% used / 73.2% wasted
41.6% external fragmentation from buddy allocator, 17.9% reservation, 13.6% internal.
Orca (Oracle): exact output length known38.2% used / 61.8% wasted
Even with impossible foresight, 36.6% external fragmentation and 25.2% reservation remain.
vLLM (PagedAttention, B = 16)96.3% used / 3.7% wasted
Zero reservation waste and zero external fragmentation; only the last block’s unfilled slots remain.

Higher token-state percentage is better. Source: Kwon et al. (2023), Figure 2 and Section 6.2.

Why contiguous KV tensors trap serving engines

Autoregressive Transformers run two distinct inference phases per request. The prompt (prefill) phase processes all input tokens in parallel via matrix-matrix multiplications that saturate GPU Tensor Cores. The decoding phase then generates tokens one by one via memory-bandwidth-bound matrix-vector math, reloading all model weights and prior keys and values on every step. Batching concurrent requests is the primary way to amortize those weight reads.

Iteration-level scheduling, introduced by Orca, improved compute utilization by admitting and retiring requests after every decode step instead of waiting for static batches to finish. Yet it hit a memory-capacity ceiling. Because PyTorch and TensorFlow expect contiguous tensors while output lengths remain unknown until generation stops, engines had to pre-allocate contiguous slabs upfront.

In real traffic, lengths vary widely: Alpaca averages 19.31 prompt and 58.45 output tokens, whereas ShareGPT averages 161.31 prompt and 337.99 output tokens up to 2,048. Pre-allocating contiguous chunks creates three forms of waste:

  • Internal fragmentation: Reserving 2,048 tokens (Orca (Max)) when a request generates 50 tokens wastes 57.3% of KV memory in untouched tail slots.
  • Reservation waste: Even with oracle length foresight (Orca (Oracle)), holding future slots idle for a sequence’s full lifetime locks up 25.2% of KV memory that shorter requests could use.
  • External fragmentation: Variable-sized buddy allocations (Orca (Pow2) or Orca (Oracle)) splinter 36.6% to 41.6% of DRAM into unusable gaps.

Periodic compaction is too slow across multi-gigabyte KV tensors between decode steps, and contiguous layouts still prevent memory sharing across branches.

Virtual memory paging, copy-on-write, and GPU kernels

PagedAttention decouples logical token order from physical GPU memory layout. Like virtual memory pages in an OS, it partitions each sequence’s KV cache into fixed-size KV blocks holding B tokens each (default B = 16). A per-sequence block table maps logical blocks to non-contiguous physical block IDs inside a pre-allocated GPU DRAM pool and tracks filled slot counts.

Walk through the paper’s example with B = 4 and a 7-token prompt (“Four score and seven years ago our”). vLLM allocates only two non-adjacent physical blocks (say 7 and 1): prefill fills tokens 1 through 4 in block 7 and 5 through 7 in block 1, leaving one empty slot. Step 1 reads blocks 7 and 1 via the block table, emits “fathers”, and fills that eighth slot. Step 2 allocates physical block 3 on demand. Memory waste never exceeds B - 1 tokens in a sequence’s final block (3.7% in Figure 2).

Reference-counted blocks enable copy-on-write (CoW) sharing via three scheduler primitives (fork, append, free):

  • Parallel sampling: fork maps k samples to shared prompt blocks (ref count k). When a sample appends to a shared tail block (ref count above 1), vLLM copies only that block, decrements the ref count, and leaves the last writer to update in place.
  • Beam search: Sharing evolves dynamically across beam candidates. Pruned beams call free, immediately reclaiming zero-ref blocks without copying surviving histories.
  • Shared prefixes: Common system prompts or few-shot headers sit in pinned physical blocks like OS shared libraries, letting requests compute prefill only on their unique suffix.

Because kernels like FlashAttention-2 assume contiguous K and V tensors, vLLM adds three custom CUDA kernels atop an 8,500-line Python scheduler and 2,000 lines of C++/CUDA: fused reshape-and-block-write, fused block-read-and-attention (one GPU warp per block for coalesced reads), and fused block-copy (batching scattered CoW copies into one launch instead of many cudaMemcpyAsync calls). For tensor-parallel models like OPT-66B (4x A100) and OPT-175B (8x A100-80GB), a single centralized scheduler owns all block tables and broadcasts block IDs each step while GPU workers shard attention heads and sync via NCCL all-reduce.

How vLLM adapts OS paging for LLM preemption and recovery
Gang eviction (FCFS)

Because decoding touches every block of a sequence, vLLM evicts all-or-nothing per sequence group (latest arrivals first) instead of OS LRU page eviction.

Swap vs. recompute

Recomputation is block-size invariant and beats CPU swapping at small blocks; at medium blocks (B = 16 to 64), both match end-to-end.

Block size B = 16

Large enough for parallel GPU warp reads and PCIe transfers, yet small enough to avoid hurting short requests like Alpaca (mean 58.45 output tokens).

Source: Kwon et al. (2023), Sections 4.5, 7.2, and 7.3.

Tracing PagedAttention across serving workloads

Explore the four evaluated serving patterns below to see where vLLM’s gains come from and how batch capacity scales across decoding methods.

PagedAttention and vLLM across four serving workloads

Select a workload (or use Left and Right arrow keys) to compare why contiguous engines waste memory, how block tables resolve it, and the measured throughput gains.

Single-sequence sampling (OPT-13B/66B/175B on ShareGPT & Alpaca)

Fragmentation

Even with zero sharing across users, eliminating reservation and fragmentation lets vLLM batch 2.2x to 4.3x more concurrent requests.

Why contiguous fails
ShareGPT prompts and outputs vary up to 2,048 tokens; Orca (Max) loses 79.6% of KV memory and FasterTransformer stalls on request-level batches.
vLLM mechanism
On-demand 16-token block allocation holds 96.3% token-state density, batching 30.42 requests on ShareGPT vs. 13.62 in Orca (Oracle).
Measured evidence
Sustains 1.7x to 2.7x higher request rates than Orca (Oracle), 2.7x to 8x over Orca (Max), and up to 22x over FasterTransformer on ShareGPT.
Edge case observed
On OPT-175B (8x A100-80GB, 264 GB KV cache) with short Alpaca prompts, Orca (Pow2/Oracle) also fits large batches and becomes compute-bound.

Source: Kwon et al. (2023), Section 6 and Figures 12 through 17.

For readers skipping the tabs, here are the headline results across all four serving regimes:

  • Basic single-sequence chat: PagedAttention lifts effective KV usage to 96.3% and batches 30.42 ShareGPT requests vs. 13.62 in Orca (Oracle), sustaining 1.7x to 2.7x higher request rates than Orca (Oracle) and up to 22x over FasterTransformer.
  • Parallel sampling: sharing prompt KV blocks via copy-on-write cuts KV memory by 6.1% to 9.8% on Alpaca and 16.2% to 30.5% on ShareGPT.
  • Beam search: dynamic block sharing saves 37.6% to 55.2% KV memory on Alpaca and 44.3% to 66.3% on ShareGPT, widening vLLM’s throughput lead over Orca (Oracle) from 1.3x to 2.3x at beam width 6.
  • Shared system prompts and multi-turn chat: pinning prefix blocks delivers 1.67x throughput with an 80-token 1-shot prefix, 3.58x with a 341-token 5-shot prefix, and 2x on long ShareGPT chatbot histories truncated to 1,024 prompt tokens.

Kernel tax, compute-bound edge cases, and what changed next

PagedAttention is not a free speedup for every GPU workload, and three architectural limits define where it helps and how serving stacks evolved after 2023.

First, memory indirection carries a real kernel tax. In Section 7.1’s microbenchmark, block-table lookups, extra branches, and variable sequence-length handling make PagedAttention’s attention kernel 20% to 26% slower than FasterTransformer’s contiguous kernel. As Section 8 explicitly notes, paging only wins when dynamic, unpredictable memory capacity limits batch size. Applying paging to workloads with static tensor shapes (such as DNN training) or compute-bound non-LLM models actually degrades performance. Even within LLM serving, OPT-175B on 8x A100-80GB (which leaves 264 GB and 60.1K KV slots free) serving short Alpaca sequences hits the compute ceiling where Orca (Oracle) and Orca (Pow2) perform similarly to vLLM.

Second, vLLM’s baselines and scheduling assumptions leave room for newer fixes. Because Orca was not open-source, the authors re-implemented Orca with a buddy allocator for comparison. More importantly, vLLM’s 2023 design runs FCFS scheduling with full-sequence prefills and drops multi-turn chatbot KV cache between rounds to avoid holding memory idle across user think time. Long prompt prefills can still stall active decode streams unless combined with chunked prefill or prefill-decode disaggregation, while automatic prefix caching across arbitrary multi-turn conversations was later generalized via radix trees in RadixAttention.

Third, block size and preemption recovery must match workload length. Setting B = 16 was empirically chosen over B = 1 through 256: larger blocks (B = 64 or 128) degrade short Alpaca traces via internal fragmentation, while tiny blocks (B = 1 to 4) crush PCIe bandwidth during CPU swapping. Under memory overload, recomputing KV states from concatenated tokens takes constant time across block sizes and never exceeds swapping by more than 20% in latency, matching swapping around B = 16 to 64 while cleanly beating it at smaller blocks.

For systems engineers building LLM inference infrastructure today, PagedAttention’s enduring contribution is treating GPU KV cache as a first-class virtual memory subsystem rather than a static tensor buffer. Whenever serving throughput drops while SM compute sits below saturation, inspect KV reservation and fragmentation first: fixing how blocks map to physical HBM routinely unlocks more capacity than optimizing the attention math alone.