How PagedAttention Partitions GPU Memory to Solve the LLM Context Bottleneck
Large language models generate text by storing previous tokens in a temporary memory bank called the KV cache. By dividing this memory into non-contiguous blocks, inference engines can eliminate fragmentation and quadruple the number of users a single server can handle.
By Sofia Matos
- Inference Engine Developers
- Focus on maximizing hardware utilization and throughput.
- Hardware Architects
- Focus on memory bandwidth and physical silicon constraints.
Perspectives this story doesn't cover
- Cloud Infrastructure Providers
- Open-Source Model Developers
The inference scheduler sitting between a large language model and its hardware decides exactly how much memory to allocate to a user's prompt. It can partition the GPU's video RAM into rigid, contiguous chunks, or it can divide it into dynamic, non-contiguous pages. It makes this choice the millisecond a new request arrives, determining whether the server can handle ten concurrent users or a hundred.
When a model like Llama 3 or GPT-4 generates a response, it does not recalculate the entire conversation history for every new word. Instead, it stores the mathematical representations of past words in a temporary storage area known as the Key-Value (KV) cache.
As the model generates more text, this cache grows linearly. In 2023, researchers at UC Berkeley identified that the KV cache was consuming up to 30% of total GPU memory during inference, creating a severe bottleneck that limited concurrent user capacity.[1]
The traditional method for managing this memory was highly inefficient. Schedulers would allocate a large, contiguous block of memory for the maximum possible length of a conversation. If a user only asked a short question, the rest of that allocated memory sat empty and unusable by other requests.
This phenomenon, known as internal memory fragmentation, wasted massive amounts of expensive hardware capacity. According to the UC Berkeley team, "existing systems waste 60% to 80% of memory due to fragmentation and over-reservation."[1]
To solve this, developers introduced PagedAttention, an algorithm inspired by how traditional computer operating systems manage RAM. Instead of reserving one massive block, PagedAttention divides the KV cache into small, fixed-size pages.
Each page typically holds the attention keys and values for a specific number of tokens—often 16 or 32. Crucially, these pages do not need to sit next to each other on the physical silicon.[1]
Each page typically holds the attention keys and values for a specific number of tokens—often 16 or 32.
A central block table tracks where each page is located. When the model needs to reference a past token, the scheduler looks up the virtual address in the block table and translates it to the physical location on the GPU.
This mechanism practically eliminates internal fragmentation. Memory is allocated dynamically, one page at a time, only when the model actually generates a new token that requires storage.
The efficiency gains are measurable and immediate. By implementing PagedAttention in the open-source vLLM engine, developers reduced memory waste to under 4%.[1]
Freeing up that wasted memory allows the server to load more concurrent user requests into the same GPU. In benchmark tests on NVIDIA A100 GPUs, vLLM achieved 2x to 4x higher throughput compared to standard Hugging Face Transformers.[1]
NVIDIA has since integrated similar paging techniques into its TensorRT-LLM software stack. In an August 2023 technical breakdown, NVIDIA engineers noted that optimizing the KV cache is critical because "memory bandwidth is the primary bottleneck for LLM inference."[2]
However, the paging mechanism introduces its own computational overhead. The scheduler must constantly update the block table and perform address translations during the highly latency-sensitive generation phase.
What remains unproven is how well PagedAttention scales as context windows expand from 128,000 tokens to over a million. At those extremes, the block table itself becomes a massive data structure that requires optimization.
The next generation of inference engines will have to decide how to compress the cache itself. Until hardware bandwidth catches up to model size, the software scheduler's ability to pack memory blocks tightly dictates the commercial viability of deploying frontier AI.
What to know
- The KV cache stores past tokens during generation but traditionally wastes up to 80% of memory due to fragmentation.
- PagedAttention divides this memory into small, dynamic blocks, allocating space only when needed.
- This optimization allows inference servers to handle up to four times as many concurrent users on the same hardware.
Key terms
- KV Cache
- A temporary memory bank where a language model stores the mathematical representations of past words to avoid recalculating them.
- Inference
- The phase where a trained AI model generates responses to user prompts.
- Internal Fragmentation
- Wasted memory that occurs when a system reserves a large block of space but only uses a small portion of it.
- Throughput
- The total number of requests or tokens a server can process in a given amount of time.
Reader questions
Why do language models need a cache?
Without a cache, the model would have to re-read and re-process the entire conversation history every time it generates a single new word, which is computationally expensive.
How does PagedAttention save memory?
It divides memory into small blocks and only allocates them when needed, rather than reserving a massive chunk of memory for every user just in case they write a long prompt.
Does this make the AI smarter?
No. PagedAttention is an engineering optimization that makes the AI cheaper and faster to run, but it does not change the quality of the model's answers.
Sources
[1]UC Berkeley vLLM TeamInference Engine DevelopersEfficient Memory Management for Large Language Model Serving with PagedAttention
Read on UC Berkeley vLLM Team →
[2]NVIDIAHardware ArchitectsMastering LLM Techniques: Inference Optimization
Read on NVIDIA →
[3]Factlen Editorial TeamInference Engine DevelopersSynthesis by Factlen editorial team
Read on Factlen Editorial Team →
Comments
More in Artificial Intelligence
See all →AI Infrastructure
How FlashAttention Bypasses the GPU Memory Bottleneck to Enable Long-Context AI
5 sources
Open Source Standards
How the Open Source Initiative's 1.0 Definition Excludes the Most Downloaded Open-Weight AI Models
7 sources
Generative Adversarial Networks
How a Generator and a Discriminator Compete to Create Realistic AI Output
8 sources
Machine Learning
How Generative AI Maps the Joint Probability Distribution of Data
5 sources
Every angle. Every day.
Get Artificial Intelligence stories with full source coverage and perspective breakdowns delivered to your inbox.




