Manuscript Offprint

arXiv:2610.02766

Exact Memory-Time Optimization for Prefix-Cached Language Model Serving

Shivam Gupta

Open access. PaperVantage converted this article to text, so layout and figures may differ from the original.

Abstract

Retaining language-model prefix states trades recomputation against storage time. Optimizing each cached block independently can overcount savings: a resident block is usable only when the required preceding prefix is also available. We introduce Prefix-Certificate Retention (PCR), an exact finite-trace formulation for static, grouped, reset-on-access timeouts. Usable-prefix rewards become nodes whose prerequisites are timeout thresholds and preceding hit certificates. The resulting maximum-weight closure reduces to one minimum cut, with graph size linear in the number of block lookups and timeout choices. A breakpoint theorem extends the construction to all nonnegative timeouts without discretization error. We also derive a linear-time-in-grid-size dynamic program for ordered timeouts and bounds that certify the cost of this restriction. Exhaustive small-instance checks and chronological replay of 39,632 public Mooncake requests validate the formulation. On the fixed grid, ordered timeouts attain the unrestricted training optimum in 118 of 120 trace-grouping-price cases. Heterogeneous retention improves several held-out memory-time tradeoffs, but finer training optimization does not uniformly improve transfer. The contribution is a tractable optimization model and an auditable benchmark for retention policies; the experiments measure usable prefix blocks and storage time, not GPU latency.

Keywords: prefix caching; maximum closure; time-to-live optimization; language model serving; memory-time budgets.

Code and reproducibility:

github.com/shi1720/prefix-certificate-retention

1 Introduction

Language-model services repeatedly process shared system prompts, conversation histories and agent instructions. Retaining their key-value (KV) states can avoid repeated prefill work, but every retained block occupies storage until it is reused or discarded. PagedAttention, RadixAttention and disaggregated cache architectures provide practical mechanisms for this reuse [6, 10, 12]. They also create an operational decision: how long should different parts of a prefix remain available?

The optimization is subtle even before queueing and hardware constraints enter. Consider a request for blocks (A,B)(A, B). If BB remains in an independently addressed store but AA has expired, counting BB as a saved prefix block is incorrect for a serving interface that resumes only from a contiguous cached prefix. Requiring the timeout of AA to be at least that of BB prevents this inconsistency. However, that requirement can retain AA unnecessarily: other requests may refresh AA while BB waits for reuse. Thus, independent hit accounting can be optimistic, whereas universally prefix-preserving timeout ordering can be conservative.

This paper asks three questions. Can actual prefix reuse be optimized exactly without imposing timeout order? Can the gap between ordered and unrestricted retention be certified?

S. Gupta

And do the resulting profiles improve memory-time tradeoffs on later requests? The first two questions admit deterministic answers within a precise model. The third requires empirical evaluation and has a mixed answer.

We study static group timeouts fitted to a historical trace. The objective is the number of reusable full prefix blocks minus a declared storage price times occupied block-seconds. It is a configuration objective for a cache store, not a complete inference-system objective. The main contributions are:

  1. An exact representation of contiguous-prefix reuse by a directed acyclic graph of hit certificates. Combining this representation with incremental storage costs yields a maximum-weight closure problem, solved by a standard minimum-cut algorithm (Theorem 2).

  2. A reuse-age breakpoint theorem that removes the timeout-grid restriction while retaining a graph of linear size (Theorem 3).

  3. A coherent-policy dynamic program and a three-way optimality bound, together with a strict counterexample and expected-budget certificates (Section 5).

  4. Reproducible tests and public-trace experiments separating mathematical optimality, the practical value of a simpler restriction, and held-out transfer (Sections 6–7).

Maximum closure and its reduction to minimum cut are classical [9]. Our contribution is the prefix-retention formulation, its exact accounting and breakpoint structure, and the resulting certification study. Neither differentiated timeouts nor prefix-aware cache management is claimed as new.