> ## Documentation Index
> Fetch the complete documentation index at: https://help.freakhosting.com/llms.txt
> Use this file to discover all available pages before exploring further.

# How to Fix Processes Killed by the Linux OOM Killer

> When the OOM killer killed a process, find it with journalctl -k, see what used the RAM, then add swap, lower memory settings or protect key services.

The Linux OOM (out-of-memory) killer stops a process when the server runs out of RAM and swap, so the rest of the system survives. Confirm it with `sudo journalctl -k | grep -i 'killed process'`, find what used the memory with `ps aux --sort=-%mem | head`, then add swap, lower the memory settings of the biggest program, or move to a plan with more RAM.

```text theme={null}
Out of memory: Killed process 1234 (mysqld) total-vm:2458340kB, anon-rss:1203840kB, file-rss:0kB, shmem-rss:0kB, UID:110 pgtables:3120kB oom_score_adj:0
```

| Difficulty | Time | Works on | Needs |
| - | - | - | - |
| Intermediate | 15 to 30 minutes | Ubuntu 22.04 / 24.04, Debian 12 / 13, AlmaLinux and Rocky Linux 9 / 10 | Root or sudo access |

## Before you start

* Typical signs: a database, game server or website stops without an error of its own, or a terminal command just prints `Killed`.
* Restart the killed service first (`sudo systemctl restart mariadb`, for example) so your site is back while you look for the cause.
* Commands use `sudo`. As root, leave it out.

## Step 1: Confirm the OOM killer did it

```bash theme={null}
sudo journalctl -k --since "2 days ago" | grep -iE 'out of memory|killed process'
```

`sudo dmesg -T | grep -i 'killed process'` shows the same since the last boot.

| Line in the log | Meaning |
| - | - |
| `Out of memory: Killed process ...` | The whole server ran out of RAM and swap. |
| `Memory cgroup out of memory: Killed process ...` | A limit on one service or container was reached, not the whole server (Cause 4). |

For a systemd service, its own log says so as well:

```bash theme={null}
sudo journalctl -u mariadb -n 20
```

```text theme={null}
mariadb.service: A process of this unit has been killed by the OOM killer.
mariadb.service: Failed with result 'oom-kill'.
```

## Step 2: See what uses the memory

```bash theme={null}
free -h
ps aux --sort=-%mem | head -n 8
```

