---
title: What problem does PagedAttention solve, and how does it enable prefix sharing?
url: https://gurkanozkan.ai/learn/questions/applied-llm-srv-03/
markdown: https://gurkanozkan.ai/learn/questions/applied-llm-srv-03.md
kind: question
role: Applied LLM
stage: Technical
difficulty: Hard
json: https://gurkanozkan.ai/api/learn/questions/applied-llm-srv-03.json
robots: noindex
---

# What problem does PagedAttention solve, and how does it enable prefix sharing?

Applied LLM · Technical · Hard

## Answer

*Model answer, written in a candidate's voice*

### In short

- Contiguous per-request KV reservations waste memory and fragment the cache, capping batch size.
- Fixed-size KV blocks plus a per-request block table allocate memory on demand, like virtual memory.
- Shared prefixes are referenced by multiple sequences; copy-on-write splits blocks only when they diverge.
- Block hashes enable automatic prefix caching and reuse across requests.
- Larger batches improve throughput; block size trades metadata/lookup overhead against internal fragmentation and sharing granularity.

### In full

PagedAttention solves the KV-cache memory problem in LLM serving: reserving one contiguous region per request over-reserves space for the worst case and leaves fragmented, unusable gaps, so fewer requests can be batched. It instead stores KV in fixed-size blocks and keeps a block table per sequence that maps logical blocks to physical blocks, allocating blocks on demand as tokens are generated. Because the block table is an indirection layer, several sequences can point at the same physical blocks (tracked with reference counts), so common prefixes such as system prompts or shared context can be stored once and referenced by many sequences; when parallel samples, beams, or later requests diverge, copy-on-write allocates new blocks only for the divergent suffix. Hashing blocks by their token/prefix content also enables automatic prefix caching, so a later request can reuse already-computed prefix blocks instead of recomputing them. The payoff is higher effective batch sizes and throughput, with block size as a trade-off: larger blocks reduce metadata and lookup overhead but waste tail space and share more coarsely, while smaller blocks reduce waste and improve sharing granularity but add more blocks and bookkeeping.

*Corrected by an independent AI reviewer.*

## What a strong answer covers

- Contiguous per-request KV reservations cause fragmentation and over-reservation
- Fixed-size blocks plus a block table (like virtual memory), allocated on demand
- Copy-on-write sharing for common prefixes, parallel samples, beam search; automatic prefix caching via block hashes
- Higher batch sizes → throughput; block-size trade-offs

## Common mistakes

- Thinking it shrinks bytes per token
- conflating it with API-level prompt caching

## Topic guides

- [KV cache](https://gurkanozkan.ai/learn/topics/kv-cache.md)
- [LLM serving: latency, throughput and operations](https://gurkanozkan.ai/learn/topics/serving.md)
---

*Study material compiled with AI: drafted by a local model (Inkling 2 Mini) from public sources, then checked against those sources by independent AI reviewers (Claude) in November 2026. Not reviewed line by line by a person.*
