Long-Context LLM Serving: Managing the KV Cache Memory Budget Behind Usage Limits
This article explains why a large model service tightened its long-session retention, per-request input limits, and daily quotas during periods of heavy demand. It covers how KV cache memory limits concurrency and raises per-token cost for long contexts, why supply constraints and inefficient use of existing compute both matter, and which resource governance measures can help, including session lifecycle management, context compression, cache reuse, scheduling, and tiered quotas.
Recently, a large model service handled weekly token calls at the scale of tens of trillions during periods of heavy traffic. Call volume grew several-fold from the previous period and ranked among the highest, and the service experienced several outages. It then changed its long-session retention policy. Long conversations inactive for more than several days are no longer retained, the per-request input limit was lowered to tens of thousands of Chinese characters, and daily conversation quotas were introduced. On the surface, this is a product policy tightening. From an inference systems perspective, it looks more like memory resource governance. When demand rises steeply and supply cannot grow at the same rate, the system must decide which requests deserve priority access to scarce GPU memory.
This is often attributed to insufficient compute. More precisely, external regulation has tightened access to incremental compute, while the limits mainly address the structural problem of inefficient use of existing compute. Together, these create the “happy trouble” of large model services. The trouble is that supply cannot expand in step with demand. The happy part is that steep demand is itself direct evidence of the product’s value.
1. Limits Are a Resource Pricing Mechanism, Not a Capability Regression
The core resources of online LLM inference are not abstract “intelligence.” They are GPU memory, memory bandwidth, compute units, and scheduling queues. In multi-turn long conversations especially, the conversation history must stay in GPU memory as key-value pairs, forming the KV cache. As long as a session is treated as active, its cache can keep occupying memory. GPU memory capacity is fixed, so the longer each sequence’s KV cache, the fewer sequences the same memory can serve concurrently.
The limits therefore reclaim memory held by low-value, high-consumption requests from free or low-priority users, and they give scarce memory first to actively running online tasks. This works like a pricing and quota mechanism. A per-request input cap controls the KV cache size of each sequence. A daily quota controls total request volume. Evicting inactive sessions releases idle cache. In a model dominated by free consumer usage, hundreds of millions of monthly active users generate no direct revenue, yet they share inference resources with paying API customers. Without lifecycle governance, idle long sessions can structurally crowd out other workloads.
2. Why Long Context Is Expensive: KV Cache Size Inversely Affects Concurrency
Publicly reported measurements show that serving a 256K-token context can cost 3.6 to 7 times more per generated token than serving a 16K-token context. The cost does not come only from prefill computation. More importantly, at every decoding step the model must read the historical KV cache, which puts pressure on both memory capacity and memory bandwidth. A single sequence’s KV cache grows linearly with context length. After model weights, activations, and reserved space are subtracted from available memory, the feasible batch size drops accordingly.
The following pseudocode estimates memory usage:
# Estimate KV cache memory for a single sequencekv_bytes_per_token = 2 * layers * kv_heads * head_dim * dtype_bytesseq_kv_bytes = kv_bytes_per_token * seq_lenbatch_kv_bytes = seq_kv_bytes * batch_sizeavailable_for_kv = gpu_mem_bytes - weights_bytes - activation_bytes - reserved_bytesmax_batch = floor(available_for_kv / seq_kv_bytes)
The coefficient 2 accounts for the K and V caches. The formula shows that doubling seq_len roughly doubles the KV cache size per sequence. With a fixed memory ceiling, max_batch roughly halves. Lower concurrency reduces throughput, raises cost per token, and increases queuing latency and P99 latency. Long context is not impossible to support. It requires clear decisions about who pays for the extra memory, which sessions should stay resident, and which should be offloaded to storage or rebuilt from summaries.
3. Constrained Growth and Existing-Capacity Optimization: Analyze the Two Curves Separately
On the incremental side, overseas regulatory rules have extended controls from the physical cross-border movement of chips to remote compute provision. Overseas data centers that supply large amounts of advanced AI accelerator compute to companies headquartered in regulated regions may require licenses, and some transit regions have been designated as high-risk. This narrows the option of renting overseas data center capacity to supplement high-end compute. For any service that depends on large-scale inference, a narrower path to incremental compute means capacity planning must be more conservative.
The main cause of the limits, however, lies on the existing-capacity side. Under the free model, long session retention is too generous, so idle sessions keep occupying KV cache. A single very long input drives up the memory demand of one sequence. Without daily quotas, low-value requests crowd out peak-hour queues. In the short term, the most effective lever is not waiting for new GPUs but governing existing resources. This includes shortening the TTL for inactive sessions, offloading cold-session KV cache to storage and rebuilding it on resume, compressing historical context through summarization, reusing system prompts and prefix caches, adopting paged KV cache management to reduce fragmentation, applying continuous batching to raise throughput, and using preemptive scheduling to protect high-priority tasks.
A combined engineering strategy can be implemented as follows:
if session.idle_time > TTL:evict_kv_to_storage(session)if request.input_tokens > MAX_INPUT:summarize_or_reject()if tenant.daily_tokens > quota:enqueue_or_reject()priority = tenant.tier + task.urgencyschedule(batch, priority)
At the access layer, implement tenant isolation, daily quotas, and priority queues. At the scheduling layer, use continuous batching, chunked prefill, prefix reuse, and preemption with recomputation. At the storage layer, manage hot and cold session tiers and rebuild sessions from summaries. At the observability layer, track GPU memory utilization, KV cache occupancy, active session count, cache hit rate, queue latency, and cost per token. On general-purpose cloud platforms such as Baidu AI Cloud, these measures can be deployed with generic service categories such as GPU instances, container platforms, monitoring and alerting, and log services. Specific choices should be based on business SLAs and cost models.
4. Conclusion: Limits Are Governance, Not the End Point
Long-context capability is a product advantage, but long-context inference runs on a real memory budget. Targeted limits show that the problem lies not in inference capability itself, but in the structural crowding of scarce GPU memory by low-value, high-consumption requests from free users. External restrictions narrow the path to incremental compute, while existing-capacity optimization determines how many active requests each unit of compute can serve. Getting session lifecycle, context compression, cache reuse, scheduling, and tiered quotas right can turn the “happy trouble” into sustainable capacity governance when demand rises steeply.
