# "Ollama fails with signal: killed: out of memory on a VPS" | Nuvits

Source: [https://nuvits.net/en/blog/ollama-out-of-memory-signal-killed](https://nuvits.net/en/blog/ollama-out-of-memory-signal-killed)

Published 2026-11-29, by Fernando Chagas.

When a model does not fit in the VPS's memory, Ollama 0.40 returns `Error: 500 Internal Server Error: llama-server process has terminated: signal: killed`. The kernel kills the process for lack of RAM, and the message does not say so. The test below ran on 29 November 2026 on Ubuntu 24.04.5 LTS, with Ollama 0.40.19 in Docker, the `llama3.2:3b` model on CPU only, and container memory limits to simulate smaller servers.

![Ollama 0.40.19 test results with llama3.2:3b on CPU: with 1 GiB, and with 2 GiB and a 32768 context, the process was killed; with 2 GiB and a 4096, 8192 or 16384 context with q8_0 cache, the model answered](https://nuvits.net/blog/ollama-out-of-memory-signal-killed/ollama-memory-context-results.webp)

## What the error looks like

In the terminal, with `ollama run`:

```text
Error: 500 Internal Server Error: llama-server process has terminated: signal: killed
```

In the container log (`docker compose logs ollama`):

```text
level=INFO source=sched.go:684 msg="Load failed" model=/root/.ollama/models/blobs/sha256-dde5... error="llama-server process has terminated: signal: killed"
```

The `ollama` server stays up and the container does not restart. What dies is the `llama-server` child process that loads the model. On every new request, Ollama tries to load it again and it dies again, which is why the problem looks intermittent if you only watch the API.

> **The old message is gone.** Guides for earlier versions mention `model requires more system memory`. That message does not exist in the 0.40.19 code. In 0.40, running out of memory shows up as `signal: killed`.

## Confirm it is memory

Three commands settle it. The first shows whether the kernel killed something inside the container (the container name is in `docker compose ps`):

```bash
docker inspect --format '{{.State.OOMKilled}}' ollama-ollama-1
```

`true` means memory. The kernel logs the same event:

```bash
sudo journalctl -k --since "-10min" | grep -i "out of memory"
```

```text
Memory cgroup out of memory: Killed process 1951950 (llama-server) total-vm:3090748kB, anon-rss:1038536kB, ...
```

And Ollama's startup log shows how much memory it sees. It respects the container limit:

```text
msg="inference compute" id=cpu library=cpu ... total="1.0 GiB" available="220.1 MiB"
```

Without a container limit, the system-wide OOM killer acts instead, and the kernel line starts with `Out of memory` rather than `Memory cgroup out of memory`.

## Why it happens

The memory a model uses is the sum of two large parts. The weights take a fixed amount: in the test, `llama3.2:3b` loaded 1918 MiB. The KV cache holds the conversation context and grows in step with the context size. A large context can weigh more than the model itself.

The same model on the same machine gave different results depending on memory and context:

| RAM limit | Context (`OLLAMA_CONTEXT_LENGTH`) | KV cache                  | Result                     |
| --------- | --------------------------------- | ------------------------- | -------------------------- |
| 1 GiB     | default (4096)                    | f16                       | killed (`OOMKilled=true`)  |
| 2 GiB     | default (4096)                    | f16                       | answered                   |
| 2 GiB     | 32768                             | f16                       | killed (`OOMKilled=true`)  |
| 2 GiB     | 8192                              | f16                       | answered, 1.825 GiB in use |
| 2 GiB     | 16384                             | q8_0 with flash attention | answered, 1.825 GiB in use |

With 2 GiB, the model works with a 4096 context and dies with 32768. Before switching models, check the configured context.

## How to fix it

Go in order. Each step costs less than the next.

1. **Lower the context.** Set `OLLAMA_CONTEXT_LENGTH=4096` or `8192` in the service environment. For a single request, the API accepts `"options": {"num_ctx": 4096}`.
2. **Quantise the KV cache.** `OLLAMA_KV_CACHE_TYPE=q8_0` together with `OLLAMA_FLASH_ATTENTION=true` shrinks the cache. In the test, that made a 16384 context fit in the same 2 GiB.
3. **Load one model at a time.** `OLLAMA_MAX_LOADED_MODELS=1` stops two models sharing memory, and `OLLAMA_NUM_PARALLEL=1` keeps parallel requests from multiplying the KV cache.
4. **Use a smaller model.** A 1b or 3b instead of a 7b or 8b, or more RAM on the VPS.

The variables are documented in the [Ollama FAQ](https://docs.ollama.com/faq) and in `envconfig/config.go` in the [official repository](https://github.com/ollama/ollama). The `docker-compose.yml` from the last row of the table:

```yaml docker-compose.yml
services:
  ollama:
    image: ollama/ollama:0.40.19
    restart: unless-stopped
    volumes:
      - ollama:/root/.ollama
    mem_limit: 2g
    environment:
      OLLAMA_CONTEXT_LENGTH: "16384"
      OLLAMA_KV_CACHE_TYPE: "q8_0"
      OLLAMA_FLASH_ATTENTION: "true"
volumes:
  ollama:
```

Apply it with `docker compose up -d` and check the effective context with `docker compose exec ollama ollama ps`.

`mem_limit` is optional, but it helps on a VPS that runs other things. With the limit, the kernel kills only `llama-server` when memory runs out. Without it, the OOM killer may pick another process, such as the database. Choose a value that leaves room for the rest of the server.

> **`ollama ps` does not show real usage.** In the test, the `SIZE` column read 3.9 GB with an 8192 context and 3.2 GB with 16384 in q8_0, while `docker stats --no-stream` measured 1.825 GiB in both cases. Use `ollama ps` for the context and processor, and `docker stats` or `free -m` for memory.

Swap may keep the process alive, but memory pushed out to disk makes CPU generation much slower. Do not treat it as a fix.

## What the test did not cover

GPU, models larger than 3b and swap were not tested. Generation speed was left out too, because the test ran in a virtual machine and its tokens-per-second numbers do not carry over to a VPS.

To set up Ollama with Open WebUI and HTTPS, follow [How to install Ollama and Open WebUI on a Linux VPS](https://nuvits.net/en/blog/install-ollama-open-webui-linux-vps). To split RAM between Ollama and other services such as n8n and Evolution API, see [How much RAM and vCPU for n8n, Evolution API and Coolify](https://nuvits.net/en/blog/how-much-ram-vcpu-n8n-evolution-api-coolify-vps). Larger models need more memory: the [Linux VPS](https://nuvits.net/en/linux-vps) and [Docker VPS](https://nuvits.net/en/docker-vps) plans list the options.
