Write, Return, Reserve: Commit-on-Write KV Memory for CPU LLM Servers

Write, Return, Reserve (arXiv:2612.02487) fixes multi-user memory exhaustion in CPU LLM servers such as llama.cpp, which eagerly zero-fills and commits entire per-slot KV caches at startup. By switching to OS commit-on-write allocation, returning idle KV pages via madvise(MADV_DONTNEED), and gating concurrency with an admission proxy, peak memory drops 12.3x at 16k context while raising below-saturation throughput 1.17-1.26x.
Write, Return, Reserve: Commit-on-Write KV Memory for CPU LLM Servers: Write, Return, Reserve (arXiv:2612.02487) fixes multi-user memory exhaustion in CPU LLM servers such as llama.cpp, which eagerly zero-fills and commits entire per-slot KV caches at startup. By switching to OS commit-on-write allocation, returning idle KV pages via madvise(MADV_DONTNEED), and gating concurrency with an admission proxy, peak memory drops 12.3x at 16k context while raising below-saturation throughput 1.17-1.26x. Designed as a zero-dependency, open-source TypeScript architecture under the MIT License with native Model Context Protocol (MCP) support and deterministic phase state machines.
- 12.3x Lower Peak Memory: Eliminates startup zero-filling and eager buffer clearing in llama.cpp on 16k-context multi-slot CPU servers with exact greedy and perplexity parity.
- Zero Throughput Penalty at Parity: Across three controlled sessions, modified/unmodified throughput ratio measured 0.996 (95% CI: 0.92-1.08) for identical workloads.
- 1.17-1.26x Higher Concurrency Throughput: Below CPU saturation on memory-capped nodes (2-3 GiB), extra admitted slots lift aggregate token throughput without OOM kills.
- Validated Across 199 Pre-Registered Outcomes: Tested across 1B-14B Qwen2.5 and Llama-3.2 models on Intel c7i (AMX) and AWS Graviton3 ARM servers (179/199 exact predictions).
import { createAgent } from '@smoke-monkey/harness';// Multi-agent worker routing through an admission-budgeted CPU llama.cpp serverconst agent = createAgent({agentId: 'cpu-kv-budgeted-agent',provider: 'openai-compatible',baseUrl: 'http://127.0.0.1:8081/v1',model: 'Qwen2.5-7B-Instruct-Q4_K_M',workspacePath: process.cwd(),permissions: {read_file: 'allow',write_file: 'ask',run_command: 'ask',},});async function main() {const result = await agent.run('Audit the server admission proxy configuration and verify max KV reservation per slot stays inside the 6 GiB cgroup limit.');console.log('CPU Server Audit:', result.summary);}main().catch(console.error);
Watch: Related Video Guides
llama.cpp Cut 31 Wasted GPU Passes
Stop Running Out of VRAM! Ultimate Guide to LLM KV Cache Optimization
What Is Commit-on-Write KV Memory for CPU LLM Servers?
Write, Return, Reserve (Kethisvarasuthan & Peiris, arXiv:2612.02487) is a systems design for multi-user CPU LLM inference servers that cuts peak resident memory by up to 12.3x without changing model outputs. Unmodified llama.cpp allocates and zero-fills or clears its entire virtual KV cache buffer at startup, forcing the Linux kernel to commit physical RAM pages for every unused token in every 16k-context slot.
By deferring physical page commitment until first write, returning finished requests' KV pages to the OS kernel, and admitting requests through a memory-budgeted proxy, CPU servers can serve bursts of short agent queries concurrently inside tight 2-10 GiB cgroup limits.
| CPU Serving Design | Startup Commit | Release on Finish | Concurrency Admission | Peak Memory (Qwen2.5-1.5B, 16k ctx) | Behavior Below CPU Saturation |
|---|---|---|---|---|---|
Stock llama.cpp (unified KV) | Eager full buffer zero-fill | Retained in user space | Static slot count | 12.3x higher (OOMs under 2-3 GiB caps) | Queues users behind idle slot RAM |
| vLLM-CPU | Paged block pool | Freed to internal pool | Token block watermark | Moderate (runtime overhead) | Fixed block allocator overhead |
| Commit-on-Write + Release + Proxy | Lazy OS demand paging | madvise(MADV_DONTNEED) | Model-config KV reservation | 1.0x baseline (exact greedy match) | 1.17-1.26x higher throughput |
The Three Changes: Lazy Commitment, Kernel Page Return, and Proxy Admission
Kernel /proc/<pid>/smaps profiling revealed that stock llama.cpp commits gigabytes of anonymous RSS before processing a single prompt because initialization memset and ggml_backend_buffer_clear touch every page. Three surgical changes eliminate that waste:
- Write (Commit-on-Write): Skip eager zero-filling and buffer-wide
clear()on the KV allocation; rely on Linuxmmap()demand paging so physical 4 KB pages are backed in RAM only as context tokens actually arrive. - Return (Release Idle Pages): When a request completes (and prompt caching is off or evicted), issue
madvise(MADV_DONTNEED)on the finished slot's KV range so the kernel immediately reclaims physical frames for active slots or co-located services. - Reserve (Proxy Admission Control): An external admission proxy calculates each queued request's worst-case KV footprint directly from
config.json(n_layers * n_kv_heads * head_dim * 2 * bytes_per_elem * max_tokens) and admits requests only while total reserved KV fits inside the server's memory budget.
Do Not Over-Admit Past CPU Saturation
The paper demonstrates across Intel c7i and Graviton3 ARM tests that returning unused KV pages increases throughput (1.17-1.26x) only while CPU cores have spare capacity; once compute is saturated, extra concurrent requests start earlier but increase per-token latency without raising total tokens/s.
Reproducible Kernel RSS Profiling and Admission Calculation
Measure how much anonymous KV RAM your CPU llama-server eagerly commits at startup using Linux smaps_rollup and verify per-slot KV budgets before configuring your reverse proxy:
# 1. Launch llama-server with 8 slots at 16k context and measure committed RSS immediately
llama-server -m Qwen2.5-1.5B-Instruct-Q4_K_M.gguf --ctx-size 131072 --parallel 8 --port 8081 &
SERVER_PID=$!
sleep 3
grep -E "Rss:|Pss:|Anonymous:" /proc/$SERVER_PID/smaps_rollup
# 2. Compute per-request KV reservation in bytes from model metadata
python3 -c '
layers, kv_heads, head_dim, bytes_per_elem, max_tokens = 28, 2, 128, 2, 16384
kv_bytes = layers * kv_heads * head_dim * 2 * bytes_per_elem * max_tokens
print(f"Max KV reservation per 16k request: {kv_bytes / (1024**2):.2f} MiB")
'Frequently Asked Questions
Q:Why does stock llama.cpp consume 12.3x more peak memory on 16k-context CPU servers?
At startup, stock llama.cpp zero-fills and clears the entire preallocated KV buffer across all configured slots, causing the OS kernel to commit physical RAM pages even for context tokens that are never used.
Q:Does commit-on-write KV allocation alter greedy outputs or perplexity?
No. Because attention masks only read tokens already written into the KV cache, skipping upfront zero-filling of unwritten pages produces bit-identical greedy outputs and identical perplexity.
Q:What happens to throughput once all CPU cores are saturated?
Below CPU saturation, admitting more concurrent users lifts throughput by 1.17-1.26x. Once CPU compute is saturated, aggregate throughput plateaus: requests start sooner with lower queueing delay, while per-token decode takes slightly longer.
Q:Which hardware and model sizes were tested in the paper?
The authors evaluated 1B to 14B models (including Llama-3.2-1B and Qwen2.5-1.5B/7B/14B) across Intel Xeon c7i instances with AMX and AWS Graviton3 ARM servers without AMX.
Related Alternatives & Comparisons
Related Architecture Guides
View all guidesBest Open Source Coding Agents in 2026: Free, Local & Fully Hackable Harnesses
MCP Server Security Best Practices: Hardening Model Context Protocol Agents in 2026
Open Source Coding Agent Harness: Build a Forkable, Local AI Engineering Runtime
Build with Smoke Monkey Harness
Zero dependencies. 24 built-in tools. Human-in-the-loop safety. 100% open source under the MIT License.