Home / Guides

Server guide

Linux out of memory: why the OOM killer kills your process

When Linux runs out of memory, it kills a process to survive. It is often your database or PHP, and it often happens at the worst time.

2 min readUpdated November 2026 by the RootManage teamWorks on Ubuntu, Debian, AlmaLinux and Rocky unless noted

The short answer

Confirm the OOM kills in the kernel log, find what uses the memory, cap the biggest users, add swap as a safety net and add RAM if the work really needs it.

Confirm it

terminal
sudo dmesg -T | grep -i -E "out of memory|killed process"
sudo journalctl -k | grep -i oom

The line names the process that was killed and how much memory it used. A service that restarts for no clear reason is often an OOM victim.

See who uses memory

terminal
free -h
ps aux --sort=-%mem | head -n 12

Check the biggest users: database, PHP-FPM workers, Java apps, caches, Docker containers.

Common fixes

  • PHP-FPM: lower pm.max_children so the workers fit in RAM. Each worker can use tens or hundreds of MB.
  • MySQL or MariaDB: check innodb_buffer_pool_size and the number of connections.
  • Caches and Redis: set a memory limit.
  • One heavy job (a backup or an import): run it at a quiet time, with lower priority.
  • Containers: set memory limits so one cannot take the whole server.

Add swap as a safety net

terminal
sudo fallocate -l 2G /swapfile
sudo chmod 600 /swapfile
sudo mkswap /swapfile
sudo swapon /swapfile

Add it to /etc/fstab to keep it after a reboot. Swap is slow, so it prevents a crash but does not cure a real shortage.

When you simply need more RAM

If the memory is used for real work and the settings are sane, move to a bigger server. Check how memory use looks over a week, not one minute.

Watch it

Alert when free memory and swap stay low. A health agent can show memory over time and warn before the OOM killer acts.

Questions people ask

Is swap bad for a server?

A little swap is a good safety net. Constant heavy swapping means you need more RAM or a better setup.

Why does the OOM killer pick my database?

It picks the process with the highest score, usually the biggest one. You can protect a service with systemd settings, but fixing the memory use is better.

Do I need to reboot?

Not usually. Restart the killed service and fix the cause.

Want a person to look at it?

Tell us what you see. We reply with what we think is wrong and what it would take to fix it.