`free -h` shows total RAM, what is used and whether swap exists. The `ps` list shows the biggest processes first; the `RSS` column is the memory in use, in kilobytes. Watch it live with [htop](https://help.freakhosting.com/portals/other/how-to-monitor-server-resources-with-htop.md) (press **Shift+M** to sort by memory).

## Cause 1: One program is set to use too much

Databases, Java apps and game servers take the memory their settings allow. A setting larger than your RAM guarantees an OOM kill.

**Fix:** lower the setting so all your programs fit, with room left for the system:

| Program | Setting |
| - | - |
| MySQL / MariaDB | `innodb_buffer_pool_size` in the server config |
| Java (Minecraft and others) | `-Xmx` in the start command, for example `-Xmx4G` on an 8 GB server |
| PHP-FPM | `pm.max_children` in the pool file |
| Apache (prefork) | `MaxRequestWorkers` |

A program whose memory keeps growing until it is killed has a memory leak. Update it, or restart it on a schedule until the fix is out.

## Cause 2: There is no swap

Swap is disk space the kernel uses as overflow when RAM is full. It is much slower than RAM, but it can turn a sudden kill into a short slowdown.

**Check:** `free -h` shows `Swap: 0B`.

**Fix:** add a swap file of 1 to 2 GB. See [add swap space on Linux](https://help.freakhosting.com/portals/other/how-to-add-swap-space-on-linux.md). Swap doesn't fix a server that is permanently short of RAM.

## Cause 3: Too much traffic or too many workers

Each web worker, PHP process or player uses memory. A traffic spike, a crawler or a small attack multiplies them.

**Fix:** cap the number of workers (Cause 1 table), add caching, and block abusive traffic with [Fail2ban](https://help.freakhosting.com/portals/other/how-to-set-up-fail2ban-for-ssh-on-ubuntu.md) or [CrowdSec](https://help.freakhosting.com/portals/other/how-to-install-crowdsec-on-linux.md).

## Cause 4: A service or container limit

`Memory cgroup out of memory` means a limit you or a tool set was reached: `MemoryMax=` in a systemd unit, or `--memory` / `mem_limit` in Docker.

**Check:**

```bash theme={null}
systemctl show mariadb -p MemoryMax
docker stats --no-stream
```

**Fix:** raise the limit, or lower the program's own memory settings so it stays below it. See [limit CPU and memory for a process](https://help.freakhosting.com/portals/other/how-to-limit-cpu-and-memory-for-a-process.md).

## Protect your most important service

You can make the kernel prefer other processes. Open an override for the service:

```bash theme={null}
sudo systemctl edit mariadb
```

Add:

```ini theme={null}
[Service]
OOMScoreAdjust=-500
```

Save, then run `sudo systemctl restart mariadb`. The range is `-1000` (never kill) to `1000` (kill first). Use `-1000` sparingly: if nothing else can be killed, the server may freeze instead.

## How to check it worked

Over the next days, this should print nothing new:

```bash theme={null}
sudo journalctl -k --since today | grep -i 'killed process'
```

`free -h` should show free or available memory left at your busiest time.

## Frequently asked questions

### Why did the OOM killer pick my database and not something else?

The kernel scores processes mainly by how much memory they use, so the biggest one usually goes first. Lower its settings or protect it with `OOMScoreAdjust`.

### Can I turn the OOM killer off?

Not safely. Without it, a server that runs out of memory hangs. Fix the memory use instead.

### When should I upgrade instead?

When your programs, at sensible settings, still use more RAM than you have at normal load. Compare `free -h` at peak times with your plan's RAM.

## Related guides

> [card] [VPS and dedicated server guides](https://help.freakhosting.com/portals/other/vps-and-dedicated-server-guides.md)
>
> Every guide in this section.

> [card] [Check memory usage](https://help.freakhosting.com/portals/other/how-to-check-memory-usage-on-linux.md)
>
> Read free, top and htop.

> [card] [Add swap space](https://help.freakhosting.com/portals/other/how-to-add-swap-space-on-linux.md)
>
> Overflow space for RAM spikes.

> [card] [Limit CPU and memory](https://help.freakhosting.com/portals/other/how-to-limit-cpu-and-memory-for-a-process.md)
>
> Cap one service's resources.

> [card] [High load on a Linux server](https://help.freakhosting.com/portals/other/how-to-fix-high-load-on-a-linux-server.md)
>
> When the server is slow, not killed.

***

> [!NOTE]
>
> **Checked against the official [Linux kernel memory management documentation](https://docs.kernel.org/admin-guide/mm/concepts.html) and the systemd [systemd.exec manual](https://www.freedesktop.org/software/systemd/man/latest/systemd.exec.html) (`OOMScoreAdjust=`)** on 4 November 2026; an OOM kill was reproduced in a 64 MB memory cgroup on Ubuntu 24.04 LTS and the kernel log lines were checked. The systemd override and the service log lines were not tested, because systemd doesn't run in our test container.

> [!NOTE]
>
> ### Need Extra Help?
>
> If you encounter any issues, our support team is ready to assist:
>
> * **Live Chat:** Quick assistance via our website.
> * **Support Ticket:** [Open a Ticket](https://freakhosting.com/clientarea/submitticket.php)
> * **Discord:** [Join our Community](https://discord.gg/freakhosting)
> * **Email:** [support@freakhosting.com](mailto:support@freakhosting.com)

> [!TIP]
>
> ### Save on Your Hosting
>
> Ready to upgrade your hosting? Use code **KB20** at checkout for **20% off** your first order!

***

**Last Updated:** November 2026


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.