Analytics Legends logoAI & Analytics Legends Sign inSign up
Concept card

PagedAttention — Memory Management for Long-Context LLMs

PagedAttention — Memory Management for Long-Context LLMs — AI & Analytics Legends section illustration for the SAP AI & Analytics knowledge base (concepts, studies, Academy)

As of 2026-11-22

What is PagedAttention?

PagedAttention stores the KV cache in small fixed-size blocks allocated on demand instead of one contiguous reservation per request sized to its maximum length. In the vLLM paper (SOSP 2023) the share of KV-cache memory holding real token states rose from 20.4–38.2% to about 96%, and throughput rose 2–4x at the same latency — but concurrency on a given GPU is still set by the KV-cache arithmetic, not by a rule of thumb.

PagedAttention is the memory-management technique behind vLLM, introduced by Kwon et al. at SOSP 2023 (paper). It takes the paging idea of operating systems and applies it to the structure that dominates GPU memory during LLM inference once the weights are loaded: the KV cache, the key and value vectors every transformer layer keeps for every token already in context.

What it is and why it matters

Each token in context costs, per layer, one key vector and one value vector for every key-value head. The size per token is therefore 2 × layers × KV heads × head dimension × bytes per value. For Llama 3.3 70B (80 layers, 8 KV heads thanks to grouped-query attention, head dimension 128, BF16 = 2 bytes, per its model configuration) that is 2 × 80 × 8 × 128 × 2 = 327,680 bytes, or 320 KiB per token; a full 32,768-token context needs 32,768 × 327,680 B = 10.74 GB.

Before PagedAttention, serving systems stored each request's cache in one contiguous region pre-allocated at the request's maximum length, because deep-learning frameworks expect contiguous tensors. A request allowed 2,048 tokens that stopped after 200 still held all 2,048 slots until it finished, and differently sized reservations left gaps between them. The vLLM authors measured that only 20.4–38.2% of KV-cache memory held actual token states in the systems they profiled, against about 96% for vLLM (Kwon et al. 2023).

Why it matters

  • Engines that reserved a contiguous KV-cache region at each request's maximum length used only 20.4–38.2% of that memory for real token states in the vLLM authors' measurements; vLLM reached about 96%.
  • Fixed-size blocks (16 tokens by default in vLLM) are mapped through a per-request block table, allocated as the sequence grows and freed when it ends — operating-system paging applied to the KV cache.
  • Memory, not compute, usually caps how many conversations a GPU serves: for Llama 3.3 70B one token of context costs 320 KiB of KV cache, so a full 32k-token session needs 10.74 GB.

Key points

  • Mechanism: the KV cache is split into fixed-size blocks (16 tokens by default in vLLM) mapped through a per-request block table; blocks are allocated on demand and freed when the request ends, so waste is limited to each request's last, partly filled block.
  • Measured effect (Kwon et al., SOSP 2023): existing systems used 20.4–38.2% of KV-cache memory for real token states, vLLM about 96%; throughput rose 2–4x over FasterTransformer and Orca at the same latency.
  • Cost: the attention kernel gathers keys and values from non-contiguous blocks and ran 20–26% slower than FasterTransformer's kernel — small end-to-end, because only the attention operator is affected.
  • KV bytes per token = 2 × layers × KV heads × head dimension × bytes per value; with grouped-query attention use the KV heads (8 × 128 = 1,024 for Llama 3.3 70B), not the hidden size (8,192) — a factor of 8.
  • Worked sizing, Llama 3.3 70B BF16 (141.1 GB of weights): 2 × 80 GB at 0.90 utilisation leaves 2.9 GB (≈ 8,850 tokens, under one 32k session); 4 × 80 GB leaves 146.9 GB (≈ 448,000 tokens): 13 sessions reserved at 32k, about 109 paged at a 4k average.
  • Prefix sharing: identical prefixes reuse the same blocks (vLLM automatic prefix caching on full blocks, LRU eviction; SGLang RadixAttention on a radix tree); 50 requests sharing a 2,048-token prefix save 49 × 2,048 × 327,680 B ≈ 32.9 GB on Llama 3.3 70B.
  • Prefix caching cuts prefill work and time-to-first-token for the shared part only; it does not speed up decoding of new tokens.
  • When KV memory runs out, vLLM's V1 engine preempts requests and recomputes them (recompute is the default, not swap); watch vllm:num_preemptions and vllm:kv_cache_usage_perc.
  • Implemented in vLLM (origin), SGLang (RadixAttention), NVIDIA TensorRT-LLM (paged KV cache with block reuse) and LMDeploy (InternLM; blocked KV cache in the TurboMind engine).
  • SAP: SAP does not document the serving engine of generative AI hub models; the KV arithmetic is the consultant's lever when an open model is self-hosted, e.g. vLLM on SAP AI Core as bring-your-own-model (SAP sample repository, option 4).

