How to stop an ollama model — the five-minute squat
Closing the chat unloads nothing. Ollama held qwen3:4b — 2.97 GiB of an 8 GiB box — for exactly five minutes after the last token, then let go to the second. Here are the doors out.
How to stop an ollama model: closing the chat unloads nothing. The server holds it warm on a five-minute timer. Our bench kept qwen3:4b — 2.97 GiB of an 8 GiB box — for exactly 300.0 seconds after the last token, then let go to the second. ollama ps is the only witness.
The chat ends. The rent doesn't. Now you hold the eviction notice.
How do I stop an ollama model from memory?
ollama stop takes a name and unloads immediately. Over the API the hold is a field: "keep_alive": 0 answers first, then empties the room.
ollama ps # the model is resident ollama stop qwen3:4b # the eviction notice ollama ps # {"models":[]}curl localhost:11434/api/chat -d '{ "model": "qwen3:4b", "messages": [{"role":"user","content":"Reply with the single word: ok."}], "stream": false, "keep_alive": 0 }'
Both measured: after ollama stop, {"models":[]}, exit 0. After keep_alive: 0, the answer still returns ("content":"ok") and RAM stayed at 477 MiB.
| door | scope | unload timing | hold after |
|---|---|---|---|
ollama stop <model> | one model, now | immediate | 0 s |
"keep_alive": 0 | this request | after answering | 0 s |
--keepalive 0 | this run | after answering | 0 s |
--keepalive 300s | this run | 5 min after last ask | 5:00 — unit required; 300 alone errors: missing unit in duration |
OLLAMA_KEEP_ALIVE=0 | every model, standing | after each ask | 0 s |
OLLAMA_KEEP_ALIVE=-1 | every model, standing | never (manual stop) | ∞ |
| no knob (default) | every model | 5 min after last ask | 5:00 |
How long does ollama keep a model loaded?
Five minutes from the last ask — every request resets the timer, so a long session never lets go. Measured ladder, qwen3:4b on a 4-thread CPU box:
| keep_alive | expires_at shift | measured hold | RAM after |
|---|---|---|---|
| default | +300 s | 5:00.0 to the second | 3,542 → 473 MiB at eviction |
0 | none | instant, post-answer | 477 MiB |
60 | +60 s | gone at the 65 s poll | ~3 GiB → base |
-1 | +293 years (stamped 2319-02-15) | still resident at +90 s | held until stopped |
env 2m | +120 s | per the stamp | held 2:00 |
The client is a messenger; residency belongs to the server. /api/ps said "size_vram": 0 — this is a CPU box. Per-request field beats env, env beats default. Env values are Go durations (300s, 5m, 1h).
from last token to empty room — expires_at stamped at ask time + 300 s, and the model held to the second.
Does closing the terminal unload the model?
No. Kill the chat, REPL or curl and the model stays warm five minutes. To clear the room, stop the server (sudo systemctl stop ollama) — memory freed, API door gone. For a standing rule, set OLLAMA_KEEP_ALIVE at boot.
sudo systemctl edit ollama # add: [Service] Environment="OLLAMA_KEEP_ALIVE=2m" sudo systemctl daemon-reload && sudo systemctl restart ollama
- ask who's resident:
ollama ps— or read/api/ps - need it gone now?
ollama stop <model> - scripting the last ask? add
"keep_alive": 0 - small box as a rule?
OLLAMA_KEEP_ALIVE=0drop-in;-1means never evict - unload everything:
curl -s localhost:11434/api/ps | jq -r '.models[].model' | xargs -r -n1 ollama stop—ollama pshas no machine format in 0.40.13
- last tested 2026-11-05 · ollama 0.40.13 (Arch package; 0.40.14 tagged upstream 11-03) · qwen3:4b Q4_K_M, digest 359d7dd4
- throwaway Arch VM · 4 threads · 8 GiB RAM · KVM · CPU-only · VM destroyed same session
- residency polled every 30 s via /api/ps across every hold · expires_at 2026-11-05T13:25:41.680418376Z · RAM 3,542 → 473 MiB at 13:25:41