agent-readings / Inference and Serving Infrastructure
Virtual memory for the KV cache
The one sentence
For agents, serving cost is dominated by long, branching, repeated contexts. PagedAttention made high-throughput LLM serving practical by treating context memory as an OS memory-management problem.
Before this paper
High-throughput LLM serving requires batching many concurrent requests.
Each request's KV cache is large, grows dynamically with generated tokens, and shrinks when a request finishes.
Contiguous allocation wastes GPU memory through fragmentation and over-reservation, limiting batch size.
The paper asks how to manage KV-cache memory dynamically so the serving system can keep GPUs full without wasting memory or duplicating shared prefixes.
Core idea
Split KV caches into fixed-size blocks, allocate physical blocks on demand, map logical sequence blocks to physical GPU blocks, and make the attention kernel follow those mappings while the serving engine handles sharing, allocation, and eviction.
Partition each sequence's KV cache into logical token blocks.
Allocate physical KV blocks only as needed instead of reserving a contiguous maximum-length cache.
Maintain a block table for each sequence.
Modify attention kernels to read KV tensors by following block-table entries.
Action grammar
sequence: one active request or decoding branch.
block size: fixed number of tokens represented by each KV block.
logical block id: sequence-local block index.
physical block id: GPU-memory block index.
Executable shape
Evidence
The paper states that KV-cache memory for each request is huge, grows and shrinks dynamically, and can be wasted by fragmentation and duplicate copies when managed inefficiently.
The paper proposes PagedAttention, an attention algorithm inspired by virtual memory and paging techniques from operating systems.
vLLM is described as achieving near-zero waste in KV-cache memory by building on PagedAttention.
The paper says vLLM flexibly shares KV cache within and across requests to further reduce memory usage.
Claim map
KV-cache memory is huge, dynamically sized, and can be significantly wasted by fragmentation and redundant duplication in existing serving systems.
PagedAttention borrows classical virtual-memory paging ideas by allowing non-contiguous KV-cache storage through block mappings.
vLLM builds on PagedAttention to achieve near-zero KV-cache memory waste.
vLLM supports flexible KV-cache sharing within and across requests, including cases such as parallel sampling and shared prompts.
Agent infrastructure
Agent serving needs memory virtualization because long prompts, tool traces, and branchy reasoning make KV cache the scarce resource.
PagedAttention is the same OS move as virtual memory: stable logical context, flexible physical placement.
Copy-on-write KV sharing is directly useful for self-consistency, Tree of Thoughts, retries, and parallel tool-plan candidates that share a prefix.
Serving engines should expose memory pressure as a scheduler signal, not hide it below the request API.
Caveats
The review uses the arXiv paper text and public metadata; detailed per-table benchmark interpretation should still be rechecked before quoting...
PagedAttention improves memory management; it does not reduce model arithmetic per token by itself.
Block-table indirection and allocator details matter for actual kernel performance.
The 2-4x throughput result is workload/baseline-specific.
Run it
No PoC yet - contributions welcome. A small PoC could simulate contiguous KV allocation versus fixed-block paging under variable-length requests and compare memory waste.