Skip to content
Inference Academy

PagedAttention interview questions

PagedAttention interview questions with model answers: the KV cache fragmentation problem, block tables, block size trade-offs, prefix sharing and copy-on-write, and how vLLM and SGLang manage KV memory.

5 questions·Model answers and follow-upsFree
Share

PagedAttention is the idea that made vLLM's throughput jump, and it comes up in nearly every interview about serving. The core is an operating-systems analogy: manage KV cache memory in fixed-size pages with a per-sequence page table, instead of one contiguous buffer per request.

Question 1

What problem does PagedAttention solve?

Model answer

Before PagedAttention, serving systems reserved a contiguous KV cache buffer for each request, sized for the maximum possible length because the output length is unknown in advance. That wasted memory three ways:

  • Reservation waste: space for tokens that might never be generated.
  • Internal fragmentation: a request that stops early leaves most of its buffer unused.
  • External fragmentation: free memory is split into gaps too small for a new request's buffer.

The vLLM paper measured that existing systems used only about 20 to 40 percent of KV cache memory for actual token state. Because KV memory caps the batch size and decode throughput rises with batch size, wasted memory directly meant lower throughput.

PagedAttention stores the cache in fixed-size blocks (vLLM's default is 16 tokens) allocated on demand from a shared pool, so waste is limited to the last, partly filled block of each sequence (under 4 percent in the paper). The result was 2 to 4 times higher throughput than earlier systems at the same latency.

Likely follow-up questions

  • Why is the output length unknown in advance, and how does that relate to the reservation problem?
  • What would a simpler fix, like allocating in large chunks, get you?
  • Does PagedAttention reduce the total memory a single long request needs?

Question 2

How does a block table work in PagedAttention?

Model answer

Each sequence has a block table that maps its logical block numbers (tokens 0 to 15, 16 to 31 and so on) to physical block IDs in a GPU memory pool. When a sequence fills its last block, the block manager hands it a free physical block from the pool and appends the ID to its table. When the sequence finishes, its blocks go back to the free list.

The attention kernel receives the block tables for the batch. For each query it walks the sequence's table, loads the keys and values from the physical blocks wherever they are, and computes attention as if the cache were contiguous. The indirection costs a little in the kernel but makes allocation trivial and fragmentation negligible.

It is the same idea as virtual memory: logical pages, physical frames, a page table, and pages shared or copied on write.

Likely follow-up questions

  • What is stored per physical block, exactly, across layers and heads?
  • How does the block table get to the GPU each step, and why does that matter for CPU overhead?
  • How does the kernel handle the last, partially filled block?

Question 3

How do block size choices trade off?

Model answer

  • Smaller blocks (8 or 16 tokens) waste less memory per sequence and make prefix sharing finer-grained, so more cache hits.
  • Larger blocks (32 to 128 tokens or more) mean fewer table entries, less indirection and more contiguous loads in the attention kernel, which can be faster, and smaller metadata to send each step.

The default of 16 tokens is a balance for GPU kernels. Some backends prefer larger blocks for their kernels, and hybrid models with sliding-window or state-space layers complicate the picture because different layers need different amounts of cache.

Likely follow-up questions

  • With a block size of 16 and 256 concurrent sequences, what is the worst-case wasted memory for Llama 3 8B?
  • How does block size affect prefix cache hit rate for prompts that differ by one token near the start?
  • Why might an FP8 KV cache change the best block size?

Question 4

How does PagedAttention enable prefix sharing and parallel sampling?

Model answer

Because sequences refer to blocks by ID, several sequences can point at the same physical blocks. Each block keeps a reference count.

  • Parallel sampling and beam search: nn completions of one prompt share the prompt's blocks instead of copying them. When one sequence needs to write into a shared block (its last, partly filled block), the engine does copy-on-write: allocate a new block, copy, and write to the copy.
  • Automatic prefix caching: vLLM hashes each full block together with everything before it. A new request whose prompt starts with the same tokens finds those block hashes in the cache and reuses the blocks, skipping that part of prefill. Freed blocks stay cached until they are evicted, usually least recently used first.

SGLang's RadixAttention reaches a similar result with a radix tree over token sequences, which matches prefixes at token granularity and lets the scheduler order requests to increase hits.

Likely follow-up questions

  • Why must the hash for a block include all previous tokens, not just its own?
  • What workloads see the largest gains from prefix caching?
  • How can prefix caching leak information between tenants, and how would you prevent it?

Question 5

What are the downsides or limits of PagedAttention?

Model answer

  • The attention kernel must gather keys and values through the block table, which adds indirection and can be slower than a contiguous layout. Kernel work since the original paper has narrowed this gap.
  • Block tables and metadata must be built on the CPU and sent each step; with small models and large batches that host-side work can bottleneck the GPU.
  • Every attention kernel (FlashAttention, FlashInfer, custom ones) needs a paged variant, which slows the adoption of new kernels.
  • It does not reduce the KV cache size per token; it only stops it being wasted. For that you need GQA, MLA or KV quantisation.

An alternative some systems use is to reserve virtual address space contiguously and map physical pages behind it with CUDA virtual memory APIs, which keeps kernels unchanged while still allocating physical memory on demand.

Likely follow-up questions

  • When would you choose a contiguous KV layout instead?
  • How does PagedAttention interact with tensor parallelism?
  • What does offloading paged blocks to CPU memory look like?

The lesson behind these answers · 24 min · Pro, first part free

vLLM for production serving

Worked numbers, step-through diagrams and a quiz, so you can derive the answer in the interview instead of reciting it.

Read the lesson →

Articles on this topic

Related interview questions

All interview topics →