PagedAttention is a memory management algorithm, popularized by the vLLM inference engine, that organizes a model's KV cache into non-contiguous, fixed-size blocks or 'pages'. This design eliminates internal fragmentation—the wasted memory from padding variable-length sequences to a fixed size—enabling highly efficient memory sharing and utilization during continuous batching. By allowing new requests to reuse freed memory blocks from completed sequences, it achieves near-zero waste in GPU memory.
Glossary
PagedAttention

What is PagedAttention?
PagedAttention is a memory management algorithm that organizes a transformer model's KV cache into non-contiguous, fixed-size blocks, analogous to virtual memory paging in operating systems.
The algorithm treats the KV cache of each sequence as a logical block list, with physical pages that can be scattered in memory. This enables flexible, on-demand allocation and deallocation, which is critical for serving dynamic workloads with unpredictable sequence lengths. PagedAttention directly reduces memory-bound latency and increases batch throughput, making it a foundational technique for cost-effective, high-scale LLM serving by maximizing the utility of expensive accelerator memory.
Key Features and Benefits
PagedAttention is a memory management algorithm that organizes a transformer model's KV cache into non-contiguous, fixed-size blocks, analogous to virtual memory paging in operating systems. This architecture enables efficient memory sharing and eliminates internal fragmentation, which is critical for high-throughput continuous batching.
Eliminates Internal Fragmentation
In traditional KV cache allocation, memory is reserved as a contiguous block for each request's maximum possible sequence length, leading to significant internal fragmentation as most sequences are shorter than the maximum. PagedAttention allocates memory in fixed-size blocks (e.g., 16 tokens). The KV cache for a sequence occupies only the exact number of blocks needed, with the final block partially filled. This results in near-zero waste, allowing more concurrent requests to fit in GPU memory.
Enables Efficient Memory Sharing
PagedAttention's block-based design allows the KV cache to be shared across multiple sequences or beam search candidates. This is crucial for two scenarios:
- Prompt Sharing: In a multi-tenant server, if two users submit the same system prompt, a single set of KV cache blocks can be referenced by both request contexts.
- Beam Search: Different beams in a search can share the KV cache blocks for their common prefix, avoiding duplicate storage. This sharing reduces total memory consumption and decreases memory I/O, directly improving throughput.
Enables Non-Contiguous Physical Storage
Just like virtual memory, PagedAttention decouples the logical sequence of tokens from their physical storage. A sequence's KV cache is represented by a logical block table that maps to physical blocks which can be scattered throughout GPU memory. This allows:
- Flexible Allocation/Deallocation: Blocks for completed sequences can be freed and reused without complex memory compaction.
- Efficient Cache Eviction: For sequences exceeding the context window, a policy like Least-Recently-Used (LRU) can evict individual blocks, not entire sequences.
- Offloading to CPU/NVMe: "Cold" blocks can be swapped to slower, larger memory tiers, enabling effectively infinite context lengths.
Optimizes for Continuous Batching
PagedAttention is the foundational enabler for high-performance continuous batching (also known as iterative or rolling batching). Because memory is allocated in small, independent blocks:
- Dynamic Joining/Exiting: New requests can be added to the batch by allocating new blocks. Completed sequences free their blocks, making room for others, without stopping the batch.
- Variable Sequence Lengths: The batch can efficiently contain requests with vastly different context lengths (e.g., 50 tokens vs. 8000 tokens) because each uses only the blocks it needs. This leads to near-100% GPU utilization and dramatically higher throughput compared to static batching.
Architectural Analogy: OS Virtual Memory
PagedAttention directly applies decades of operating system research to the KV cache problem. Key parallels include:
- Block/Page Table: The logical block table acts as a page table, translating logical token positions to physical block addresses.
- Demand Paging: Blocks can be allocated on-demand as the sequence grows, rather than pre-allocating the maximum.
- Copy-on-Write: For shared prompts, blocks are marked as read-only; if a sequence needs to modify a shared block (e.g., during fine-grained attention), a private copy is created. This proven architecture provides a robust, predictable framework for cache management.
PagedAttention vs. Traditional KV Cache Management
A technical comparison of memory management paradigms for the Key-Value (KV) cache in transformer-based language model inference.
| Feature / Metric | PagedAttention (vLLM) | Traditional KV Cache |
|---|---|---|
Core Memory Management Paradigm | Non-contiguous, virtual memory paging | Contiguous, monolithic allocation |
Allocation Unit | Fixed-size blocks (pages) | Variable-length per sequence |
Internal Fragmentation | Eliminated (near-zero waste) | High (up to 50%+ waste) |
Efficient Continuous Batching | ||
Dynamic Sequence Length Support | ||
Memory Sharing (e.g., for prompts) | ||
KV Cache Eviction Policy | Block-level LRU | Sequence-level LRU or FIFO |
Memory Overhead for Management | Low (page table) | Very Low (pointer only) |
Implementation Complexity | High (OS-like allocator) | Low (simple allocator) |
Typical GPU Memory Utilization |
| 50-70% |
Optimal For | High-throughput, variable-length serving | Simple, static-batching scenarios |
Where is PagedAttention Used?
PagedAttention's primary application is in high-throughput LLM inference serving, but its principles influence broader system design for managing large, dynamic memory buffers.
Long Context Generation
By managing memory in fixed-size pages, PagedAttention facilitates techniques for handling sequences that exceed physical GPU memory. This is critical for applications requiring long-context windows, such as:
- Document analysis and summarization of lengthy reports or codebases.
- Long-form conversational agents that maintain context over extended dialogues.
- Research and legal review tools that process multi-document inputs. The paging mechanism allows for efficient KV cache offloading to CPU RAM or NVMe when context length outstrips GPU VRAM.
Multi-Tenant Model Serving
In cloud-based Model-as-a-Service (MaaS) platforms, PagedAttention optimizes resource sharing across multiple users and requests. Its block-based management enables:
- Strong performance isolation by preventing one user's long sequence from fragmenting memory for others.
- Predictable memory allocation, allowing service providers to accurately provision capacity and guarantee Quality of Service (QoS).
- Efficient context switching between heterogeneous workloads with varying sequence lengths and request patterns.
Advanced Attention Variants
The paging abstraction simplifies the implementation of complex, memory-efficient attention mechanisms that rely on non-contiguous or dynamic KV cache access patterns. Examples include:
- Sliding Window Attention, where only a local window of recent tokens is kept active.
- StreamingLLM frameworks, which use attention sink tokens to stabilize infinite-length generation.
- Speculative decoding, where the KV cache for draft tokens must be managed separately from the target model's verification pass.
Research on Memory-Bound Systems
PagedAttention has become a canonical reference in research for optimizing systems operating in a memory-bound regime. It demonstrates how OS-inspired virtual memory concepts can solve modern hardware bottlenecks. This influences work on:
- Novel caching policies for dynamic neural network states.
- Scheduling algorithms that are cache-aware to improve locality.
- Hardware-software co-design for future accelerators, where efficient, fine-grained memory management is a first-class design constraint.
Frequently Asked Questions
PagedAttention is a foundational memory management algorithm for transformer inference. These questions address its core mechanisms, benefits, and implementation details for engineers optimizing KV cache usage.
PagedAttention is a memory management algorithm that organizes a transformer model's KV cache into non-contiguous, fixed-size blocks or pages, analogous to virtual memory in operating systems. During the decode phase, the attention mechanism's queries reference these pages via a block table, which maps logical token positions to physical memory blocks. This abstraction allows the system to allocate pages independently for different requests in a continuous batching scenario and to share pages between sequences with common prefixes, eliminating internal fragmentation and enabling near-100% memory utilization for the KV cache.
Enabling Efficiency, Speed & Accuracy
Intelligent Analysis, Decision & Execution
We build AI systems for teams that need search across company data, workflow automation across tools, or AI features inside products and internal software.
Talk to Us
Search across company data
Give teams answers from docs, tickets, runbooks, and product data with sources and permissions.
Useful when people spend too long searching or get different answers from different systems.

