esc
  • WorkflowsPages
  • Case studiesPages
  • Machine Learning FoundationsLearn
  • AI EngineeringLearn
  • AI Guardrails & Red TeamingLearn
  • UI/UXLearn
  • Design SystemsLearn
  • Production System DesignLearn
  • AI papersPages
  • Interview KitPages
  • Book a callContact
Let’s talk

I’ll build the agent for it.

What Is PagedAttention and vLLM?

How vLLM keeps a model's working memory in small pages, why that saves GPU memory and what it costs, explained for your AI interview.

In short

PagedAttention is a way to store an AI model's working memory, the KV cache, in small fixed-size blocks instead of one large reserved chunk per request. vLLM is a serving engine built on it, so the same GPU can serve more users at once.

12 min readAdvancedCommon · estimateFacts checked 27 November 2026

Say it out loud

Read it once, then say it without looking. Start with the short one; use the long one when they ask you to go deeper.

PagedAttention is how vLLM stores a chat's working memory on the GPU. Old systems reserved one big space per chat, in case it grew long, so most of it sat empty. PagedAttention cuts that memory into small blocks and gives each chat more only when it needs it, like pages in an operating system. That lets one GPU serve more users at once. The cost is a slower attention step. The paper reports 20 to 26 percent more attention latency than FasterTransformer, and the block size needs tuning.

What is PagedAttention, in plain words?

A chat model keeps a running memory of the conversation so far, called the KV cache. It grows by one entry for every token. A token is a short piece of text, roughly a word or part of one. Nobody knows in advance how long the reply will be. The memory sits on the GPU, the graphics chip that runs the model, and it decides how many chats can run at the same time.

Think of a warehouse that reserves a whole aisle for each customer on the day they book, just in case they fill it. Most aisles stay half empty. A smarter warehouse hands out shelf bays one at a time, as parcels arrive. PagedAttention works like the smarter warehouse. In a bank's support bot, eight chats might be open at once, and any one of them might run long.

Key words

KV cache
The model's saved working memory for one chat, which grows with every token it reads or writes.
Block
A fixed-size slice of cache memory, like one page. In the paper's tests, 16 tokens per block worked well.
Serving engine
The software that runs a model for many users at once, handling queues, memory and replies. vLLM is one.
Attention
The step where the model looks back over earlier tokens to decide what comes next.

The idea is borrowed from operating systems. The vLLM paper was presented at the ACM SIGOPS 29th Symposium on Operating Systems Principles, an operating systems conference, and PagedAttention borrows from the way an operating system manages memory.

How does PagedAttention store the cache?

Earlier systems reserved one continuous chunk per request, sized for the longest reply allowed. The chunk was held for the whole request, and a request can end far below its limit. Space that nobody could use sat idle.

PagedAttention splits the cache into fixed-size blocks and adds them one at a time as the reply grows. Every block has the same size, so the engine can give any free block to any chat.

Two ways to hold a chat's memory

Old way

Reserve 2,048 slots

for each chat, before it starts

Use about 300

most of the reserved space stays empty

PagedAttention

Take 16-slot blocks

added only as the chat grows

Block table

maps each chat's slots to blocks

Memory wasted

slots no other chat can use

Room for more chats

same GPU, more users served

  1. 1The reserved chunk stays mostly empty, and no other chat can use it.
  2. 2Only the blocks in use are taken, so more chats fit on the same GPU.
Two ways to hold a chat's memory. The old way reserves room for the longest reply up front. PagedAttention takes 16-slot blocks as the chat grows, so the spare room goes to other chats.
  1. 1

    Start small

    A new chat gets one block. Nothing more is reserved for it.

  2. 2

    Grow on demand

    When the last block fills, the engine takes a new free block.

  3. 3

    Keep a map

    A block table records which blocks belong to the chat, in order, so attention can find them.

  4. 4

    Free it at once

    When the chat ends, its blocks return to the free pool for other chats.

A made-up example. The support bot has eight chats open. Each may reach 2,048 tokens, but these ones used between 96 and 530 tokens. Reserving the full 2,048 for every chat takes 16,384 slots, and only 2,212 are used, about 14 percent.

Python
# Made-up support bot: eight chats share one GPU's cache space.
# Each chat may reach 2,048 tokens, but these ones stopped much earlier.
import math

MAX_LEN = 2048   # the longest reply a chat may reach
BLOCK = 16       # tokens per block, as in the paper's tests
used = [312, 287, 143, 401, 96, 255, 530, 188]  # tokens each chat really used

reserved = len(used) * MAX_LEN                   # old way: whole chunk up front
blocks = [math.ceil(n / BLOCK) for n in used]    # paged way: blocks as needed
paged = sum(blocks) * BLOCK

print(f"reserved up front: {reserved} slots, used {sum(used)} ({sum(used) / reserved:.0%})")
print(f"paged blocks: {sum(blocks)} blocks = {paged} slots, used {sum(used) / paged:.0%}")
print(f"slots left free for more chats: {reserved - paged}")

Output

reserved up front: 16384 slots, used 2212 (14%)
paged blocks: 141 blocks = 2256 slots, used 98%
slots left free for more chats: 14128

