Inferensys

Glossary

Paged Attention

A memory management technique that partitions the KV cache into non-contiguous blocks, eliminating fragmentation and enabling high-throughput serving of large language models.
MLOps engineer reviewing model serving infrastructure on laptop, container orchestration visible, technical workspace.
MEMORY MANAGEMENT FOR LLM SERVING

What is Paged Attention?

Paged Attention is a memory management algorithm that partitions the KV cache into non-contiguous blocks, eliminating fragmentation and enabling high-throughput serving of large language models.

Paged Attention is a virtual memory-inspired technique that divides the KV cache into fixed-size blocks, allowing them to be stored non-contiguously in GPU memory. This eliminates the internal and external fragmentation caused by pre-allocating large contiguous memory chunks for each sequence's maximum possible context length.

By mapping logical KV cache blocks to physical memory blocks via a block table, Paged Attention enables memory sharing across sequences with identical prompt prefixes. This prefix caching optimization, implemented in serving engines like vLLM, dramatically increases throughput and reduces memory waste during batched inference.

MEMORY MANAGEMENT

Key Features of Paged Attention

Paged Attention is a novel memory management algorithm that treats the KV cache like virtual memory, partitioning it into fixed-size blocks that can be mapped non-contiguously in physical memory. This eliminates fragmentation and enables near-optimal memory utilization during LLM serving.

01

Block-Based Memory Management

Paged Attention partitions the KV cache into fixed-size blocks, analogous to pages in an operating system's virtual memory. Each block stores the key and value tensors for a contiguous subsequence of tokens. The block table maps logical sequences to physical blocks, allowing non-contiguous storage without requiring large contiguous memory allocations. This eliminates internal and external fragmentation, ensuring that memory is wasted only in the last block of a sequence—typically less than 4% overhead.

< 4%
Memory Waste
02

Memory Sharing via Copy-on-Write

Blocks can be shared across multiple sequences through a copy-on-write mechanism. When parallel sampling generates multiple outputs from a single prompt, all output sequences share the prompt's KV cache blocks. A block is only copied when a sequence writes to it, drastically reducing memory duplication. This is critical for techniques like beam search and parallel decoding, where dozens of sequences share a common prefix.

03

Dynamic Memory Allocation

Unlike traditional serving systems that pre-allocate a fixed maximum-length KV cache slot per sequence, Paged Attention allocates blocks on demand as generation proceeds. This enables the scheduler to oversubscribe GPU memory, packing more concurrent sequences than physically possible under static allocation. When memory is exhausted, blocks from preempted sequences can be swapped to CPU RAM and later restored, enabling graceful handling of memory pressure without request failure.

04

Near-Optimal Throughput

By eliminating fragmentation and enabling memory sharing, Paged Attention achieves near-optimal memory utilization. The vLLM serving engine, which implements this algorithm, demonstrates up to 24x higher throughput compared to Hugging Face Transformers and 2-4x improvement over previous state-of-the-art systems like FasterTransformer. This throughput gain comes entirely from better memory management, not from modifying the attention computation itself.

24x
Throughput vs HF
05

Seamless Batching and Preemption

Paged Attention enables continuous batching by allowing new sequences to join a running batch without waiting for existing sequences to complete. When GPU memory is exhausted, the scheduler can preempt low-priority sequences by evicting their blocks to CPU memory. When memory becomes available, blocks are swapped back in, and generation resumes exactly where it left off. This cooperative preemption avoids the all-or-nothing eviction of traditional systems.

PAGED ATTENTION

Frequently Asked Questions

Clear, technical answers to the most common questions about the PagedAttention algorithm, its implementation in vLLM, and its impact on large language model serving throughput.

PagedAttention is a novel attention algorithm that manages the KV cache by partitioning it into fixed-size, non-contiguous blocks of memory, analogous to how an operating system manages virtual memory with pages. In a standard transformer, the KV cache grows as a contiguous tensor for each sequence, leading to internal and external memory fragmentation and limiting batch size. PagedAttention eliminates this by allowing each sequence's KV cache to be stored across multiple discrete blocks that do not need to be physically adjacent. During the attention computation, a block table maps logical block indices to physical block addresses, and a custom GPU kernel efficiently gathers the relevant blocks. This enables memory sharing between sequences—for example, when multiple requests share an identical system prompt prefix, the KV cache blocks for that prefix are mapped into each sequence's logical block table rather than being physically duplicated. The result is near-zero memory waste and the ability to pack significantly more concurrent sequences into GPU VRAM, directly translating to higher serving throughput.

Prasad Kumkar

About the author

Prasad Kumkar

CEO & MD, Inference Systems

Prasad Kumkar is the CEO & MD of Inference Systems and writes about AI systems architecture, LLM infrastructure, model serving, evaluation, and production deployment. Over 5+ years, he has worked across computer vision models, L5 autonomous vehicle systems, and LLM research, with a focus on taking complex AI ideas into real-world engineering systems.

His work and writing cover AI systems, large language models, AI agents, multimodal systems, autonomous systems, inference optimization, RAG, evaluation, and production AI engineering.