Automate internal workflows
Use AI to route work, draft outputs, trigger actions, and keep approvals and logs in place.
Useful when repetitive work moves across multiple tools and teams.

Add AI to products and internal tools
Build assistants, guided actions, or decision support into the software your team or customers already use.
Useful when AI needs to be part of the product, not a separate tool.
Related Terms
PagedAttention is a core technique for optimizing the key-value cache in transformer inference. These related concepts define the broader ecosystem of memory management and latency reduction.
KV Cache
The KV cache is a memory buffer that stores computed key and value tensors from previous tokens during the autoregressive decoding phase of a transformer. Its primary purpose is to eliminate redundant computation: instead of recomputing keys and values for all prior tokens on each new generation step, the model reads them from this cache, dramatically reducing latency.
- Structure: For a model with multiple layers and attention heads, the cache holds separate key and value tensors for each.
- Memory Footprint: The cache size scales linearly with batch size, sequence length, and model dimensions, making it a primary bottleneck for long-context inference.
- Management Challenge: Efficiently allocating, sharing, and evicting data in the KV cache is the central problem that PagedAttention solves.
Continuous Batching
Continuous batching is a dynamic request scheduling technique that maximizes GPU utilization by allowing new inference requests to join a running batch and completed sequences to exit independently. This is in contrast to static batching, where the entire batch must finish before a new one can begin.
PagedAttention is the enabling technology for efficient continuous batching in systems like vLLM. It allows:
- Non-contiguous Memory Allocation: Requests of different sequence lengths can share GPU memory without internal fragmentation.
- Independent Completion: When one sequence in the batch finishes generation, its allocated cache blocks can be immediately freed and reused for a new request, without stalling the entire batch.
vLLM
vLLM is a high-throughput, memory-efficient open-source inference serving engine for large language models. It is the canonical implementation that popularized the PagedAttention algorithm.
- Core Innovation: vLLM treats the KV cache as virtual memory, dividing it into fixed-size blocks. This allows for zero internal fragmentation and efficient sharing of physical memory across multiple requests.
- Performance Impact: By eliminating wasted memory, vLLM can support batch sizes that are 2-4x larger than previous systems, leading to dramatically higher throughput.
- Ecosystem Role: It serves as a reference architecture for modern, efficient inference serving, demonstrating the practical application of OS-inspired memory management to AI systems.
Attention Sink
An attention sink is a phenomenon observed in streaming language models, where the initial tokens of a sequence (often the first few) receive disproportionately high attention scores from all subsequent tokens. This effect is leveraged by frameworks like StreamingLLM to enable infinite-length generation without model retraining.
- Connection to PagedAttention: Managing very long contexts requires efficient cache policies. The attention sink concept informs cache eviction strategies; evicting middle tokens while preserving the initial "sink" tokens can maintain generation quality far beyond the model's original training window.
- Practical Implication: Understanding attention sinks is crucial for designing systems that handle long dialogues or documents, as it dictates which parts of the KV cache are most critical to retain.
Prefill & Decode Phases
Transformer inference is split into two distinct computational phases:
- Prefill Phase: The initial, compute-bound stage where the entire input prompt is processed in parallel. All prompt tokens attend to each other, and the initial KV cache for the entire prompt is computed and stored.
- Decode Phase: The subsequent, memory-bound stage where tokens are generated one-by-one (autoregressively). In this phase, the model attends to the cached keys and values from all previous tokens to predict the next token.
PagedAttention's Role: It optimizes memory management primarily for the decode phase, where efficient, random-access reads from the KV cache are the performance bottleneck. The non-contiguous paging allows the decode phase to handle highly variable sequence lengths efficiently within a continuous batch.
Memory-Bound Regime
A system is in a memory-bound regime when its performance is limited by the speed of memory accesses (bandwidth or latency) rather than by the speed of its arithmetic logic units (ALUs). Autoregressive decoding in large language models is a classic example of a memory-bound workload.
- The Bottleneck: The primary operation during decoding is attention, which involves reading the massive KV cache from GPU memory. The time spent waiting for this data often far exceeds the time spent on the actual matrix multiplications.
- PagedAttention as a Solution: By organizing the cache into blocks and reducing fragmentation, PagedAttention improves effective memory bandwidth utilization. It ensures that memory fetches are as efficient as possible, directly alleviating the memory-bound bottleneck and increasing decode throughput.

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.
Partnered with leading AI, data, and software stack.
How We Work
Custom AI workflows for your Business
One-fit-all AI don't work for modern businesses. At Inferensys, we aim to understand your business & custom requirements; which we use to define most efficient agentic workflows, the data, and the tools for your business.
01
Review the use case
We understand the task, the users, and where AI can actually help.
Read more02
Pick the right approach
We define what needs search, automation, or product integration.
Read more03
Build the first useful version
We implement the part that proves the value first.
Read more04
Improve from there
We add the checks and visibility needed to keep it useful.
Read moreThe first call is a practical review of your use case and the right next step.
Talk to Us