PagedAttention
PagedAttention is an attention algorithm that stores a model’s key-value cache (KV cache) in fixed-size blocks scattered across GPU memory, applying the paging technique that operating systems use for virtual memory.
During autoregressive generation, a request accumulates key and value vectors for every token it has processed, so its cache keeps growing and its final size isn’t known in advance. Serving systems that reserve one contiguous slab per request lose much of that memory to fragmentation and over-reservation. PagedAttention allocates small blocks on demand and keeps a per-request block table that maps logical token positions to physical blocks.
The simulation below runs the same request stream under both schemes, with dashed blocks marking memory that was reserved but never filled.
The block table also lets requests share blocks, so a common prompt prefix is stored once and copied only when generations diverge. Reclaiming the wasted memory lets a server batch more concurrent requests, which raises throughput at comparable latency. The 2023 vLLM paper introduced the algorithm, and other inference servers such as TensorRT-LLM added paged KV caches soon after.
Related Resources
Tutorial
How to Use Ollama to Run Large Language Models Locally
Learn how to use Ollama to run large language models locally. Install it, pull models, and start chatting from your terminal without needing API keys.
For additional information on related topics, take a look at the following resources:
- Hugging Face Transformers: Leverage Open-Source AI in Python (Tutorial)
- Memory Management in Python (Tutorial)
- How Python Manages Memory (Course)
- Python mmap: Improved File I/O With Memory Mapping (Tutorial)
- Caching in Python Using the LRU Cache Strategy (Tutorial)
- How to Use Ollama to Run Large Language Models Locally (Quiz)
- Hugging Face Transformers (Quiz)
- Memory Management in Python (Quiz)
- Python mmap: Doing File I/O With Memory Mapping (Course)
- Caching in Python With lru_cache (Course)
By Martin Breuss • Updated Aug. 20, 2026