Ollama: "model requires more system memory than is available"
Ollama refuses to run the model and says I need more memory
错误信息
Error: model requires more system memory (9.2 GiB) than is available (7.6 GiB)
| 如果你看到 | 原因是 | 前往 |
|---|---|---|
| The required figure is larger than your total installed RAM | The model is too big for this machine at any setting | Fix 1: pull a smaller tag |
| The required figure is below your total RAM but above the available figure | Other programs or a loaded model hold the difference | Fix 2: close what is eating your RAM |
ollama ps lists a model you are not using | It is still resident from an earlier request | Fix 2: ollama stop <model> |
| The error appeared after you raised the context length | The KV cache for the larger window pushed the estimate over | Fix 3: shrink the context window |
何时出现
You run ollama run <model> and instead of a prompt you get this one-liner and an immediate exit. It happens most on 8 GB and 16 GB machines, and especially on laptops where a chunk of RAM is already spoken for.
- An 8 GB machine trying the default tag of an 8B model, which needs more than the RAM left over after the operating system.
- A laptop with integrated graphics, whose GPU memory is carved out of the same RAM.
- A second model still loaded from an earlier session — Ollama keeps models resident for five minutes by default.
- A large context length set for the server, which raises the estimate for every model.
- A browser, IDE or virtual machine holding several gigabytes in the background.
实际原因
Ollama does a sanity check before loading: it estimates how much memory the model plus its context will need and compares that to what is actually free right now (not your total installed RAM). If the estimate is higher than the free pool, it refuses to start rather than thrash or get OOM-killed mid-load. The number in the error is that estimate — and it grows with the model size and the context length. The available figure is what the operating system reports as free or reclaimable at that moment, and it moves: closing a browser can add several gigabytes, and a model Ollama loaded earlier keeps its memory until it is unloaded, five minutes after its last use by default. On a machine with a dedicated GPU, layers that fit in VRAM go there first and the check mostly concerns what is left over; on Macs and on laptops with integrated graphics, model and system share one pool, so all of it counts.
如何修复
- 1
Pull a smaller tag of the same model最常见的修复方法
Most Ollama models publish several sizes and quant levels as tags. If
llama3.1(the default 8B) is too heavy, there is almost always a:1bor:3bsibling, or a more aggressive quant like:q4_0. Dropping to a smaller tag is the cleanest fix and keeps you on the same model family. Check what your machine can actually hold before you pull, so you only download once.# instead of the heavy default tag: ollama run llama3.2:3b # or pick a smaller quant of the model you want: ollama run llama3.1:8b-instruct-q4_0生效了吗?The model starts and gives you a prompt, andollama pslists it with a size comfortably below the memory you have free.检查哪些模型适配你的硬件see which Ollama models fit your RAM before you pull them打开显存检查器 → - 2
Close what is eating your RAM
The check is against *free* memory, so a browser with 40 tabs or another model still resident can be the difference. Quit the obvious offenders and, if a previous Ollama model is still loaded, unload it first.
ollama ps # see what is currently loaded ollama stop <model> # unload it to free memory生效了吗?ollama psno longer lists the model you stopped, and Task Manager, Activity Monitor orfree -hshows that much more memory available. - 3
Shrink the context window
A big context allocation inflates the estimate. If you do not need a huge window, cap it — this can pull the requirement back under your free memory. It is a server setting: the error appears while
ollama runloads the model, before you could type/set parameter num_ctx, so setOLLAMA_CONTEXT_LENGTHwhere the Ollama server reads it and restart the server.# bash — set it on the SERVER, then restart Ollama. Prefixing `ollama run` # does nothing: the client does not read this variable. OLLAMA_CONTEXT_LENGTH=2048 ollama serve # Windows: set OLLAMA_CONTEXT_LENGTH in your user environment variables # macOS app: launchctl setenv OLLAMA_CONTEXT_LENGTH 2048, then reopen Ollama生效了吗?Once the model loads, the CONTEXT column ofollama psshows the smaller value. If it still shows the old one, the server never read the variable — restart it. - 4
Add swap as a last resort
On Linux you can give the system swap space so the loader has somewhere to spill. This will run, but it will be slow once it touches disk — treat it as a stopgap, not a solution. The durable answer is still a model that fits in real RAM.
生效了吗?swapon --showlists the new swap space andfree -hshows it under Swap. Expect generation to slow sharply whenever the model touches it.swapon --show free -h
如果以上都没用
If the model fits in free memory and the error persists, read the Ollama server log, which records the memory it detected at startup, and compare it with what your system monitor shows. On a Mac, a model that passes this check can still drive the machine into heavy swapping, which is a different failure with its own page.
- Your Mac is swapping to disk instead of running the model
- Out of memory at long context (the KV cache)
- Your Ollama environment variables are ignored on Linux
- The full error line, with both memory figures
ollama psoutput andollama -v- Installed RAM, and GPU model and VRAM if you have one
- The model tag and any context length you set
相关内容
常见问题
Does this mean my computer is too weak for local AI?
Not at all. It means this particular model is too big for your free memory. There are capable 1B–3B models that run comfortably on 8 GB machines — you just need to pick one sized for your hardware.
Can I force Ollama to run the model anyway?
You can lower the requirement (smaller tag, smaller context, freeing RAM) but you should not try to bypass the check itself — it exists to stop the model from getting killed mid-load or freezing your machine. Reduce the requirement instead of overriding the guardrail.
Why does it say less is available than my total RAM?
The error compares against currently free memory, not installed RAM. Your OS, background apps, and any already-loaded model are using some of it. Closing things or rebooting frees more of the pool.
Does a GPU help with this error?
Yes, if part of the model fits in its VRAM. Ollama places as many layers as it can on a dedicated GPU and keeps the rest in system RAM, so a card reduces what the system-memory check has to cover. Integrated graphics do not help, because they borrow from the same RAM the check is measuring.
How much free RAM does a model need?
Roughly its file size plus the context cache and some overhead. A 3B model at Q4 needs about 3–4 GB, and an 8B model about 6–7 GB at a typical context length. The analyzer computes the figure for a specific model, quantization and context length, so you can check before you pull.
Will adding more RAM fix it?
Yes, if the model's requirement is below what the upgraded machine would have free. It will not make the model fast: whatever runs from system RAM on the CPU is far slower than on a GPU. Check the requirement first, then decide whether a smaller model or more memory is the better use of the money.