NeurIPS 2026Coming to NeurIPS?Explore papers, orals & directions

Efficient Memory Management for Large Language Model Serving with PagedAttention

Woosuk Kwon, Zhuohan Li, Siyuan Zhuang, Ying Sheng, Lianmin Zheng, Cody Hao Yu, Joseph E. Gonzalez, Hao Zhang, Ion Stoica

Introduction

The rapid adoption of Large Language Models (LLMs) has highlighted a significant bottleneck in AI infrastructure: the high cost and memory intensity of serving these models at scale. During the autoregressive generation process, LLMs store "KV caches"—mathematical representations of all previous tokens—to avoid redundant calculations. However, managing these caches efficiently is notoriously difficult. vLLM addresses this challenge by introducing PagedAttention, a memory management engine inspired by classic operating system paging. By partitioning the KV cache into non-contiguous blocks, vLLM eliminates fragmentation and enables efficient memory sharing, resulting in a 2-4x throughput increase over existing state-of-the-art systems.

The Problem: Memory Fragmentation in LLM Serving

In traditional LLM serving systems, the KV cache is managed by allocating a single, contiguous memory chunk for each request based on the maximum possible sequence length (e.g., 2048 tokens). This approach is highly inefficient for three primary reasons:

  1. Internal Fragmentation: Memory is reserved for tokens that have not yet been generated.
  2. External Fragmentation: Small, unusable gaps appear between allocated chunks in the GPU memory.
  3. Inability to Share: Advanced decoding methods like beam search or parallel sampling generate multiple outputs from a single prompt. Traditional systems store the prompt's KV cache multiple times because they cannot share non-contiguous memory segments.

These inefficiencies often lead to 60-80% of GPU memory being wasted, severely limiting the number of concurrent requests a system can handle.

PagedAttention: Virtual Memory for LLMs

The core innovation of vLLM is PagedAttention, which treats GPU memory similarly to how an operating system manages RAM.

KV Blocks and Logical Mapping

Instead of contiguous chunks, PagedAttention divides the KV cache into fixed-size KV blocks (e.g., 16 tokens). A request’s KV cache is represented as a series of logical blocks. These are mapped to non-contiguous physical blocks on the GPU via a Block Table. As the model generates new tokens, the system allocates physical blocks on-demand, mirroring the behavior of virtual memory in an OS.

The vLLM Engine

The vLLM engine is a distributed serving system built on PagedAttention. It utilizes a centralized scheduler to manage block tables across multiple GPUs. This architecture allows for:

  • Dynamic Growth: Physical memory is only assigned when a token is actually generated, allowing the system to pack significantly more requests into a single batch.
  • Efficient Sharing via Copy-on-Write (CoW): When multiple sequences share a common prefix (such as a system prompt or a few-shot example), they initially point to the same physical blocks. If a sequence generates a unique token, the system performs a "copy-on-write," creating a new physical block only for that specific sequence. This makes sharing a first-class citizen in the serving process.

Experimental Evaluation

The researchers evaluated vLLM against state-of-the-art systems like FasterTransformer and Orca using several real-world datasets to simulate diverse workloads:

  • ShareGPT: Real user conversations with high variance in sequence length.
  • Alpaca: An instruction-following dataset with generally shorter sequences.
  • WMT16: Translation tasks used specifically to test shared prefix scenarios.

Key Results

  • Throughput: vLLM achieved 2-4x higher throughput than competitors across various model sizes, ranging from OPT-13B to OPT-175B.
  • Batch Size: On an NVIDIA A100 (40GB), vLLM increased the effective batch size for ShareGPT from approximately 7 requests to 30.
  • Decoding Efficiency: For beam search, vLLM improved throughput by up to 2.3x by leveraging its unique prefix-sharing capabilities.
  • Near-Zero Waste: vLLM reduced memory waste to under 4% (limited only to the final, partially filled block), compared to the massive waste seen in traditional systems.

Discussion and Limitations

While PagedAttention significantly improves throughput, it introduces a small amount of kernel overhead—approximately 20-26% higher latency for the attention kernel itself—due to the necessity of block table lookups. However, this micro-latency cost is heavily outweighed by the massive gains in system-level throughput.

Furthermore, performance is sensitive to the chosen block size. While 16 tokens proved optimal in testing, different hardware configurations or model architectures might require further tuning. The authors suggest that this paged memory management approach could eventually be applied to other dynamic GPU workloads beyond autoregressive LLMs, such as model training.

Conclusion

By applying foundational operating system principles to the modern challenge of LLM serving, vLLM and PagedAttention provide a scalable solution to memory fragmentation. This approach not only increases throughput but also makes complex decoding strategies more computationally feasible, paving the way for more efficient and accessible AI services.

Summary updated

BibTeX
@inproceedings{kwon2023efficient,
  author = {Woosuk Kwon and Zhuohan Li and Siyuan Zhuang and Ying Sheng and Lianmin Zheng and Cody Hao Yu and Joseph E. Gonzalez and Hao Zhang and Ion Stoica},
  title = {{Efficient Memory Management for Large Language Model Serving with PagedAttention}},
  booktitle = {SOSP},
  year = {2023},
}
Figure