LLM Inference Memory Bottlenecks and KV Cache Quota Governance

    This article explains why large language model services enforce limits on long conversations and why inference platforms suffer performance degradation, tracing both back to GPU memory pressure from the KV cache. It covers the KV cache cost model, idle-session overhead, and engineering practices such as capacity planning, admission control, cache eviction and tiering, tiered quotas, graceful degradation, and observability, plus lessons from incident reviews and practical advice for developers building on LLM APIs.

    1. The Symptoms: Long Conversations Get Capped, Service Incidents Repeat

    A large language model service recently adjusted the limits on long conversations for its web and mobile clients. Three changes are visible to users: sessions inactive beyond a certain number of days are no longer retained; a single input is compressed to roughly 40,000 characters; and daily conversation volume is capped, after which requests return a “server busy, quota limit reached” message.

    Over the same period, the service’s status log recorded about ten incidents in a little over a month — roughly seven in October and three so far in November, with two occurring on one date. Most were performance degradations: slower responses, higher generation latency, and occasional request failures. A few were partial outages of the web client or the API. The most severe lasted more than four hours and constrained the web client, the mobile client, and both API surfaces at once; afterward the operator compensated API users with credits and committed to preventing a recurrence.

    One looks like a product decision, the other like an operational accident, but technically they are two ends of the same chain: GPU memory and compute on the inference side get squeezed by long sessions and burst traffic, and the pressure surfaces as quotas on one end and degradation on the other.

    2. Root Cause: Why the KV Cache Is Expensive

    Autoregressive generation predicts one token at a time. Every new token requires attention over the representations of all preceding tokens, and recomputing them each round costs work that grows linearly with context length. The standard engineering fix is to cache the Key and Value tensors of each layer’s attention and read them back on the next round. That cache is the KV cache.

    Its cost structure has three characteristics:

    • It grows roughly linearly with context length, making long conversations the main amplifier.
    • It lives in GPU memory, which is scarce and expensive per unit and cannot be expanded as freely as host memory.
    • Its lifetime is bound to the session, so the cache stays allocated as long as the session is not reclaimed.

    Schematically, the size of a single layer’s KV cache can be approximated as:

    1. # bytes_per_layer ≈ 2(K and V) * batch * seq_len * num_kv_heads * head_dim * dtype_bytes
    2. bytes_per_layer = 2 * batch * seq_len * num_kv_heads * head_dim * dtype_bytes
    3. total_bytes = bytes_per_layer * num_layers

    One immediate implication: double the context and the cache doubles; double the concurrency and it doubles again. When many long sessions coexist, GPU memory is consumed by retained sessions and new requests cannot even get into the queue.

    3. Idle Sessions: The Overlooked Cost of Retained State

    The three long-conversation rules all reduce retained state:

    1. Capping how many days an inactive session is kept effectively sets a TTL for its cache.
    2. Compressing the per-request input limit effectively caps the cache peak of a single request.
    3. Setting a daily quota effectively caps one user’s sustained occupancy.

    This reflects a commonly underestimated fact: GPU memory usage is determined not by currently active requests but by the total number of sessions still retained. A long conversation opened last week and never touched since still holds its cache. Reclaiming those resources and prioritizing active requests is the most reasonable explanation for the limit changes.

    4. Engineering Practice: Treating GPU Memory as a First-Class Resource

    4.1 Capacity Planning and Admission Control

    Estimate memory demand from context length × concurrency × layers × bytes per element, reserve a safety margin, and gate at the entry point: requests above the threshold queue or get rejected, keeping the system out of an unrecoverable thrashing zone.

    1. supportable concurrency ≈ (available GPU memory - weights - activations/temporary buffers) / average KV cache per session

    4.2 Cache Eviction and Tiering

    Set a TTL and LRU eviction for session caches. Where conditions allow, swap inactive sessions’ caches out to host memory or slower storage and swap them back when active, trading latency for capacity. Shared system prompts and template content with identical prefixes can share a cache, cutting duplicate overhead further.

    4.3 Tiered Quotas and Priorities

    Classify users and requests: prioritize interactive conversation, deprioritize batch and offline jobs; set daily quotas, concurrency caps, and context caps per tier. Quotas are not punishment; they steer scarce resources toward the requests that create the most value during peaks.

    4.4 Graceful Degradation

    Under overload, degrade in order — reduce sampling first, then context, then reject — so basic conversation stays available. Give failed requests retryable semantics and backoff guidance to avoid retry storms amplifying the failure.

    4.5 Observability

    Monitor at minimum: GPU memory usage and fragmentation, KV cache hit rate, time to first token and generation throughput, queue time, rejection rate, and the distribution of session activity. Most “the service got slow” reports show warning signs in these metrics well in advance.

    5. Lessons from the Incident Review

    Breaking the incidents down by severity yields three general lessons. First, performance degradation usually precedes hard outages, so trends in latency and error rate are more valuable than any single alert. Second, blast radius should be assessed in layers — core conversation, auxiliary tools, API — and a failure in an auxiliary capability should not drag down the main path. Third, beyond compensation and commitments, what matters is verifiable improvements such as capacity watermark alerts, rate-limit thresholds, and load-test baselines.

    6. Recommendations for Developers

    If you are building or integrating an LLM application, four things help: control context growth (rolling summaries, retrieval instead of concatenating everything); split long tasks into shorter sessions; budget and back off on the client side against quotas and rate limits; and bring cache and latency metrics into your own monitoring dashboard.

    Quotas and incidents are not an incomprehensible black box but an inevitable consequence of GPU memory and compute constraints. Understanding the KV cache cost model is what lets you make predictable tradeoffs among capacity, cost, and user experience.