When the prefix cache runs out of room
Many requests to a server begin the same way: the same system prompt, the same document, the earlier turns of a conversation. A server that keeps the keys and values of those prefixes can skip their prefill and compute only the new tokens, as the KV cache tab shows within one request. But GPU memory is small, and as conversations grow the prefixes are evicted and must be computed again. HiCache, SGLang's hierarchical cache, keeps evicted pages in larger, slower tiers, host memory and storage, and brings them back when a request needs them.
The page serves 11 real requests that share prefixes (a hotel front desk with a long system prompt, a Python tutor, a multi-turn chat about Kyoto) with Qwen2.5-0.5B-Instruct on this Mac. The Apple GPU is the GPU tier with room for 14 pages, CPU memory the host tier with 28, and the SSD the storage tier, one file per page. The budgets are kept small so that pages move between tiers within a few requests, and each write policy is a separate recorded run of the same requests.
Pages and the radix tree
The cache is kept in pages of 16 tokens. One token's keys and values in all 24 layers, with 2 key-value heads of 64 dimensions in float32, take
so a page is 393,216 bytes, 384 KiB. A radix tree indexes the pages by the tokens they hold: each node is a run of whole pages that the requests below it share, and records which tiers hold a copy. A new request walks down the tree to its longest cached prefix, in whole pages, prefills only the rest, and inserts its prompt and answer as new nodes. The Radix tree panel draws the tree after each request, with the prefix it matched in the colour of the tier that served it.
Three tiers
Each tier keeps its pages in its own layout: the GPU pool layer by layer, as the attention kernels read them, and the host pool page by page, so that a page moves to storage in one large transfer. When a matched prefix is only in host memory, its pages are copied to the GPU before the prefill; SGLang overlaps that copy layer by layer with the computation. When it is only in storage, its pages are first prefetched into host memory, but only if the hit is at least 32 tokens long; a shorter hit is cheaper to recompute. Evictions take the least recently used leaves first, from every tier.
The Three tiers panel shows the pools and the copies each request sets off. The Page view shows one page's keys as stored: the same bits in every tier, and every page read back from host memory or storage matched the SHA-256 it had when written.
Write policies
A policy decides when a page is copied down to the slower tier:
- write-through copies every new node to host memory at once, and on to storage;
- write-through selective copies a node once it has been hit twice, and a cold node evicted from the GPU is dropped;
- write-back copies a node only when it is evicted from the tier above.
Over the 11 requests, write-through reuses 752 of the 1,235 prompt tokens and moves 16 MiB from the GPU to host memory and 16 MiB on to storage. Write-back reuses as many tokens while writing 15 MiB to host memory and only 4.9 MiB to storage. Write-through selective writes about a seventh as much as write-through, and reuses only 592 tokens.
One request, three outcomes
The difference shows at request 10, a guest asking the hotel desk for the Wi-Fi password after the hotel system prompt's pages have left the GPU. Under write-through its 160 cached tokens come from storage: prefetching them and copying them to the GPU takes 13.2 ms, the prefill of the other 24 tokens 18.1 ms, so the first token arrives after 31 ms against 37.1 ms with no cache. Under write-back the pages are still in host memory and come back from there. Under write-through selective they were dropped when they left the GPU, so all 184 prompt tokens are computed again.
Every request's answer is the same as without a cache, and its first-token logits agree within . The savings here are small because the model is small and the prompts short: a full prefill of 184 tokens takes 37 ms on this Mac. With long contexts and large models, recomputing a prefix costs far more than copying its pages back, which is the case HiCache is built for; its announcement reports up to 6× throughput and up to 80 % lower time to first token in its benchmarks.
Where it came from
vLLM's PagedAttention (Kwon et al., 2023) stored the KV cache in fixed-size blocks, and SGLang's RadixAttention (Zheng et al., 2024) kept the blocks of finished requests in a radix tree so that later requests can reuse shared prefixes, all in GPU memory. CachedAttention (Gao et al., 2024) moved the caches of multi-turn conversations to host memory and disk and loaded them back layer by layer; Mooncake (Qin et al., 2024) built a serving system around a disaggregated KV cache pooled across machines; LMCache (Liu et al., 2025) offers a KV cache layer between engines and storage. SGLang's HiCache (2025) extends the radix tree into a page table across GPU memory, host memory and pluggable storage backends. The KV cache tab shows the single-tier cache it builds on, and the DP attention tab another way a server saves cache memory.
Papers
- SGLang HiCache: Fast Hierarchical KV Caching with Your Favorite Storage Backends The design this page reproduces: a radix tree over GPU, host and storage tiers, layer-first and page-first layouts, prefetching and the three write policies; a blog post, not a paper.
- SGLang: Efficient Execution of Structured Language Model Programs RadixAttention: reusing the KV cache of shared prefixes through a radix tree in GPU memory, the single-tier cache HiCache extends.
- Efficient Memory Management for Large Language Model Serving with PagedAttention Fixed-size KV pages and a block table, the paging this cache's tiers move.
- Cost-Efficient Large Language Model Serving for Multi-turn Conversations with CachedAttention Keeps conversations' KV caches in host memory and on disk between turns, with layer-wise loading and prefetching back to the GPU.
- Mooncake: A KVCache-centric Disaggregated Architecture for LLM Serving A serving system built around a KV cache pooled in the CPU memory and SSDs of many machines; one of HiCache's storage backends.
- LMCache: An Efficient KV Cache Layer for Enterprise-Scale LLM Inference A KV cache layer that stores and moves caches between inference engines, CPU memory and storage.
- Qwen2.5 Technical Report The Qwen2.5 family, including Qwen2.5-0.5B-Instruct, the model served here.