Once you move past single-turn chat and start running autonomous coding loops over a real repository, the bottleneck in local inference flips overnight. Compute stops being the villain; memory footprint and bandwidth take the crown.1

In an interactive session, 85–95% of your prompt tokens are prefix reuse: the system prompt, tool schemas, repository map, and previous turns. Recomputing that prefill from scratch on every turn wastes tens of seconds of GPU time. Holding every dormant session in VRAM or unified RAM, however, starves active decode batches.

§ 01 The Three-Tier Residency Model

The clean solution looks remarkably like a classical operating system virtual memory hierarchy. Instead of treating the KV cache as a monolithic tensor pinned in device memory, we partition it into fixed 64-token pages indexed by a rolling BLAKE3 content hash.2

TIER 0 · HOT Device / Unified INT4 · ~250 GB/s Active decode heads TIER 1 · WARM Pinned Host RAM DMA · ~48 GB/s Recent turns & forks TIER 2 · COLD NVMe Slab Pool O_DIRECT · 6.4 GB/s 48 GiB ring buffer EVICTION POLICY: LRU-K WITH PREFIX PINNING · PREFETCH PIPELINED PER LAYER
Figure 1 — Asynchronous layer-pipelined KV paging overlaps NVMe DMA reads with layer N-1 attention compute.

§ 02 Avoiding Kernel Compaction Stalls

Direct I/O into a 48 GiB slab pool works beautifully until the Linux kernel decides to compact fragmented memory zones mid-allocation. Setting vm.compaction_proactiveness=0 eliminates background stall spikes that otherwise look identical to a network wedge.

# /etc/sysctl.d/99-inference-kv.conf
vm.compaction_proactiveness = 0
vm.swappiness = 1
vm.dirty_background_ratio = 3
vm.dirty_ratio = 8
Listing 1 — Minimal sysctl tuning for predictable NVMe-backed KV pools.
Predictable tail latency beats peak synthetic throughput every single time when you are actually sitting at the terminal waiting for a diff.

§ 03 Measured Prefix Restore Latency

Prefix Length Cold Prefill NVMe INT4 Restore Speedup
16,384 tokens 4.82 s 0.41 s 11.7×
65,536 tokens 23.90 s 1.58 s 15.1×
131,058 tokens 56.40 s 3.12 s 18.1×

Even over a modest PCIe Gen4 drive, streaming quantized KV pages beats recomputing attention by an order of magnitude once prefixes cross 16K tokens. And because the entire stack speaks plain files and fixed offsets, crash recovery is literally truncating an index header.