PagedAttention is a memory management algorithm, introduced by the vLLM serving engine, that manages the KV cache in non-contiguous, paged blocks. This approach is directly analogous to how operating systems manage virtual memory using paging. By allocating memory in fixed-size blocks, it eliminates the internal fragmentation caused by variable-length sequences, allowing for highly efficient GPU memory utilization and enabling much higher request concurrency during inference.
Glossary
PagedAttention

What is PagedAttention?
PagedAttention is a memory management algorithm for transformer-based large language models (LLMs) that dramatically reduces memory waste and increases serving throughput by managing the Key-Value (KV) cache in non-contiguous, paged blocks.
The algorithm treats the KV cache of each request's sequence as a set of blocks that can be physically scattered in memory but logically contiguous. This paged KV cache allows for near-zero memory waste, as new sequences can reuse freed blocks from completed ones. This efficient management is the core innovation enabling vLLM to achieve state-of-the-art throughput and support advanced features like continuous batching with variable-length sequences without performance degradation.
Key Features and Benefits
PagedAttention is a memory management algorithm for transformer inference that treats the KV cache like virtual memory, organizing it into non-contiguous, fixed-size blocks. This approach directly addresses the core inefficiencies of serving variable-length sequences at scale.
Eliminates Memory Fragmentation
Traditional KV cache allocation reserves a contiguous block of memory for the maximum possible sequence length of each request, leading to severe internal fragmentation as most sequences are shorter. PagedAttention allocates memory in fixed-size blocks (pages). Only the blocks actually containing KV data are allocated, dramatically reducing wasted memory. This allows more concurrent requests to be served on the same GPU hardware.
Enables Efficient Memory Sharing
PagedAttention's block-level abstraction enables powerful optimizations:
- Shared Prompts: In multi-tenant or chatbot scenarios, many requests may share a common system prompt or context. PagedAttention allows these shared tokens' KV caches to be stored in read-only memory blocks, referenced by all relevant requests. This eliminates redundant storage and computation.
- Beam Search: During beam search, multiple candidate sequences share a common prefix. PagedAttention stores the prefix's KV cache once, with all beams holding references to the same physical blocks.
Optimizes for Variable-Length Sequences
Real-world LLM workloads are highly variable; input prompts and output generations have unpredictable lengths. PagedAttention's paged design is inherently flexible:
- New blocks are allocated on-demand as generation progresses.
- Finished requests release their blocks immediately, making memory available for new requests.
- This dynamic allocation is analogous to an operating system managing heap memory for processes, providing optimal utilization for irregular, real-time workloads.
Increases Serving Throughput & Concurrency
By drastically reducing memory waste, PagedAttention directly increases the number of concurrent requests a single GPU can handle. This translates to higher Tokens Per Second (TPS) at the system level and lower cost per token. For example, vLLM demonstrated throughput increases of up to 24x compared to prior systems like Hugging Face Transformers by leveraging PagedAttention to serve more users simultaneously without additional hardware.
Analogy to Virtual Memory
PagedAttention's mechanism is a direct translation of OS virtual memory concepts to the KV cache:
- KV Cache Block = Physical Memory Page: A fixed-size unit of storage.
- Logical Block Table = Page Table: Each request maintains a table mapping its logical token positions to physical block IDs.
- Block Allocation = Memory Allocation: The system manages a free list of available blocks. This proven abstraction provides a robust, predictable foundation for managing the LLM's most memory-intensive component during inference.
PagedAttention vs. Traditional KV Cache Allocation
This table compares the core architectural differences between the PagedAttention algorithm and traditional contiguous KV cache allocation, highlighting their impact on memory efficiency, performance, and operational flexibility during LLM inference.
| Feature / Metric | Traditional KV Cache Allocation | PagedAttention (vLLM) |
|---|---|---|
Allocation Strategy | Contiguous, monolithic blocks per sequence | Non-contiguous, paged blocks (analogous to OS virtual memory) |
Memory Fragmentation | High (due to variable sequence lengths and pre-allocation) | Near-zero (pages are allocated and freed independently) |
Memory Waste | Significant (up to 60-80% in practice due to over-provisioning) | Minimal (memory used is proportional to actual cached tokens) |
Handling of Long Sequences | Inefficient; requires large contiguous free space | Efficient; sequences can span multiple non-adjacent pages |
Support for Variable-Length & Concurrent Requests | Poor; static allocation leads to underutilization | Excellent; dynamic page allocation maximizes GPU utilization |
Throughput (Tokens/Second) Impact | Lower; limited by memory fragmentation and waste | Higher (up to 23x reported); enables greater request concurrency |
Implementation Complexity | Lower (simple pre-allocation) | Higher (requires a memory manager and block table) |
Optimal Use Case | Simple, predictable workloads with fixed sequence lengths | Production serving with highly variable, concurrent requests |
Implementation and Ecosystem
PagedAttention is not just an algorithm but a foundational component of modern, high-performance LLM serving systems. Its implementation has catalyzed a new generation of inference engines and optimization techniques.
Core Algorithm: Virtual Memory for KV Cache
PagedAttention manages the KV (Key-Value) cache by dividing it into fixed-size blocks, analogous to memory pages in an operating system. These blocks are allocated non-contiguously in physical GPU memory.
- Block Table: Each request's sequence is tracked via a block table that maps logical blocks to physical memory addresses.
- On-Demand Allocation: Blocks are allocated only when new tokens are generated, eliminating pre-allocation waste.
- Shared Memory: Identical prompt prefixes across requests can share the same physical blocks, a powerful form of memory deduplication. This virtual memory abstraction is what enables vLLM to achieve near-zero memory waste and support very long context windows efficiently.
vLLM: The Reference Implementation
vLLM is the high-throughput, open-source LLM serving engine that introduced and popularized PagedAttention. It is the de facto reference implementation.
- Architecture: vLLM integrates PagedAttention into a production-grade serving system with features like continuous batching and efficient scheduling.
- Performance Impact: Benchmarks show vLLM can serve models like Llama 2 with up to 24x higher throughput compared to previous systems like Hugging Face Transformers, primarily due to superior KV cache management.
- Ecosystem Role: It has become a critical backend for inference platforms and a benchmark for new optimization research. Learn more: https://github.com/vllm-project/vllm
Memory Efficiency & Fragmentation Reduction
The primary engineering benefit of PagedAttention is the drastic reduction of memory fragmentation, which directly translates to cost savings and higher concurrency.
- Traditional Problem: Sequential, contiguous allocation for variable-length sequences leads to unusable gaps between requests (external fragmentation) and wasted reserved space within requests (internal fragmentation).
- PagedAttention Solution: By using small, fixed-size blocks, free memory is pooled and can be allocated to any request. This eliminates external fragmentation and minimizes internal waste to at most one block per request.
- Result: GPU memory utilization can approach 99%, allowing more concurrent requests or longer contexts on the same hardware.
Enabling Advanced Serving Features
PagedAttention's block-level abstraction unlocks sophisticated serving optimizations that are difficult or impossible with contiguous cache management.
- Shared Prompts: As mentioned, common system prompts or few-shot examples are stored once in physical memory and referenced by multiple user requests.
- Parallel Sampling: Techniques like beam search or parallel sampling of multiple outputs from a single prompt can share the cached prompt context blocks.
- Efficient Cache Eviction & Swapping: The block table enables LRU (Least Recently Used) or other policies to evict or swap out less-used blocks to CPU RAM, enabling effective management of extremely long contexts that exceed GPU memory.
Integration with Continuous Batching
PagedAttention is highly synergistic with continuous batching (or in-flight batching), forming the core of modern serving stacks.
- Dynamic Workloads: Continuous batching groups requests of different lengths and adds new requests to a running batch. PagedAttention's non-contiguous allocation is essential to handle this dynamic, heterogeneous mix efficiently.
- Eliminating Padding: Without PagedAttention, variable-length sequences in a batch require padding to the longest sequence, wasting compute and memory. PagedAttention's block-based approach inherently requires no padding for the KV cache.
- Combined Benefit: Together, they maximize GPU utilization for both compute (through batching) and memory (through paging), delivering optimal throughput.
Ecosystem & Alternative Implementations
The success of PagedAttention has influenced the design of other inference systems and sparked research into related optimizations.
- Inspired Systems: Frameworks like LMDeploy (by InternLM) and TensorRT-LLM have incorporated similar block-based KV cache management strategies, validating the core concept.
- Research Extensions: Work like FlashInfer explores kernel-level optimizations for PagedAttention-like operations. VLLM's Blocked KV Cache design is a direct influence.
- Hardware Considerations: The algorithm influences thinking about future GPU memory architectures, highlighting the importance of efficient, fine-grained memory management for LLM inference. This ecosystem growth confirms PagedAttention as a foundational primitive for efficient LLM serving.
Frequently Asked Questions
PagedAttention is a foundational memory management algorithm for efficient LLM inference. These questions address its core mechanics, benefits, and practical applications.
PagedAttention is a memory management algorithm for transformer-based large language models that manages the KV cache in non-contiguous, paged blocks, analogous to virtual memory in operating systems. It works by decoupling the logical sequence of tokens from their physical memory location. Instead of allocating a single, contiguous block of memory for each request's KV cache—which leads to fragmentation due to variable sequence lengths—PagedAttention divides the cache into fixed-size blocks (pages). These blocks are allocated dynamically from a shared pool as new tokens are generated. The system maintains a page table for each request to map its logical token positions to the physical blocks holding their key and value vectors. This allows the GPU's high-bandwidth memory to be utilized near its theoretical maximum, enabling higher batch sizes and concurrency.
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 designed to optimize the cost and efficiency of LLM inference. These related concepts work in concert to manage memory, compute, and financial expenditure.
KV Cache
The KV Cache (Key-Value Cache) is the memory structure that PagedAttention manages. During autoregressive generation, a transformer model computes and stores key and value tensors for each previously generated token. The KV cache prevents redundant computation for these past tokens, drastically reducing latency. However, it can consume gigabytes of memory per concurrent request, making its efficient management—via techniques like PagedAttention—critical for high-throughput serving.
- Purpose: Stores intermediate computations to avoid recomputation.
- Memory Footprint: Grows linearly with sequence length and batch size.
- Optimization Target: The primary target for memory savings in inference engines like vLLM.
Continuous Batching
Continuous Batching (or in-flight batching) is an inference optimization technique that dynamically adds new requests to a running batch as previous requests finish generation. This maximizes GPU utilization by eliminating idle time. PagedAttention complements continuous batching by efficiently handling the variable and unpredictable memory demands of this dynamic scheduling.
- Mechanism: Batches are updated in real-time, not statically formed.
- Efficiency: Achieves much higher GPU utilization than static batching.
- Synergy with PagedAttention: Allows flexible memory allocation for requests entering and exiting the batch at different times.
Memory Fragmentation
Memory Fragmentation occurs when free memory is broken into small, non-contiguous blocks that are unusable for larger allocations. In LLM serving, traditional KV cache management leads to severe fragmentation as variable-length sequences finish, leaving gaps in GPU memory. PagedAttention solves this by using a paging system, analogous to operating systems, where cache blocks can be allocated non-contiguously and reused.
- Problem: Wastes up to 80% of reserved KV cache memory in naive systems.
- Analogy: Similar to disk fragmentation in hard drives.
- Solution: PagedAttention's block-based management allows efficient reuse of freed memory.
Inference Cost
Inference Cost is the total financial expenditure of running a trained model to make predictions. For LLMs, this is dominated by GPU memory and compute time. PagedAttention directly reduces inference cost by allowing more concurrent requests (higher throughput) to run on the same GPU hardware, thereby lowering the cost per token.
- Drivers: GPU instance hours, memory footprint, and throughput.
- Key Metric: Cost per thousand tokens ($/1K tokens).
- Impact of PagedAttention: Increases tokens per second (TPS) for a fixed hardware budget, driving down unit economics.
Tokens Per Second (TPS)
Tokens Per Second (TPS) is the primary throughput metric for LLM serving, measuring how many output tokens a system can generate per second. Higher TPS means lower latency and cost for users. PagedAttention boosts TPS by enabling higher levels of request concurrency within the same GPU memory constraints, as it minimizes wasted memory from fragmentation.
- Business Impact: Directly correlates with user experience and infrastructure cost.
- Optimization Goal: Maximize TPS for a given hardware profile.
- Influence of Memory Management: Efficient KV cache usage (via PagedAttention) is a major lever for improving TPS.

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