How LLM serving worksLesson 7 of 9
Offloading Overflowing KV Cache
Accelerator memory is fast but small and expensive. When the KV cache overflows, the engine discards old entries, and if that conversation comes back it recomputes everything from scratch. KV cache offloading moves the cache down to larger, slower storage tiers instead, and loads it back when it is needed.
KV cache on accel.95%
This chat’s cacheaccel. memory
First token on return—
RequestResponse / reportAppears in a later step
What you will learn
- When accelerator memory overflows, cache is dropped and recomputed
- Storage tiers run from fast and small to slow and large
- It pays off only when loading back beats recomputing
- Storage upkeep and failures become new risks
What to check on Kubernetes
- Offloading is an engine feature; in vLLM, for example, you attach a KV connector with
--kv-transfer-config: the built-inOffloadingConnectorfor CPU memory, or an external one such as LMCache. Before turning it on, check KV cache usage and the preemption count to confirm the cache really is overflowing. - Cache offloaded to CPU memory counts against the Pod’s memory. If the Pod’s memory requests and limits do not include the offload size, the container gets OOMKilled.
- If local NVMe is mounted as an emptyDir, the cache disappears with the Pod. That is fine for a cache, but exceeding the ephemeral-storage limit gets the Pod evicted by the kubelet. Put a cap and a cleanup rule on disk usage.
- With shared storage, storage latency shows up directly in time to first token. Put storage response time and TTFT on the same dashboard.
- The benefit depends on how often the same conversation or prefix comes back. Compare prefix cache hit rate and TTFT before and after enabling it.
Try it yourself
curl -s http://<engine>:8000/metrics | grep -E 'vllm:(kv|gpu)_cache_usage_perc|vllm:num_preemptions' # e.g. vLLM: really overflowing? (step 2)
curl -s http://<engine>:8000/metrics | grep vllm:prefix_cache # Hit rate before vs after (step 5)
kubectl get pod <pod> -o jsonpath='{.spec.containers[*].resources}' # Memory limit includes offload size?
kubectl get pod <pod> -o jsonpath='{.status.containerStatuses[*].lastState.terminated.reason}' # OOMKilled?
kubectl get events -n <namespace> --field-selector reason=Evicted # ephemeral-storage evictions
Check yourself
Further reading: GPUDirect Storage · LMCache · Resource Management for Pods and Containers