KV Cache Offloading to RAM and NVMe

Vladimir Lomtev•
KV Cache Offloading to RAM and NVMe

Offloading the KV cache moves the states of already processed tokens from video memory to system RAM, local NVMe, or shared storage so that when the same context is repeated, prefill does not have to be recomputed from scratch. It helps in multi-turn conversations, agents, and RAG with repeating documents. For a stream of unique short requests, the benefit is close to zero, while memory and the PCIe bus are consumed.

The material was prepared by AI Studio by Vladimir Lomtev on November 16, 2026, for engineers who run vLLM, SGLang, or NVIDIA Dynamo on their own servers. We checked the flags against the documentation for vLLM, LMCache, SGLang, and Dynamo, as well as the release notes for llama.cpp v1.0.0. We did not perform our own GPU measurements. The acceleration figures below belong to the authors of the cited sources, and the memory calculations are illustrative examples.

Contents

Why the KV cache does not fit in video memory

During generation, the model stores attention keys and values for each token — this is KV cache. Its size grows with context length and the number of simultaneous conversations. For a model with GQA, the size per token is calculated as follows:

2 × number of layers × number of KV heads × head size × bytes per value

A hypothetical example for a configuration typical of 8B models: 32 layers, 8 KV heads, head size 128, storage in FP16 (2 bytes). We get 2 × 32 × 8 × 128 × 2 = 131,072 bytes, or 128 KiB per token. A session with a 32,768-token context will take 128 KiB × 32,768 = 4 GiB. One hundred such sessions would require 400 GiB — more than any single GPU has. How weights and overhead memory are added to this is explained in the article “How much VRAM does an LLM need”.

When video memory runs out, the engine evicts older blocks. If a user returns to a conversation a minute later, their history will go through prefill again. With long contexts, that means seconds of latency and a busy GPU. Offloading keeps evicted blocks lower in the memory hierarchy and brings them back on reuse.

Memory hierarchy: from GPU to shared storage

Level Where the cache lives Who can use it Typical role
L1 GPU video memory Only this engine instance Active requests and hot prefixes
L2 Server RAM Only this instance Recently evicted conversations and shared system prompts
L3 local NVMe or the node file system Processes on the node, if storage is shared Long history, rare repeats
L3 shared Mooncake, 3FS, Redis, S3, and others Multiple servers Reuse across replicas

The lower the level, the larger the capacity and the more expensive access becomes. Loading a block from RAM goes through PCIe, and from NVMe it also goes through the file system. Offloading is worthwhile as long as loading ready-made cache is faster than repeating prefill for the same text. For long repeating contexts, that is usually true; for short ones, not always.

When offloading helps, and when it does not

Offloading makes sense if:

  • users return to long conversations after a pause long enough for the cache to be evicted from the GPU;
  • agents call the model repeatedly with a growing history of steps and tools;
  • many requests start with the same long system prompt or the same RAG documents;
  • the engine often evicts requests under load, and recomputation consumes a noticeable share of the GPU.

Offloading will hardly help if:

  • requests are unique and short, with no reuse;
  • the server has too little RAM, and the cache will be evicted from L2 before it is needed;
  • the bottleneck is generating long responses (decode), not prefill;
  • the application changes the beginning of the prompt in every request, for example by inserting the current time into the first line, so the prefixes do not match.

Before turning on offloading, check through metrics that the problem is really repeated prefill. How to read the queue and evictions is explained in the article about the LLM request queue.

Built-in offloading in vLLM

vLLM has its own mechanism for offloading to system RAM. According to the argument reference, --kv-offloading-size sets the size of the offload buffer in GiB. By default, the value is not set and offloading is disabled. --kv-offloading-backend selects the implementation: native (default) or lmcache.

vllm serve Qwen/Qwen3-8B \
  --host 127.0.0.1 --port 8000 \
  --api-key "$VLLM_API_KEY" \
  --kv-offloading-backend native \
  --kv-offloading-size 64

Here, 64 GiB of RAM is allocated for the cache of one replica. This is a hypothetical value: leave headroom for the system, model loading processes, and other services on the server.

