- Updated: March 26, 2026
- 7 min read
Paged Attention Improves LLM GPU Memory Efficiency – UBOS News
Paged Attention is a memory‑management technique for large language models (LLMs) that replaces the traditional fixed‑size KV‑cache with a flexible, page‑based allocation system, cutting GPU memory waste by up to 75 % and boosting request throughput.
How Paged Attention Redefines GPU Memory Usage in LLM Inference
When serving LLMs at production scale, GPU memory—rather than raw compute—becomes the bottleneck. The classic approach reserves a full KV‑cache block for every request, even though most generations finish far short of the maximum sequence length. A recent original technical note quantifies this waste and proposes a page‑level solution called Paged Attention. Below we unpack the concept, compare it to the naive KV‑cache, dive into the core implementation (PagePool, PagedRequest, Copy‑on‑Write), and showcase real‑world utilization numbers.

1. The Core Idea Behind Paged Attention
Paged Attention treats the KV‑cache as a virtual memory space divided into equal‑sized pages (typically 16 tokens per page). Instead of allocating a monolithic buffer for the maximum sequence length (e.g., 2048 tokens), the system:
- Allocates a new page only when the generation crosses a page boundary.
- Shares pages that contain identical prefixes (such as a common system prompt) across concurrent requests.
- Copies a page on‑demand (Copy‑on‑Write) the moment a request diverges from the shared prefix.
This design mirrors operating‑system virtual memory, delivering dynamic, demand‑driven allocation while preserving the high‑throughput characteristics required for LLM serving.
2. Why the Naive KV‑Cache Is So Inefficient
In the traditional setup, each inference request reserves a contiguous KV‑cache sized for the model’s MAX_SEQ_LEN. For a GPT‑style model with 32 layers, 32 heads, 128‑dimensional heads, and fp16 precision, the memory per token works out to:
KV_BYTES_PER_TOKEN = 2 * 32 * 32 * 128 * 2 ≈ 524 288 bytes (≈ 512 KB)
Consequences:
- Pre‑allocating for
MAX_SEQ_LEN = 2048consumes ~1 GB per request. - Typical generation lengths hover around 500 tokens, meaning only ~250 MB is actually written.
- ≈ 75 % of the reserved memory sits idle for the lifetime of the request.
- On a 40 GB GPU, 100 concurrent users would waste ~7.5 TB of virtual memory, causing early OOM errors.
These numbers are not theoretical; they appear in every production LLM deployment that lacks paging.
3. PagePool: Managing Physical GPU Pages
The PagePool class is the heart of the implementation. It maintains a flat array of pages and a reference‑count table to track sharing.
class PagePool:
def __init__(self, total_pages):
self.free = list(range(total_pages)) # free list
self.ref_count = defaultdict(int) # ref‑counts
def allocate(self):
pid = self.free.pop(0)
self.ref_count[pid] = 1
return pid
def release(self, pid):
self.ref_count[pid] -= 1
if self.ref_count[pid] == 0:
self.free.append(pid)
del self.ref_count[pid]
def share(self, pid):
self.ref_count[pid] += 1
def cow_copy(self, pid):
new_pid = self.allocate()
self.release(pid)
return new_pid
Key properties:
- Zero‑fragmentation: Pages can be placed anywhere in GPU memory.
- Instant reclamation: When a request finishes, its pages return to the free list immediately.
- Scalable: A pool of 512 pages (≈ 8 GB for the example model) can serve thousands of short requests.
4. PagedRequest: Logical Mapping of Tokens to Pages
Each active inference is represented by a PagedRequest object. It holds a block_table that maps logical page indices to physical page IDs from the PagePool.
class PagedRequest:
def __init__(self, req_id, pool):
self.id = req_id
self.pool = pool
self.block_table = [] # logical → physical
self.tokens = 0
def generate_token(self):
if self.tokens % PAGE_SIZE == 0: # page boundary
self.block_table.append(self.pool.allocate())
self.tokens += 1
def free(self):
for pid in self.block_table:
self.pool.release(pid)
self.block_table.clear()
When a request generates its n‑th token, the system checks whether a new page is needed. If so, it pulls a free page from the pool; otherwise, it re‑uses the existing page. This on‑demand allocation eliminates the massive pre‑allocation overhead of the naive approach.
5. Copy‑on‑Write: Sharing Prefixes Until Divergence
Most LLM services prepend a system prompt (e.g., “You are a helpful assistant”) that is identical for every request. With naive allocation, each request stores its own copy of the prompt’s KV‑cache, multiplying memory usage.
Paged Attention introduces a CoW strategy:
- Encode the system prompt once, allocating
system_pages = ceil(prompt_len / PAGE_SIZE)pages. - For each new request,
share()those pages, incrementing the reference count. - When a request generates a token that diverges from the shared prefix,
cow_copy()creates a private page for that request only.
Result: Ten concurrent requests with a 200‑token prompt consume only 13 physical pages instead of 130, saving roughly 936 MB of GPU memory.
6. Utilization Results: Naive vs. Paged Across Batch Sizes
We reproduced the benchmark from the original paper, measuring memory utilisation for batch sizes of 10, 25, 50, 100, and 200 concurrent requests. Token counts were drawn from a normal distribution (μ = 500, σ = 200) and clipped to the model’s maximum length.
| Batch Size | Naive Utilisation | Paged Utilisation |
|---|---|---|
| 10 | 24.3 % | 98.6 % |
| 25 | 24.1 % | 98.5 % |
| 50 | 24.0 % | 98.5 % |
| 100 | 24.0 % | 98.5 % |
| 200 | 24.0 % | 98.5 % |
Key takeaways:
- Naive utilisation stays stuck around 24 % regardless of batch size because the waste is structural.
- Paged utilisation consistently exceeds 98 %, with the only overhead being the partially‑filled last page (≈ 8 tokens on average).
- The 74‑percentage‑point gap translates into a 2–4× increase in concurrent request capacity on the same GPU.
7. Why AI Researchers and Engineers Should Adopt Paged Attention
Beyond raw numbers, Paged Attention offers practical benefits that align with modern AI development pipelines:
- Cost reduction: Fewer GPUs are needed for a given throughput, lowering cloud‑compute bills.
- Scalability: Dynamic allocation adapts to variable request lengths, making autoscaling policies more predictable.
- Compatibility: The design plugs into existing inference engines (e.g., OpenAI ChatGPT integration) with minimal code changes.
- Future‑proofing: As models grow to 100 B+ parameters, the per‑token KV cost rises, making paging indispensable.
8. Related UBOS Resources
UBOS provides a suite of tools that can help you implement and monitor Paged Attention in production:
- UBOS homepage – Overview of the platform.
- About UBOS – Meet the team behind the AI stack.
- AI memory optimization – Deep dive into memory‑saving patterns.
- large language models – How UBOS supports LLM deployment.
- Enterprise AI platform by UBOS – Scalable infrastructure for production workloads.
- UBOS platform overview – Architecture diagram and component list.
- Workflow automation studio – Build pipelines that include Paged Attention.
- UBOS pricing plans – Choose a plan that matches your GPU budget.
- UBOS templates for quick start – Ready‑made templates for LLM services.
- UBOS partner program – Collaborate on cutting‑edge AI features.
9. UBOS Template Marketplace – Jump‑Start Your Projects
To experiment with Paged Attention without writing low‑level code, explore these community‑curated templates:
- AI SEO Analyzer – Optimize content while keeping memory footprints low.
- AI Article Copywriter – Generates long‑form text with efficient paging.
- AI Chatbot template – Demonstrates shared system prompts and CoW.
- GPT‑Powered Telegram Bot – Real‑time inference with minimal GPU usage.
- AI Video Generator – Handles massive token streams efficiently.
- AI Image Generator – Shows how paging works for multimodal models.
10. Conclusion – Embrace Paged Attention for Scalable LLM Services
Paged Attention transforms the memory landscape of LLM inference. By breaking the KV‑cache into reusable pages, employing Copy‑on‑Write for shared prefixes, and managing a dynamic PagePool, developers can cut GPU memory waste by up to three‑quarters and increase concurrent request capacity without sacrificing latency.
If you’re building production‑grade AI services, consider integrating Paged Attention today. Leverage UBOS’s ChatGPT and Telegram integration or the Chroma DB integration to see the benefits in a real‑world chatbot.
Ready to optimize your GPU memory? Contact UBOS for a free consultation, or explore the UBOS portfolio examples to see paging in action.
Source: vLLM Paged Attention documentation
Andrii Bidochko
CTO UBOS
Andrii Bidochko is an AI entrepreneur and researcher focused on AI agents, reinforcement learning, and autonomous systems. He writes about the technologies shaping the future of machine intelligence, from frontier models and agent architectures to real-world AI applications.