A database, a game server or a script was running and is suddenly gone, without an error of its own. Very often Linux ended it because the memory was used up: the kernel then picks a large program and kills it, so that the rest of the server keeps working. This guide shows how to see whether that happened, which program uses the memory, and what to do about it.
The examples use Ubuntu 26.04 LTS. Run the commands as root, or put sudo in front of them.
1. Look for the Kill in the Log of the Kernel
journalctl -k --since "7 days ago" -g "out of memory"
Dec 02 04:09:45 server01 kernel: Memory cgroup out of memory: Killed process 3857 (python3) total-vm:80156kB, anon-rss:61220kB, file-rss:6940kB, shmem-rss:0kB, UID:0 pgtables:192kB oom_score_adj:0
- Killed process 3857 (python3): the number and the name of the program that was ended.
- anon-rss: the memory it held at that moment, here about 60 MB.
- A line that begins with Out of memory means that the whole server had no memory left. Memory cgroup out of memory, as in the example, means that the program reached a limit of its own, for example the memory limit of a container or of a service.
-- No entries --means that nothing was killed for lack of memory in this time. Look for another cause: Find Errors in the Logs of Your Linux Server: journalctl.
A program that you started yourself in the terminal ends with the single word Killed.
2. See How Much Memory There Is
free -h
total used free shared buff/cache available Mem: 15Gi 578Mi 13Gi 4.1Mi 798Mi 14Gi Swap: 4.0Gi 0B 4.0Gi
available is what programs can still get. buff/cache does not count as used: Linux gives it back at once when a program needs it. The line Swap is space on the disk that Linux uses when the memory is full; if its used value is large, the memory is too small for what runs.
3. See Which Programs Use the Most
ps -eo pid,rss,comm --sort=-rss | head
PID RSS COMMAND 2758 46140 fwupd 1661 45908 snapd 1765 33012 unattended-upgr
RSS is the memory of each program in kilobytes, the largest first. Run the command a few times while the server is busy. A program whose number only ever grows does not give memory back.
4. What to Do
| What you found | What to do |
|---|---|
| The program was killed once, during a peak | Start it again. Run it as a service that restarts by itself: Keep a Program Running on Linux. |
| One program grows until it is killed | Restart it regularly or update it, and tell its maker. Lower its own memory settings if it has any, for example the cache size of a database. |
| Several programs together need more than the server has | Run fewer of them at the same time, or move to a server with more memory. |
| The server has no swap, or the swap is full | Swap gives short peaks room. See Add Swap Space to Your Linux Server. |
| The log says Memory cgroup out of memory | The limit of the container or service is too low for the program. Raise it where it was set: in the settings of the container (Docker on Your Linux Server) or in the file of the service. |
Good to Know
- Linux does not ask. The killed program gets no chance to save its data. A database repairs itself at the next start, but a download or a calculation starts again from the beginning.
- The victim is not always the culprit. Linux ends a large program to free memory quickly, even if another program caused the shortage. Step 3 shows who really uses the memory.
- More about load and disk space: What Fills the Disk and What Loads the Server.