PagedAttention is a memory management algorithm that treats a Large Language Model's KV cache—the storage of computed key and value tensors for prior tokens—as non-contiguous, virtual pages. Inspired by operating system paging, it allows the system to allocate physical GPU memory in fixed-size blocks only as needed, eliminating external fragmentation and enabling efficient sharing of cached states between sequences in a batch, such as in a shared prompt prefix. This is the core innovation enabling vLLM's high performance.
Glossary
PagedAttention

What is PagedAttention?
PagedAttention is a memory management algorithm for the KV cache, introduced by the vLLM inference engine, that dramatically improves throughput and supports longer contexts.
The algorithm's primary benefits are near-zero waste from memory fragmentation and the ability to serve sequences with longer context windows than physically available memory by swapping pages. By managing the KV cache in pages, it works seamlessly with continuous batching, allowing the serving system to dynamically add and evict sequences. This makes it foundational for cost-effective, high-throughput LLM serving where memory is the primary bottleneck for batch size and sequence length.
Key Features and Benefits
PagedAttention is a memory management algorithm for the KV cache that treats it as non-contiguous pages, analogous to virtual memory in operating systems. This architectural shift enables several critical performance and scalability benefits for LLM inference.
Eliminates Memory Fragmentation
Traditional KV cache allocation reserves a large, contiguous block of memory for the maximum possible sequence length, leading to significant internal fragmentation when sequences are shorter. PagedAttention allocates memory in fixed-size pages (e.g., 16 tokens per block). This allows the system to allocate only the pages needed for the actual sequence length, dramatically reducing wasted memory. This efficient packing is the foundation for supporting longer context windows and higher batch sizes within the same GPU memory constraints.
Enables Efficient Memory Sharing
A core innovation of PagedAttention is its ability to share KV cache pages between different requests or within a single request. This is critical for two scenarios:
- Prompt Sharing: In multi-tenant serving or chatbot applications, identical system prompts or few-shot examples can be stored once in physical memory and have their pages mapped into the virtual KV cache of multiple concurrent requests.
- Sampling Algorithms: Techniques like beam search or parallel sampling, which generate multiple output sequences from a shared prefix, can now share the KV cache pages for that common prefix. This eliminates redundant memory storage and computation, directly reducing memory overhead and cost.
Supports Non-Contiguous Logical Sequences
The algorithm decouples the logical layout of the KV cache (the sequence of tokens as seen by the attention mechanism) from its physical layout in GPU memory. It maintains a block table for each sequence, mapping logical token positions to physical memory pages. This allows:
- Dynamic Growth: Sequences can grow token-by-token, with new pages allocated on-demand without reallocating or copying the entire cache.
- Flexible Management: Pages can be efficiently swapped or evicted if needed (a foundation for future KV cache spilling to CPU RAM).
- Complex Attention Patterns: It naturally accommodates advanced decoding methods where the logical token order may not be physically contiguous.
Increases GPU Utilization & Throughput
By eliminating fragmentation and enabling sharing, PagedAttention allows the vLLM inference engine to pack more concurrent sequences (a larger batch size) into available GPU High-Bandwidth Memory (HBM). This directly translates to higher GPU utilization and throughput (tokens/second). When combined with continuous batching, the system can maintain a high batch size with diverse sequence lengths, keeping the computational hardware saturated and driving down the effective cost-per-token.
Facilitates Longer Context Windows
Memory fragmentation is a primary bottleneck for deploying models with long context windows (e.g., 128K+ tokens). PagedAttention's efficient, page-based allocation makes it feasible to utilize these long contexts without requiring prohibitively large GPU memory reserves. The memory used scales nearly linearly with the actual number of cached tokens across all requests, not the maximum possible per request. This makes production deployment of models with massive context windows economically and technically viable.
PagedAttention vs. Traditional KV Cache Allocation
This table compares the core architectural differences between the PagedAttention algorithm and traditional contiguous KV cache allocation methods, highlighting their impact on memory efficiency, throughput, and operational flexibility during LLM inference.
| Feature / Metric | PagedAttention (vLLM) | Traditional Contiguous Allocation |
|---|---|---|
Core Allocation Unit | Non-contiguous memory pages (blocks) | Contiguous memory per request sequence |
KV Cache Sharing | Supported (for shared prompt prefixes) | Not supported |
Memory Fragmentation | Eliminated via block-level management | High (external fragmentation from variable-length sequences) |
Memory Overhead | Near-zero waste (< 4% typical) | High waste (up to 50%+ due to padding and pre-allocation) |
Context Window Flexibility | Dynamic, supports very long contexts | Fixed, limited by pre-allocated contiguous space |
Throughput Impact | High (enables larger effective batch sizes) | Reduced (limited by worst-case memory pre-allocation) |
Implementation Complexity | High (requires custom memory manager & attention kernel) | Low (relies on framework's default allocator) |
Optimal Use Case | High-throughput serving with variable, long contexts | Research or static workloads with predictable sequence lengths |
Implementation and Ecosystem
PagedAttention is not an abstract concept but a concrete algorithm implemented within specific inference engines and frameworks. This ecosystem enables its benefits in production systems.
Cloud & Managed Services
Major cloud providers have integrated PagedAttention-based optimizations into their managed AI services, abstracting the infrastructure complexity. Key implementations include:
- Amazon SageMaker with vLLM as a supported deep learning container.
- Google Cloud's Vertex AI offering optimized prediction for open models.
- Microsoft Azure's AI Model Inference optimizations for high-throughput scenarios. These services offer auto-scaling, security, and managed GPUs, allowing enterprises to leverage PagedAttention's efficiency without managing the underlying inference engine.
Orchestration & Scaling (Kubernetes)
Deploying PagedAttention-optimized engines in production requires container orchestration. The standard approach uses Kubernetes with:
- Custom Resource Definitions (CRDs) for managing inference deployments (e.g., using KServe or Kubeflow).
- Horizontal Pod Autoscaler to scale inference workers based on request queue depth or GPU utilization.
- GPU time-slicing or MIG to share expensive hardware across multiple model instances. This layer manages lifecycle, health checks, and resource guarantees, ensuring the low-level memory efficiency translates to system-level reliability.
Performance Benchmarking
The efficacy of PagedAttention is measured through standardized benchmarks that track key inference metrics:
- Throughput (tokens/sec): Increased by 2-4x in vLLM compared to prior systems due to reduced memory contention and better batching.
- Memory Efficiency: Enables longer context windows (e.g., 128K+) on the same GPU hardware by eliminating fragmentation.
- Cost-Per-Token: Directly reduced by the higher throughput and better GPU utilization. Real-world results depend on the model size, sequence length distribution, and batch size, but the algorithm fundamentally shifts the performance frontier for autoregressive decoding.
Frequently Asked Questions
PagedAttention is a foundational algorithm for efficient large language model inference. These questions address its core mechanisms, benefits, and practical implications.
PagedAttention is a memory management algorithm, introduced by the vLLM inference engine, that treats the Key-Value (KV) cache—a memory-intensive intermediate state generated during autoregressive text generation—as non-contiguous, virtual pages. It works by dynamically allocating physical blocks of GPU memory (pages) to store the KV cache for different requests and sequences, analogous to how an operating system manages virtual memory. This allows for:
- Elimination of Internal Fragmentation: Traditional methods pre-allocate a large, contiguous block of memory for each request's maximum potential sequence length, wasting space if the actual sequence is shorter. PagedAttention allocates only the pages needed for the tokens generated so far.
- Efficient Memory Sharing: For use cases like parallel sampling (generating multiple outputs from one prompt) or beam search, the KV cache for the shared prompt context can be stored in a single set of pages and referenced by multiple sequences, drastically reducing memory duplication.
- Support for Very Long Contexts: By managing memory in fixed-size pages, the system can handle sequences that exceed the pre-allocated contiguous memory of traditional systems, enabling longer context windows without out-of-memory errors.
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 component of a broader ecosystem of techniques and systems designed to optimize the cost, latency, and efficiency of large language model inference. Understanding these related concepts is essential for engineering performant, scalable LLM applications.
KV Caching
KV caching is the foundational optimization that PagedAttention manages. During autoregressive generation, the key and value tensors for all previously processed tokens are stored in a cache. This eliminates the need to recompute these tensors for the prompt and prior context on every new token generation, dramatically reducing computational load and latency. PagedAttention's innovation is treating this KV cache as a virtual, paged memory system.
- Core Mechanism: Stores computed attention states to avoid redundant computation.
- Direct Relationship: PagedAttention is a memory management algorithm specifically for the KV cache.
Continuous Batching
Continuous batching (or iterative batching) is an inference scheduling technique that dynamically groups incoming requests of varying sequence lengths into a single batch to maximize GPU utilization. It is highly synergistic with PagedAttention. While continuous batching manages request scheduling, PagedAttention efficiently manages the memory for the variable-length KV caches those requests produce, preventing wasted memory from fragmentation.
- Synergy: PagedAttention enables the memory efficiency required for robust continuous batching.
- Combined Goal: Both techniques aim to maximize GPU throughput and reduce latency.
Memory Fragmentation
Memory fragmentation is the critical problem PagedAttention was designed to solve. In naive LLM serving, allocating and deallocating variable-length KV caches for different requests leads to scattered, unusable gaps of free memory within the GPU's high-bandwidth memory (HBM). This severely limits the batch size and context length. PagedAttention treats memory in fixed-size pages, allowing non-contiguous allocation and efficient reuse, effectively eliminating fragmentation.
- Problem Defined: Wasted GPU memory due to inefficient allocation patterns.
- PagedAttention's Solution: Uses a paging system, inspired by operating systems, to manage cache memory.
Attention Mechanism
The attention mechanism is the core transformer layer component that computes contextual relationships between tokens. PagedAttention optimizes the memory footprint of one specific part of this mechanism: the caching of intermediate key and value tensors. Understanding attention is prerequisite to understanding what is being cached and why managing that cache is so performance-critical.
- Foundation: The attention computation generates the KV tensors that are cached.
- Performance Bottleneck: Attention is computationally expensive; KV caching is the primary optimization to reduce its cost during generation.
Operator Fusion & Kernel Optimization
Operator fusion and low-level kernel optimization are complementary inference optimizations that occur at a different layer of the stack. While PagedAttention optimizes memory management and scheduling, kernel optimizations like those in FlashAttention or within vLLM's custom kernels make the actual computation of attention and other operations faster. These techniques work in tandem: efficient memory layout (PagedAttention) enables more effective kernel execution.
- Different Layer: PagedAttention is a system-level algorithm; kernel optimizations are hardware-level code.
- Shared Goal: Both are essential for achieving low latency and high throughput in LLM inference.

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