PagedAttention: how vLLM manages the KV cache

PagedAttention is often introduced with one sentence: it is virtual memory for the KV cache. The analogy is useful, but it skips the part an inference engineer needs.

What is being paged? Why did contiguous allocation waste so much memory? What changes inside attention, and what stays exactly the same?

This guide follows the PagedAttention paper and the vLLM design documentation.

In this article

  • The problem is a cache with an unknown ending
  • Contiguous allocation wastes memory in two ways
  • Logical blocks separate a sequence from physical memory
  • Walk one request through the allocator
  • PagedAttention changes addressing inside attention
  • Copy-on-write makes shared prefixes practical
  • Better memory use creates room for a larger batch
  • The block size is a real tradeoff
  • PagedAttention does not solve admission control
  • Keep the tensor formula beside the allocator model
  • What to inspect in a real serving engine

Continue reading

This field note is part of Fanout Pro, with the complete archive, courses, labs, and every Daily paper guide.

See plans