The vLLM team described the mechanism in a blog post from January 8, 2026. According to their data, the feature appeared in version 0.11.0 and became noticeably faster in 0.12.0. On Llama-3.1-8B-Instruct and H100, loading the cache from RAM reduced time to first token for a single request by 2–22x depending on prompt length. On cache misses, the impact is minimal because copying from GPU to RAM happens asynchronously. This is the authors’ result on their own hardware; on a different model and server, the effect will be different. The same source also lists limitations: the CPU backend works only with CUDA-compatible devices, hybrid models are not yet optimized, and the result depends on the model block size.

LMCache: A Separate Cache Management Layer

LMCache describes itself as a KV cache management layer for scalable inference. It runs separately from the engine and supports RAM, local disk, and remote storage: Redis/Valkey, Mooncake, InfiniStore, S3-compatible storage, NIXL, and GDS.

In the LMCache quick start guide it shows a mode with a separate server process. First, you start the cache server:

lmcache server \
  --host localhost --port 5555 \
  --l1-size-gb 20 --eviction-policy LRU --chunk-size 16

Then connect vLLM to it through --kv-transfer-config:

vllm serve Qwen/Qwen3-8B --port 8000 \
  --kv-transfer-config '{"kv_connector":"LMCacheMPConnector","kv_role":"kv_both","kv_connector_extra_config":{"lmcache.mp.host":"localhost","lmcache.mp.port":5555}}'

The documentation notes that the block size of 16 is used for demonstration, while the default value is 256. LMCache is the right choice when the cache needs to be shared by multiple engine instances or when a networked layer is required. For a single replica with offload only to RAM, the built-in vLLM mechanism is simpler.

SGLang HiCache: Three Levels in One Engine

In SGLang, the hierarchical cache is called HiCache. According to the HiCache configuration guide it is enabled with the flag --enable-hierarchical-cache. The in-memory pool size is set as a multiple of the GPU pool through --hicache-ratio or in gigabytes through --hicache-size, which overrides the ratio. The third level is connected through --hicache-storage-backend: examples include file, fast_file, hf3fs, mooncake, nixl, aibrix and dynamic.

python3 -m sglang.launch_server \
  --model-path Qwen/Qwen3-8B --host 127.0.0.1 --port 30000 \
  --enable-hierarchical-cache \
  --hicache-ratio 2 \
  --hicache-write-policy write_through \
  --hicache-storage-backend fast_file

Three rules are important to remember from the documentation:

  • L1 and L2 belong to a single instance; only L3 can be shared; increasing --hicache-ratio expands the instance’s private cache, not the shared one;
  • hits from storage are first copied into the RAM pool, so it must be larger than the GPU pool, otherwise hits are dropped and the prompt is recomputed;
  • by default, the file backend writes to the local directory /tmp/hicache and serves as the minimal reference implementation; for local NVMe, fast_file is recommended; for shared storage, use hf3fs or mooncake with direct I/O.

Dynamo KVBM: Offload in the NVIDIA Dynamo Cluster

In NVIDIA Dynamo, KVBM handles offload. In the KVBM guide it is described as a component for allocating, managing, and remotely exchanging KV blocks, working as a memory and write-through cache layer for vLLM and TensorRT-LLM. It supports offload to RAM only, to RAM and disk, and an experimental disk-only mode.

Tier sizes are set with the environment variables DYN_KVBM_CPU_CACHE_GB and DYN_KVBM_DISK_CACHE_GB, and vLLM is connected through --kv-transfer-config with DynamoConnector and the module kvbm.vllm_integration.connector. The documentation includes a direct warning: if the RAM cache is smaller than the device cache, KVBM provides no benefit. Therefore, the RAM tier must be at least as large as the GPU KV pool, and the disk tier must be at least as large as the RAM tier.

The MoE Expert Cache in llama.cpp 1.0 Is Not a KV Cache

In the llama.cpp v1.0.0 release from November 13, 2026, an in-memory MoE expert cache with a configurable CPU share was added. In llama_context_params the following were added: moe_cache_size and moe_cache_cpu_share, experts that miss the cache are executed on the CPU, and LRFU and ClassLRU policies are used for replacement.

