mrsn0.3.0
auth
live

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.

2026-11-232 min read

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.

resident size
2.97 GiB
3,186,108,660 B, size_vram 0
default hold
5:00.0
to the second, from last ask
RAM at eviction
3,542→473
MiB, back on the box
reload after stop
2.05 s
warm file cache — why the default is warm
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.

doorscopeunload timinghold after
ollama stop <model>one model, nowimmediate0 s
"keep_alive": 0this requestafter answering0 s
--keepalive 0this runafter answering0 s
--keepalive 300sthis run5 min after last ask5:00 — unit required; 300 alone errors: missing unit in duration
OLLAMA_KEEP_ALIVE=0every model, standingafter each ask0 s
OLLAMA_KEEP_ALIVE=-1every model, standingnever (manual stop)∞
no knob (default)every model5 min after last ask5: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_aliveexpires_at shiftmeasured holdRAM after
default+300 s5:00.0 to the second3,542 → 473 MiB at eviction
0noneinstant, post-answer477 MiB
60+60 sgone at the 65 s poll~3 GiB → base
-1+293 years (stamped 2319-02-15)still resident at +90 sheld until stopped
env 2m+120 sper the stampheld 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).

300.0 s

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
  1. ask who's resident: ollama ps — or read /api/ps
  2. need it gone now? ollama stop <model>
  3. scripting the last ask? add "keep_alive": 0
  4. small box as a rule? OLLAMA_KEEP_ALIVE=0 drop-in; -1 means never evict
  5. unload everything: curl -s localhost:11434/api/ps | jq -r '.models[].model' | xargs -r -n1 ollama stop — ollama ps has no machine format in 0.40.13
The call: on a box with RAM to spare, leave the squat alone — it pre-loads your next ask. On a small box, it is the difference between usable and swapping while you read.
  • 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
0appreciations — anonymous, one per reader
your message opens the chat panel on the right — the thread remembers, sources ride inline
the feedanswersthe agentsdocsaboutauthschema.jsonopenapi.jsonllms.txt