LLM Inference Cache Residency in GPU Memory: A Practical Guide
This article explains how keeping inference data resident in GPU memory can significantly increase LLM throughput. It breaks down the performance gains, shows how to calculate a VRAM budget, and compares two caching strategies—lazy eviction and active prefetching—along with guidance on combining them, common pitfalls, and how to benchmark results.
1. Background: Why Keeping Data Off the Host Boosts Throughput
In high-concurrency LLM inference, a commonly observed pattern is that with the same model and the same hardware, simply changing the caching and data movement strategy can produce several-fold differences in tokens generated per second. A technical community once discussed an inference serving design that treated “data never lands on the host” as its core principle. Combined with high-throughput scheduling and compute implementations, it achieved generation speeds of hundreds of tokens per second on a single GPU.
Here, “never lands” means that the weight shards, KV cache, and intermediate activations reused throughout inference are not frequently shuttled back and forth between host memory and device VRAM. Instead, they stay resident in device memory (HBM) as much as possible, ready for direct access by the compute units. The benefits are not mysterious and can be broken down into three layers:
- Bandwidth hierarchy differences. Device memory bandwidth is typically an order of magnitude higher than host memory bandwidth, and transfers across PCIe or an equivalent bus add protocol and scheduling overhead. Every avoided round trip removes one traversal of a high-latency, low-bandwidth bottleneck.
- Latency determinism. Transfers are asynchronous and subject to bus contention, so tail latency fluctuates widely. Resident access takes a shorter path, producing a more tightly clustered latency distribution that is friendlier to interactive workloads.
- Scheduling freedom. When data is local, batching policies, paging policies, preemption, and recovery are all easier to control at a fine grain, without reserving a conservative time budget for “how long will it take to bring the data back.”
This is not a cost-free optimization. VRAM is a scarce resource, residency means occupancy, and occupancy limits the concurrency and context length the system can accommodate. So the real engineering question is: given a fixed VRAM budget, how do you maximize the marginal benefit of residency?
2. Prerequisites: Do the VRAM Math Before Choosing a Strategy
Any caching strategy must be built on a clear VRAM budget. A rough calculation looks like this:
Total VRAM ≈ weights + KV cache + activations and temporary buffers + runtime/communication buffers + headroomKV cache ≈ 2 × num_layers × num_kv_heads × head_dim × sequence_length × concurrency × bytes_per_precision
The factor of 2 accounts for the two tensors, Key and Value. This formula highlights a key fact: the KV cache grows linearly with “sequence length × concurrency,” making it the item most likely to spiral out of control. Without upper-bound management, long-context requests will quickly consume all the headroom and push the system into frequent swapping.
Practical recommendations:
- First fix the incompressible items (weights, runtime buffers), then treat the remaining VRAM as a “schedulable cache pool.”
- Set watermarks for the cache pool (a high watermark triggers reclamation, a low watermark restores admission) to avoid repeated thrashing at the critical point.
- Agree on a uniform precision convention (for example, storing the cache in half precision and converting as required by the kernels), and evaluate the VRAM savings and accuracy loss together.
3. Strategy 1: If It Never Fills Up, Nothing Gets Evicted
The first approach can be summarized as “no eviction as long as there is spare capacity”: as long as the cache pool is not full, resident data stays in VRAM and is not actively reclaimed.
Its essence is lazy eviction: no prediction, no prefetching, only making room according to some eviction rule when data genuinely no longer fits. The advantages are a simple implementation, explainable behavior, and naturally high hit rates under steady load. The drawback is poor adaptability to bursts—once concurrency or context length spikes, the system can drop rapidly from “all hits” to “frequent swapping in and out,” accompanied by a noticeable rise in tail latency.
Applicability and engineering points:
- Request length distribution is relatively concentrated, and peak concurrency is predictable;
- Leave ample VRAM headroom (a common practice is to reserve 15%–25% as a buffer, with the exact ratio tuned by measurement);
- Keep the eviction rule stable to avoid thrashing where data is “evicted and immediately needed again”; a minimum residency time or access-frequency counter can help;
- Pair it with admission control—prefer queuing over pushing the cache pool to the critical point.
Illustrative admission and watermark logic:
def admit(req, pool):need = estimate_kv_bytes(req) # estimate from length and concurrencyif pool.used + need > pool.high_watermark:pool.evict_until(pool.used + need <= pool.low_watermark)if pool.used + need > pool.capacity:return QUEUE(req) # queue instead of forcing an evictionpool.reserve(req, need)return RUN(req)
4. Strategy 2: Prefetch So Hits Keep Happening
The second approach is active prefetching: based on the request queue and historical access patterns, cache blocks that will soon be needed are moved into VRAM ahead of time, so the data is already cached exactly when the workload requests it, appearing as continuous hits in observation.
The key to this route is not the “moving” but “predicting accurately.” Inaccurate predictions cause two kinds of loss: first, prefetched data consumes bandwidth and VRAM, squeezing out normal compute resources; second, wrongly prefetched blocks become resident garbage that increases eviction pressure. Prefetching must therefore share the same “future view” as the scheduler: the pending queue, each request’s context length, continuation characteristics of streaming output, and reuse relationships among shared prefixes.
Engineering points:
- Build a prefetch plan per request, and hand “when to move, how much, and where” to a controlled transfer queue that limits the number of concurrent transfers so the bus is not saturated by prefetching;
- Prioritize high-reuse content such as system prompts, template prefixes, and long document fragments shared across requests, since these have the highest reuse rate and the most certain prefetch benefit;
- Provide a cancellation mechanism for prefetching: when a request is canceled, times out, or has its priority lowered, discard transfer tasks that have not yet started;
- Measure effectiveness with a hit window—the fraction of blocks still cached at the moment of access—rather than a vague cache occupancy rate.
Pseudocode illustration:
def schedule_prefetch(queue, pool, budget_bytes):plan = []for req in queue.peek(k=8): # look at only a few requests at the headblocks = predict_blocks(req) # shared prefixes firstfor b in blocks:if b in pool: continueif budget_bytes < b.size: breakplan.append(Prefetch(b, req.id))budget_bytes -= b.sizereturn plan[:MAX_INFLIGHT] # cap in-flight transfers
5. A Unified View and Selection Guidance
Viewing both strategies in the same frame makes things clearer: Strategy 1 is passive and capacity-driven, while Strategy 2 is active and prediction-driven. They are not mutually exclusive, and mature systems often combine them in layers:
- Hot data stays resident: weights and high-frequency shared prefixes remain resident long-term and do not participate in eviction;
- Warm data is managed by watermarks: session-level KV cache is kept above the low watermark, and the high watermark triggers eviction by access frequency;
- Cold data is moved on demand: long-tail documents and low-frequency contexts are not prefetched but loaded on a miss, accepting one observable latency cost.
Three criteria can guide selection: whether the load is predictable, whether VRAM headroom is ample, and how much tail latency the business tolerates. Under steady load with ample headroom, Strategy 1 offers the best cost-performance ratio; when the load has clear queue characteristics and there are many reusable prefixes, Strategy 2 delivers more significant gains. When stacking the two, always manage them with a unified budget ledger to avoid over-allocation caused by each acting on its own.
6. Common Pitfalls and Verification Methods
- Pitfall 1: Treating “high cache occupancy” as a high hit rate. High occupancy only means nothing was reclaimed; it does not mean the data is still there at access time. Use the hit window, bytes swapped in, and queueing time as core metrics.
- Pitfall 2: Assuming more prefetching is always better. Prefetching is a resource-competition behavior and must have an upper bound and be included in unified scheduling.
- Pitfall 3: Ignoring precision and layout. The storage layout, precision, and block granularity of the cache all affect effective capacity and kernel efficiency, and must be co-designed with the compute implementation.
- Verification method: Replay a fixed input set under load testing across three configurations—“no cache,” “passive residency,” and “active prefetching”—measuring throughput, time to first token, tail latency, and bytes swapped in to form a comparable baseline; then increase the load step by step to find the inflection point and determine the watermarks and prefetch budget.
7. Conclusion
“Keeping data off the host” is not some irreproducible proprietary feature, but a set of plain engineering principles: reduce cross-level data movement, keep hot data close to compute, and constrain scarce resources with explicit watermarks and budgets. Passive residency wins on simplicity and reliability, while active prefetching wins on capturing reusable content; only by combining them can you approach the throughput ceiling under limited VRAM. When deploying in the public cloud, you can rely on a container platform to host the inference service, object storage to hold models and long documents, and logging and monitoring/alerting systems to observe hit and queueing metrics, forming an optimization loop of “measurable—tunable—reproducible.”
