In short: Run ollama ps first: anything other than 100% GPU means the model spilled into system memory. Then cut, in this order: parallel requests and loaded models, the context length, the KV cache precision (q8_0 halves it), and finally the model size. If the agent needs a 64K context and a 7B model does not fit with it, the machine is too small for that job.
| Check | ollama ps, PROCESSOR column: 100% GPU, 100% CPU or a split |
|---|---|
| Default context | 4k under 24 GiB VRAM, 32k at 24 to 48 GiB, 256k at 48 GiB or more |
| Agents need | at least 64000 tokens of context, per Ollama's docs |
| Parallel requests | multiply the context: 2K x 4 requests = 8K |
| KV cache q8_0 / q4_0 | about 1/2 / 1/4 of f16's memory; needs Flash Attention |
See where the model landed
ollama psOllama's FAQ explains the PROCESSOR column: 100% GPU "means the model was loaded entirely into the GPU", 100% CPU that it "was loaded entirely in system memory", and a split such as 48%/52% CPU/GPU that it was loaded partly onto both. A split is the quiet form of running out of memory: nothing crashes, the answers just get slow. Newer versions also show a CONTEXT column, which tells you what context the model was loaded with.
The server log says why. Ollama gives these locations:
# macOS
cat ~/.ollama/logs/server.log
# Linux (systemd)
journalctl -u ollama --no-pager --follow --pager-endIn Docker, the troubleshooting page also describes a different problem with the same symptom: Ollama "switches to running on CPU after some period of time with errors in the server log reporting GPU discovery failures". That is the GPU going missing, not memory running out; the log tells them apart.
Context length: the setting that grows quietly
Ollama's context docs: "Setting a larger context length will increase the amount of memory required to run a model." The default now depends on the memory of the GPU:
| VRAM | Default context |
|---|---|
| under 24 GiB | 4k |
| 24 to 48 GiB | 32k |
| 48 GiB or more | 256k |
The same page says "Tasks which require large context like web search, agents, and coding tools should be set to at least 64000 tokens." That is the tension for an agent host: the context an agent needs is many times the default on a small GPU, and raising it is often what pushes the model out of memory. Set it for the server, or per model:
OLLAMA_CONTEXT_LENGTH=64000 ollama serve
# per model, in ollama run
/set parameter num_ctx 4096
# per request, through the API
"options": {"num_ctx": 4096}Lower it until ollama ps shows 100% GPU, and check that the agent still works at that size: cutting the context below what the agent sends trades a memory error for an agent that cannot see its whole conversation.
Parallel requests and loaded models
OLLAMA_NUM_PARALLEL is "the maximum number of parallel requests each model will process at the same time", and each one needs its own context. Ollama's example: "a 2K context with 4 parallel requests will result in an 8K context and additional memory allocation." An agent that runs sub-agents or tools in parallel against one model hits this. For a single-user agent host, OLLAMA_NUM_PARALLEL=1 is the setting that frees the most.
OLLAMA_MAX_LOADED_MODELS defaults to "3 * the number of GPUs or 3 for CPU inference". If your agent uses one model for chat and another for embeddings or summaries, both may stay resident; models stay in memory for 5 minutes after use by default. Setting OLLAMA_MAX_LOADED_MODELS=1 trades reload time for memory.
A smaller KV cache: q8_0, and Flash Attention
OLLAMA_KV_CACHE_TYPE sets the precision of the context cache, for every model the server runs. From the FAQ: f16 is the default, with "high precision and memory usage"; q8_0 "uses approximately 1/2 the memory of f16 with a very small loss in precision"; q4_0 "uses approximately 1/4 the memory of f16 with a small-medium loss in precision". It requires Flash Attention, which Ollama "uses automatically when the selected backend and devices support it"; OLLAMA_FLASH_ATTENTION=1 forces it on.
OLLAMA_FLASH_ATTENTION=1 OLLAMA_KV_CACHE_TYPE=q8_0 ollama serveq8_0 is the boring choice: half the cache memory, a very small loss. NVIDIA's own OpenClaw tutorial for the 8 GB Jetson Orin Nano uses exactly these two settings (see the Jetson Orin Nano page). On a systemd install, put them in the service's environment rather than on a command line.
When none of that is enough: a smaller model, or more memory
The weights are the floor. These are the download sizes of common default tags on Ollama's library, at 4-bit (Q4_K_M) unless noted; the memory in use is larger once the context is added:
| Model (tag) | Download |
|---|---|
| llama3.2:1b (Q8_0) | 1.3 GB |
| llama3.2:3b | 2.0 GB |
| gemma3:4b | 3.4 GB |
| mistral:7b | 4.4 GB |
| llama3.1:8b | 4.9 GB |
| qwen3:8b | 5.2 GB |
| gemma3:12b | 8.2 GB |
| qwen3:14b | 9.3 GB |
| gpt-oss:20b (MXFP4) | 14 GB |
| gemma3:27b | 17 GB |
| qwen3:32b | 20 GB |
| llama3.3:70b | 43 GB |
Going from an 8B to a 4B model, by these sizes, frees about 1.5 GB of weights before the context is counted. On a Mac, the GPU does not get all of the unified memory: community reports in llama.cpp's discussions put the default share at about two thirds to three quarters. Apple and Ollama do not document it, so treat it as an estimate, and leave room on a 16 GB machine.
If the model you need does not fit at the context the agent needs, the fix is hardware. For a 7B or 8B model with a long context next to an agent, 24 GB of unified memory is the size we point to (Mac mini M4, 16 GB vs 24 GB, Mac mini M4 on Amazon); larger models are on the Ryzen AI Max page and our estimates per agent on how much RAM an agent needs.
What to buy
- Mac mini M4: take 24 GB or more if a 7B or 8B model with a long context has to sit next to the agent.
- Ryzen AI Max+ 395 mini PC: for models beyond what a Mac mini M4 holds.
Shop links go through /go/ and open Amazon (amazon.fr in the EU and Switzerland, amazon.com elsewhere). As an Amazon Associate we earn from qualifying purchases. Your price does not change and no brand pays for a place on this page (disclosure). We write no price down: it moves, the shop shows today's.
Questions
How do I know if Ollama is running out of memory?
Does a bigger context use more memory in Ollama?
What does OLLAMA_KV_CACHE_TYPE=q8_0 do?
What context length should I give an agent?
Does Ollama document an out-of-memory fix?
Sources
- Ollama docs, context length, read on 21 November 2026.
- Ollama docs, FAQ (parallel requests, KV cache, ollama ps), read on 21 November 2026.
- Ollama docs, troubleshooting (logs, GPU discovery), read on 21 November 2026.
- Ollama docs, GPU support, read on 21 November 2026.
- Ollama library, llama3.2 tags, read on 21 November 2026.
- Ollama library, llama3.1 tags, read on 21 November 2026.
- Ollama library, qwen3 tags, read on 21 November 2026.
- Ollama library, gemma3 tags, read on 21 November 2026.
- Ollama library, mistral tags, read on 21 November 2026.
- Ollama library, gpt-oss, read on 21 November 2026.
- Ollama library, llama3.3 tags, read on 21 November 2026.
- llama.cpp discussion 2182, Metal memory share (community reports), read on 21 November 2026.
- NVIDIA Jetson AI Lab, OpenClaw tutorial, read on 21 November 2026.