With 16-token blocks, the same eight chats need 141 blocks, which is 2,256 slots, about 98 percent used. The last block of each chat is partly empty, so some space is still lost. Even so, usage is close to full, and the rest of the GPU's cache is free for more chats.

What one step of serving does

Scheduler

picks the chats for this step

Block table

lists each chat's blocks

GPU attention

reads blocks where they sit

Save the new token

into the last block, or a new one

Next token

sent back to the chat

  1. 1The scheduler hands over each chat's block table for this step.
  2. 2The GPU looks up the blocks and reads the cache where it sits.
  3. 3The model picks the next token, and its keys and values are saved.
  4. 4The new token goes back to the chat.
What happens on each serving step. The scheduler hands over block tables, the GPU reads the blocks where they sit, and the new token is saved and sent back. The same flow repeats for every step.
  • “an attention algorithm inspired by the classical virtual memory and paging techniques in operating systems”

    The vLLM paper

  • “we organize the KV cache as fixed-size KV blocks, like pages in virtual memory.”

    The paper, on its design

  • “This is a historical document based on the original paper for vLLM.”

    The vLLM PagedAttention docs

Why does sharing the cache matter?

Many chats start with the same long instructions, such as a bank's system prompt. The paper says vLLM allows flexible sharing of the KV cache within and across requests, so one set of blocks can serve several chats instead of being stored many times.

  • Shared start

    Blocks are reused

    Chats with the same opening reuse the blocks already stored for it. Fewer tokens are computed again.

  • Early change

    Later blocks are lost

    A change near the start spoils every block after it, even when the later text is identical.

vLLM's prefix caching (keeping the blocks for a shared opening, so later chats reuse them) builds on the same blocks. It reuses only the longest run of full blocks at the start of a prompt that is already stored. So a prompt that changes its first few words gets little reuse, and one that changes only at the end keeps most of its blocks.

What are the trade-offs and limits?

There are three. First, block size. vLLM sets its default block size to 16. The paper found that size large enough to use the GPU well and small enough to avoid much wasted space in most workloads. Bigger blocks waste more space in each chat's last block and make sharing less likely.

Second, lookup cost. The paper's GPU code (its kernels, the small programs that run on the chip) has extra overheads for reading the block table and for handling sequences of different lengths. The paper reports 20 to 26 percent higher attention latency than FasterTransformer, a highly optimized system. The authors believe the overhead is small, but the number is real and worth measuring.

Third, the code has moved on. The vLLM docs label their paged attention page as historical, and say paged attention now runs inside the attention backends. The idea still holds, but the paper's details have changed in the current code.

Tip

Asked about the cost? Name the block table lookup, say you would tune block size on your own traffic, and say that the paper's numbers come from its own tests.

How would you cut GPU memory waste for a busy support bot?

I would start by measuring the real reply lengths. Chats often have a long tail, where a few very long replies take most of the memory. Check that in your own logs. The steps below target that tail.

  1. 1

    Measure first

    Log the real reply lengths and the cache use at peak hour. The long tail decides the waste.

  2. 2

    Use a paging engine

    Run the model on vLLM or a similar engine that splits the cache into blocks, rather than code that reserves a full chunk per request.

  3. 3

    Cap the reply length

    Set a sensible maximum output, so no single chat can claim a huge share of the GPU.

  4. 4

    Keep the opening the same

    Keep the long instructions identical across chats, so prefix caching can reuse their blocks.

What does the interviewer want to hear?

A strong answer covers

  • PagedAttention stores the KV cache in small fixed-size blocks, like operating system pages.
  • Why reserving for the longest reply wastes GPU memory.
  • The block table, and the lookup it costs on each step.
  • vLLM is the serving engine that uses it.
  • Trade-offs: block size, sharing, and the lookup cost.
  • Tuning on your own traffic, not on a paper's numbers.

Common traps

  • Trap"PagedAttention makes the model smarter."

    BetterIt changes where memory is kept, so the server fits more chats. The model itself stays the same.

  • Trap"Use a bigger GPU and skip paging."

    BetterA bigger GPU adds room but keeps the same waste pattern. Paging removes most of that waste, so the same card serves more chats.

  • Trap"Make blocks as big as possible to be efficient."

    BetterBigger blocks waste more in each last block and share less. The paper sets 16 as vLLM's default block size.

Can you spot the waste?

Spot the waste

Which line sets aside room for the longest possible reply, before the chat starts?

Quick check

A support bot wastes GPU memory on reserved slots. Which change fixes most of that?

Can you answer these from memory?

Flash cards · tap a card to flip it

1 / 6

What will they ask next?

  1. Q314Static vs continuous batching?12 min
  2. Q316TTFT vs tokens/sec vs total latency?12 min
  3. Q320Serving engines (vLLM, SGLang, TensorRT-LLM, llama.cpp)?11 min
  4. Q321What is speculative decoding?11 min
  5. Q326Prompt cache vs semantic cache vs KV cache?13 min
  6. Q327GPU basics: why does memory bandwidth limit decoding?11 min

Last updated on 27 November 2026

Serving an AI model to many users at once?

Venkat designs and builds AI products and agents (the UI and the system behind it), so book a short call and say what you need.