norboten · cheat sheet

A loaded model costs its weights plus a cache for every token it may hold — cheat sheet

ollama, kernel-performance, boot-systemd
# what the unit is allowed, what it used, whether it died
systemctl show ollama -p MemoryMax -p MemoryHigh -p MemoryPeak -p MemoryCurrent -p NRestarts -p Result
systemctl cat ollama
sudo journalctl -u ollama -o cat | grep -E 'oom-kill|OOM killer|Scheduled restart|Consumed'
sudo journalctl -k | grep -i 'out of memory'

# what the runtime tried
sudo journalctl -u ollama -o cat | grep -E 'projected to use|n_ctx|insufficient memory|kv cache|Load failed'

# what is loaded, and how big
curl -s 127.0.0.1:11434/api/ps | jq '.models[] | {name, size, context_length, expires_at}'

# from the client: 000 = connection dropped (killed), 500 = error answered
curl -s -o /dev/null -w '%{http_code}\n' 127.0.0.1:11434/api/generate -d '{"model":"qwen2.5:0.5b","prompt":"hi","stream":false}'

# sizing
[Service]
Environment="OLLAMA_CONTEXT_LENGTH=4096"     # tokens per request
Environment="OLLAMA_NUM_PARALLEL=2"          # simultaneous requests; cache ∝ context × parallel
MemoryMax=1536M                              # hard cap: OOM kill inside the cgroup
MemoryHigh=1200M                             # soft: throttle and reclaim first
sudo systemctl daemon-reload && sudo systemctl restart ollama