Paged Attention Explained: How OS Paging Fixes GPU Memory Waste in LLMs
A Humanitarians AI fellow explains how PagedAttention splits each request's KV cache into small non-contiguous blocks instead of one reserved slab. The change cuts wasted memory sharply and lets a server handle more requests at once.
Imagine a server handling a hundred conversations with a language model at the same time. Each conversation needs its own slice of GPU memory to hold everything the model has generated so far. This video, presented by a fellow at Humanitarians AI, explains how PagedAttention solves the problem of reserving that memory, and why the fix comes from an old idea in operating systems.
The memory problem in multi-tenant serving
Every active conversation needs GPU memory for its key and value cache, the stored record of what has been processed so far. The video frames the dilemma plainly. If a server reserves too little, long conversations break. If it reserves the maximum for everyone, most of that memory simply sits empty.
Before PagedAttention, most serving systems handled this by giving each request one contiguous slab of memory, sized for the longest sequence the system allowed. A short reply therefore still held room for thousands of tokens it would never use.
How much memory the slab approach wastes
The paper behind PagedAttention measured the damage: 60 to 80 percent of the cache memory went to waste. The video asks the viewer to picture one giant reserved block per conversation with only a sliver holding real generated tokens. The rest waits for tokens that may never arrive. Nobody else can use it, even while other requests are queued for space.
Paging the KV cache
PagedAttention borrows paging from operating systems. Instead of one contiguous slab, each sequence's key and value cache is split into small fixed-size blocks of 16 tokens each. In the original design, a block table maps each sequence's logical blocks to wherever they actually sit in physical memory. The blocks are scattered rather than sequential, exactly as a page table maps virtual memory to physical RAM.
Blocks are allocated one at a time, only as new tokens are generated, and never reserved in advance. Every block before the last one is completely full. Only the final, in-progress block can be partly empty, so the most any single sequence can waste is less than one block: a few tokens rather than a few thousand.
Sharing memory between requests
Because sequences are just pointers into a shared pool of blocks, requests can share memory. If you ask a model for several sampled outputs from the same prompt, or run a beam search, every candidate starts by pointing at the same prompt blocks. A block is copied only if and when one candidate's tokens diverge from another's.
What the results show
Measured against the same fragmented systems, KV cache waste falls from the 60 to 80 percent range to under 4 percent. Almost every byte allocated holds a real token. That reclaimed memory goes straight into serving more requests at once. vLLM, the engine built around this technique, reported two to four times the throughput of the strongest prior systems, with the gap widening on longer sequences, which is where fragmentation used to hurt most.
What PagedAttention does not do
The video is careful about the limits. PagedAttention is a memory manager, not a shortcut around attention's own math. It applies an operating system idea to the KV cache, and the throughput gain comes because freed memory now serves more requests. It does not make attention itself cheaper. A longer, more shared cache is still more work to attend across.
Key takeaways
- Giving each request one contiguous slab sized for the longest sequence wastes 60 to 80 percent of KV cache memory.
- PagedAttention splits each sequence's cache into fixed 16-token blocks that need not sit next to each other.
- A block table maps logical blocks to physical locations, like a page table in an operating system.
- Blocks are allocated only as tokens are generated, so waste per sequence is under one block.
- Sampled outputs and beam search candidates can share prompt blocks and copy only when they diverge.
- Waste drops to under 4 percent, and vLLM reported two to four times the throughput.
- It is a memory management technique and does not reduce the cost of attention itself.
Try it yourself
If you serve a model yourself, check how your KV cache is actually allocated. Find out whether each request gets one reserved slab, or whether blocks are handed out only as tokens arrive. That single answer tells you how much memory your setup may be leaving idle.
Chapters
- 0:00The memory bottleneck of multi-tenant LLM serving
- 0:20Why contiguous slab allocation wastes 60% to 80% of KV cache memory
- 0:45How PagedAttention uses block tables to allocate 16-token blocks on demand
- 1:10Memory sharing across prompt blocks and beam search candidates
- 1:30Slashing waste under 4% to achieve 2x to 4x throughput gains
Full transcript(auto-generated, with timestamps)
The memory bottleneck of multi-tenant LLM serving
[0:00]Hi, I am Simba. Say a server is handling a hundred conversations with a language model at once. Each one needs its own slice of GPU memory for everything it's generated so far. Reserve too little and long conversations break. Reserve the max for everyone and most of that memory just sits empty. That's the problem page
Why contiguous slab allocation wastes 60% to 80% of KV cache memory
[0:21]Detention solves. Paged detention splits each request's cache into small fixedsiz blocks that don't have to sit next to each other in memory. So nothing is reserved for tokens that might never come. Before this, most serving systems gave each request one contiguous slab of memory sized for the longest sequence allowed. A short reply still reserving room for thousands of tokens it would
How PagedAttention uses block tables to allocate 16-token blocks on demand
[0:45]Never use. The paper behind this technique measured the damage. 60 to 80% of that memory going to waste. Picture that memory as one giant reserved block per conversation. Only a sliver of it holding real generated tokens. The rest sits empty, waiting for tokens that may never arrive, unusable by anyone else, even while other requests are cued for space. Paged attention borrows an old
Memory sharing across prompt blocks and beam search candidates
[1:11]Idea from operating systems. Paging. Instead of one contiguous lab, each sequence's key and value cache is split into small fixed-siz blocks, 16 tokens each. In the original design, a block table maps each sequence's logical blocks to wherever they actually sit in physical memory, scattered, not
Slashing waste under 4% to achieve 2x to 4x throughput gains
[1:32]Sequential, exactly like a page table maps virtual memory to physical RAM. Blocks get allocated one at a time only as new tokens are actually generated, never reserved in advance. Every block before the last one is completely full. Only the final in progress block can be partly empty. So the absolute most any single sequence can waste is less than one block, a few tokens, not a few thousand. Because sequences are just pointers into a shared pool of blocks, requests can share memory, too. Ask a model for several sampled outputs from the same prompt or run a beam search and every candidate starts by pointing at the exact same prompt blocks. Copied only if and when one candidates's tokens actually diverge from anothers. The result measured against those same fragmented systems. KV cash waste drops from that 60 to 80% down to under 4%. Almost every bite allocated is a bite
Actually holding a real token. That reclaimed memory goes straight into serving more requests at once. V LLM, the engine built around this technique, reported two to four times the throughput of the strongest prior systems with the gap widening on longer sequences exactly where fragmentation used to hurt most. So paged detention is a memory manager, not a shortcut around attention's own math. It applies an operating system idea paging to the KV cache, cutting waste from 60 to 80% down to under four and buying two to four times the throughput because that freed memory now serves more requests. What it doesn't do is make attention itself cheaper. A longer, more shared cache is still more work to attend across. Your turn. If you're serving a model yourself, check how your KV cache is actually allocated. One reserved slab per request or blocks handed out only as tokens arrive. How page detention works.
More from Humanitarians AI Fellows
2:14Deterministic vs Probabilistic AI: When Guessing is Dangerous
5:00How Kafka Handles Millions of Events: Architecture Explained
1:46How Do You Know AI Is Right? Moving Beyond the Demo
1:39Brutalist AI Video Production & Content Pipeline Progress | Akshay Chavan
1:51The 512 Token Blind Spot: How Truncation Ruins AI Accuracy
4:29