Local & Offline
~8 min readUpdated: December 2026

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

Commit-on-write KV cache memory management for multi-user CPU llama.cpp servers in Smoke Monkey

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.

Technical Review: Smoke Monkey Core Architecture Team
Tested on Node.js 18+ & BunTypeScript 5.x
Quick Answer & Executive Definition

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.

Key Architectural Takeaways
Quick Implementation Examplecpu-kv-budget-agent.ts
cpu-kv-budget-agent.tstypescript
import { createAgent } from '@smoke-monkey/harness';
// Multi-agent worker routing through an admission-budgeted CPU llama.cpp server
const 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);
Video Guides

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 DesignStartup CommitRelease on FinishConcurrency AdmissionPeak Memory (Qwen2.5-1.5B, 16k ctx)Behavior Below CPU Saturation
Stock llama.cpp (unified KV)Eager full buffer zero-fillRetained in user spaceStatic slot count12.3x higher (OOMs under 2-3 GiB caps)Queues users behind idle slot RAM
vLLM-CPUPaged block poolFreed to internal poolToken block watermarkModerate (runtime overhead)Fixed block allocator overhead
Commit-on-Write + Release + ProxyLazy OS demand pagingmadvise(MADV_DONTNEED)Model-config KV reservation1.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:

  1. Write (Commit-on-Write): Skip eager zero-filling and buffer-wide clear() on the KV allocation; rely on Linux mmap() demand paging so physical 4 KB pages are backed in RAM only as context tokens actually arrive.
  2. 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.
  3. 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:

bash
# 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")
'
Google Search Questions & Answers

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 guides

Build with Smoke Monkey Harness

Zero dependencies. 24 built-in tools. Human-in-the-loop safety. 100% open source under the MIT License.

npm install smoke-monkey-harness