The name is similar, but the mechanism is different. This cache keeps frequently used experts, meaning the model weights, in fast memory rather than token states. It is needed when a large MoE model does not fit entirely in video memory. In the same release, FP8 KV cache support also appeared ( weights of the model, not token states. It is needed when a large MoE model does not fit entirely in VRAM. That same release also introduced an FP8 KV cache (-ctk/-ctv f8_e4m3) — this is a different way to reduce the KV cache specifically, and we cover it separately.

How to choose a tool

Situation What to try first
A single vLLM replica, long conversations, lots of free RAM Built-in vLLM offloading (native)
Multiple vLLM replicas need to share the cache LMCache with a shared backend
A service on SGLang HiCache: first L2, then fast_file on NVMe
A cluster on NVIDIA Dynamo KVBM with the rule RAM ≥ GPU, disk ≥ RAM
A large MoE model does not fit in VRAM on llama.cpp MoE expert cache, not KV offloading

Do not enable multiple offloading mechanisms at the same time on one engine unless the documentation explicitly describes such a combination. Each one manages blocks differently, so the result will be hard to explain.

How to test the effect on your own workload

  1. Record a baseline. Without offloading, measure p50 and p95 time to first token, the share of occupied KV cache, and the number of evictions on a real mix of requests.
  2. Prepare a repeat scenario. For a multi-turn chat, send the first turn, wait until it is evicted from the GPU, then send the second turn with the same history. For RAG, use a repeating set of documents.
  3. Enable one mechanism. Compare time to first token on repeat requests and on new requests separately.
  4. Monitor resources. RAM usage, NVMe I/O, and PCIe load. If RAM runs out at peak, the system will start swapping and the benefit will disappear.
  5. Check quality. Responses with and without cache for the same request at zero temperature should match or differ only within the engine's normal noise margin.
  6. Lock in the decision. Keep offloading if repeat requests got faster and new requests did not get slower.

Security and isolation

The KV cache contains a derived representation of user text. If you offload it to disk or shared storage, the same rules apply as for the data itself:

  • the shared layer across tenants must respect isolation: one user's request should not receive another user's blocks;
  • an NVMe directory with cache should be encrypted and wiped when the server is decommissioned;
  • access to network cache storage should be limited to inference servers.

Working with cache in distributed setups requires engine updates. In the LMSYS analysis from October 26, 2026 the corrected SGLang bugs are described, where with separate prefill and decode, another user's KV cache could end up in someone else's response; another case was tied to HiCache offloading on the decode side. Keep the engine on the latest version and read the release notes.

Frequently asked questions

Will offloading speed up long response generation? No. It saves repeated prefill. The speed of generating each next token does not depend on it.

How much RAM should be allocated? No less than the GPU KV pool; otherwise, according to Dynamo and SGLang rules, there will be no benefit. After that, size it based on how many conversations you need to keep alive and for how long.

Can you offload the KV cache to a regular SSD? Yes, but the benefit depends on disk speed. For frequent reuse, local NVMe is better, while a SATA drive may be slower than repeated prefill.

Is prefix caching required for offloading? Offloading reuses blocks for matching prefixes, so keep prefix caching enabled unless your engine version's documentation says otherwise.

How Vladimir Lomtev's AI studio helps with KV cache offloading

Vladimir Lomtev's AI studio deploys LLMs on the company's servers and supports them. For cache offloading, this means:

  • checking with metrics that the latency is caused by repeated prefill, not queueing or generation;
  • choosing the offloading mechanism and level sizes for the server's engine, memory, and disks;
  • running comparative tests on real conversations and documents before and after enabling it;
  • setting up memory monitoring and cache retention rules along with data requirements.

The first step is to choose one scenario with a long, repeating context, record the current time to first token, and define the target you need to reach. Discuss the task.

Bottom line: offloading saves repeated prefill

KV cache offloading to RAM and NVMe is useful when the same long context returns after being evicted from video memory. Start with your engine's built-in offloading to RAM, measure the effect on repeat requests, and only then add disk or shared storage for multiple replicas.

Request an audit

Share your contact details and we will follow up.

← All articles

Comments (0)

Loading comments…

Leave a comment
No registration required

Book a strategy call
for agentic operations

Tell us which workflow you want to improve. We will map feasibility, risks, and the fastest MVP path.

By submitting, you agree to our privacy policy

Contacts

Global Operations

Serving U.S. clients remotely
with private cloud and on-prem options

Strategy calls by request

We respond after reviewing your workflow context.

info@agentsunrise.pro

For partnership inquiries

Have a proposal?

Write to us in messengers

© 2026 AgentSunrise