Fix Ollama: model requires more system memory than is available
Fix Ollama model requires more system memory: unload other models, pick a smaller quantization, lower num_ctx, and check the container memory limit.
Error: 500 Internal Server Error: model requires more system memory (9.7 GiB) than is available (8.1 GiB)Before loading a model, Ollama estimates the memory it needs (the first number) and refuses if that exceeds what it believes is free (the second number). The message above is Ollama 0.20.7 output posted in official repository issue #15650. To get past it, shrink the first number (unload other models, use a smaller quantization, shorten the context) or raise the second (a higher memory limit).
[1] Read the two numbers separately. The first includes the context (KV cache) as well as the weights, so it is larger than the file size in ollama list. If the second is far below available in free -m, Ollama may not be counting reclaimable cache as free. The official repository has an open issue saying it seems to use MemFree instead of MemAvailable (#15704, LXC) and an open PR fixing the cgroup calculation (#15961); neither was closed as of 2026-10.
[2] Unload models that are already loaded. By default Ollama keeps a model in memory for 5 minutes (FAQ).
$ ollama ps$ ollama stop <model name>SIZE in ollama ps is the memory the model holds right now. If you switch between models, lower OLLAMA_MAX_LOADED_MODELS on the server, or send "keep_alive": 0 so the model unloads right after it answers.
[3] Pull a smaller quantization tag. The same model comes in different sizes. Here is ollama ps after loading qwen2.5:0.5b (default q4_K_M, 398MB) and qwen2.5:0.5b-instruct-fp16 (994MB) with the same 4096 context:
NAME ID SIZE PROCESSOR CONTEXT RUNNER UNTILqwen2.5:0.5b a8b0c5157701 486 MB 100% CPU 4096 llamacpp 4 minutes from nowNAME ID SIZE PROCESSOR CONTEXT RUNNER UNTILqwen2.5:0.5b-instruct-fp16 c82efd44bfdc 1.1 GB 100% CPU 4096 llamacpp 4 minutes from nowfp16 is more than twice as large. The Tags list on each model page shows every tag's size (qwen2.5:0.5b: q8_0 531MB, q4_K_M 398MB, q2_K 339MB). Compare that size with your free memory before you pull, and if it still doesn't fit, switch to a model with fewer parameters (for example 3b instead of 7b).
[4] Shorten the context. The same qwen2.5:0.5b loaded with num_ctx 2048 and then 32768, checking the size with ollama ps after each request. HTTP 200 is a test line that prints only the status code instead of the response body (the real request also had -o /dev/null -w "HTTP %{http_code}\n" and "num_predict":3 for a short answer):
$ curl -s localhost:11434/api/generate -d '{"model":"qwen2.5:0.5b","prompt":"hi","stream":false,"options":{"num_ctx":2048}}'HTTP 200$ ollama psNAME ID SIZE PROCESSOR CONTEXT RUNNER UNTILqwen2.5:0.5b a8b0c5157701 458 MB 100% CPU 2048 llamacpp 4 minutes from now$ curl -s localhost:11434/api/generate -d '{"model":"qwen2.5:0.5b","prompt":"hi","stream":false,"options":{"num_ctx":32768}}'HTTP 200$ ollama psNAME ID SIZE PROCESSOR CONTEXT RUNNER UNTILqwen2.5:0.5b a8b0c5157701 940 MB 100% CPU 32768 llamacpp 4 minutes from nowEven on a tiny model, context alone doubled the footprint; the KV cache share grows with model size. You can set it in three places (official FAQ):
| Where | How |
|---|---|
| Whole server | Environment variable OLLAMA_CONTEXT_LENGTH=2048 (default 4096) |
Inside ollama run | /set parameter num_ctx 2048 |
| API request | "options": {"num_ctx": 2048} |
The FAQ says required RAM scales with OLLAMA_NUM_PARALLEL × OLLAMA_CONTEXT_LENGTH. If you raised parallelism, set it back to 1.
[5] Quantize the KV cache. With OLLAMA_KV_CACHE_TYPE=q8_0 on the server, the FAQ says it uses about half the memory of f16 with a very small loss in precision (q4_0 is about a quarter, with more loss). It applies only when Flash Attention is on; Ollama enables it automatically where supported, and OLLAMA_FLASH_ATTENTION=1 forces it. Set variables on the server process: for the Linux service, add Environment="OLLAMA_KV_CACHE_TYPE=q8_0" under [Service] with systemctl edit ollama.service, then systemctl daemon-reload and systemctl restart ollama. To roll back, remove the line and run the same two commands.
[6] If Ollama runs in Docker, check the container memory limit. Version 0.40.11 treated the --memory limit as total memory (startup log of a --memory 512m --memory-swap 512m container):
time=2026-10-27T07:50:54.430Z level=INFO source=types.go:50 msg="inference compute" id=cpu library=cpu compute="" name=cpu description=cpu libdirs=ollama driver="" pci_id="" type="" total="512.0 MiB" available="416.6 MiB"time=2026-10-27T07:50:56.953Z level=INFO source=sched.go:658 msg="system memory" total="512.0 MiB" free="416.6 MiB" free_swap="12.0 GiB"But free_swap showed host swap that the container couldn't use, so the pre-check passed and the runner loading the fp16 model was killed inside the container. Instead of the message above, you get:
{"error":"llama-server process has terminated: signal: killed"}HTTP 500In the same 512MB container, qwen2.5:0.5b with num_ctx 2048 loaded with HTTP 200 (SIZE 458 MB). Give docker run --memory comfortable headroom over the model's SIZE, or shrink it with [3] and [4]. If the server doesn't answer at all, see Ollama connection refused 11434. If you have a GPU but ollama ps shows 100% CPU and only system memory is used, check Ollama using CPU instead of GPU first.