Terms used on this page

PagedAttention
Attention algorithm and KV-cache memory manager that stores keys and values in fixed-size blocks mapped by a per-request block table, as OS virtual memory maps pages; introduced with vLLM (Kwon et al., SOSP 2023), where it delivered 2–4x throughput over FasterTransformer and Orca at the same latency.
KV-cache
The key and value vectors of every token already in context, kept in GPU memory so attention does not recompute them; its size per token is 2 × layers × KV heads × head dimension × bytes — 327,680 bytes for Llama 3.3 70B in BF16.
Block table
Per-request structure that maps logical token positions to the physical blocks holding their keys and values; the equivalent of an OS page table, it decouples sequence length from physical layout.
Prefix caching
Reuse of the KV blocks of an identical prompt prefix (system prompt, shared document, earlier turns) by later requests; it removes prefill work and lowers time-to-first-token for the shared part, but not decoding time. vLLM caches full blocks only.
RadixAttention
SGLang's KV-cache reuse scheme (Zheng et al., 2023): cached prompts and generations are kept in a radix tree keyed by token sequences, so any shared prefix — few-shot examples, multi-turn chat, tree-of-thought branches — is reused; leaves are evicted LRU.
Page eviction
What happens when KV memory runs out: vLLM's V1 engine preempts requests and recomputes their cache later (its default), and evicts free cached prefix blocks least-recently-used first; CPU offloading exists only when explicitly configured.
TTFT (Time to First Token)
Latency from request submission to the first generated token; dominated by prefill, so it is the metric prefix caching improves (vLLM exposes it as vllm:time_to_first_token_seconds).
Continuous batching
Scheduling that admits new requests into the running batch between decoding steps instead of waiting for the whole batch to finish; paged allocation makes it effective, because admission depends on free blocks, not on a contiguous region of maximum length.

Sources

  1. Kwon et al. — Efficient Memory Management for Large Language Model Serving with PagedAttention (SOSP 2023)
  2. vLLM docs — Automatic Prefix Caching (skips prefill of the shared part; no decoding gain)
  3. vLLM docs — Prefix caching design (full blocks, hash chain with extra keys and cache_salt, LRU eviction)
  4. Zheng et al. — SGLang: Efficient Execution of Structured Language Model Programs (RadixAttention)
  5. NVIDIA TensorRT-LLM — KV cache reuse (paged KV blocks, system-prompt and multi-turn reuse)
  6. vLLM docs — Optimization and tuning (V1 preemption by recomputation; max_num_seqs, tensor parallelism)
  7. vLLM docs — Production metrics (vllm:num_preemptions, vllm:kv_cache_usage_perc, vllm:time_to_first_token_seconds)
  8. vLLM docs — Quantized KV cache (kv_cache_dtype fp8)
  9. vLLM — v0.31.0 release notes, 5 Oct 2026 (prefix-cache extra keys tagged by source, --max-num-active-seqs, vllm preload)
  10. LMSYS Org — Fast and Expressive LLM Inference with RadixAttention and SGLang (radix tree, LRU eviction)
  11. InternLM — LMDeploy repository (TurboMind engine, blocked KV cache, persistent batch)
  12. Hugging Face — Llama 3.3 70B Instruct configuration (80 layers, 8 KV heads, head dimension 128, 131,072 positions)
  13. SAP-samples — Bring open-source LLMs into SAP AI Core (serving options incl. vLLM)
  14. Microsoft Learn — Prompt caching with Azure OpenAI in Microsoft Foundry Models
  15. Databricks docs — Provisioned throughput Foundation Model APIs
  16. Snowflake docs — Cortex AI Functions

Full card with the Consultant plan — €19.90/month. What the full card adds: the full decision framework · the SAP vs Snowflake / Databricks / Fabric comparison · the common pitfalls and their fix · the cheat sheet · the architecture schemas · the code blocks · the facts worth quoting.

Open in the app →

Open missions

SAP analytics jobs and contracts · freelance SAP contracts.