Fix out-of-memory error on a server
We'll confirm memory with free -h, check dmesg for OOM killer activity, identify the cause, add swap or tune limits—or tell you when to escalate.
What you'll need
- SSH or console access with sudo
Step-by-step diagnostic
Quick triage — pick your path
Get started
Choose the option that matches what you see. You can jump straight to that section.
Show full guide
Steps
Goal: Confirm memory state, check OOM killer activity, and fix or escalate.
- Run
free -hto confirm memory and swap usage. Rundmesg | grep -i oomorjournalctl -k | grep -i oomto see OOM killer messages. - Good: You see memory state and which process was killed. Proceed to Check memory and OOM.
- Bad: No OOM in dmesg—check the exact error message; it may be a different issue.
Check memory and OOM
Goal: Understand current memory state and OOM killer activity.
- Run
free -h. Check Mem (available) and Swap (used, total). When Mem available is near zero and Swap is full or absent, the system hit memory exhaustion. - Run
dmesg | grep -i oomorjournalctl -k | grep -i oom. The OOM killer logs which process it killed. Note the process name and PID. - Good: You know memory state and the victim process. Proceed to Add swap or limit processes.
- Bad: Run
dmesg | tail -100to see recent kernel messages.
Add swap or limit processes
Goal: Add swap if missing, or restart and limit leaky processes.
- Run
swapon --show. If swap is absent or too small:sudo fallocate -l 2G /swapfile,sudo chmod 600 /swapfile,sudo mkswap /swapfile,sudo swapon /swapfile. Add/swapfile none swap sw 0 0to /etc/fstab. - When a single process leaks:
sudo systemctl restart servicename. For long-term: setMemoryMaxin the systemd unit. - When swap thrashing causes slowness:
sudo sysctl vm.swappiness=10. Add to /etc/sysctl.conf to persist. - Good: Swap added or process restarted. Check
free -hto confirm headroom. - Bad: OOM kills continue—see When to escalate.
When to escalate
Escalate if:
- OOM kills continue after adding swap and limiting processes.
- You cannot add swap (e.g. no disk space).
- The workload needs more physical RAM.
Provide free -h and dmesg | grep -i oom (or journalctl OOM output) before escalating.
Verification
free -hshows Mem available and Swap headroom.dmesg | grep -i oomshows no new OOM kills (or fewer after changes).- Applications run without being killed.
Escalation ladder
Work from the device outward. Stop when the problem is fixed.
- Check memory and OOM Run free -h and dmesg | grep -i oom.
- Add swap fallocate, mkswap, swapon; add to fstab.
- Restart or limit Restart leaky services; set MemoryMax in systemd.
- Tune swappiness Lower vm.swappiness to reduce thrashing.
- Escalate Provide free -h and dmesg OOM output; consider add RAM.
What to capture if you need help
Before calling support or posting for help, have these ready. It speeds everything up.
- free -h output
- dmesg or journalctl OOM messages
- swapon --show output
- Steps already tried
Did you see an OOM error or process killed?
Check dmesg | grep -i oom or journalctl -k | grep -i oom.
You can change your answer later.
Check the exact error
Is swap absent or too small?
Run free -h and swapon --show.
You can change your answer later.
Add swap file
Is a single process leaking?
ps aux --sort=-%mem | head -20
You can change your answer later.
Restart or limit the process
Escalate
Reviewed by Blackbox Atlas
Frequently asked questions
- What causes out-of-memory errors on a server?
- RAM and swap exhausted. Too many processes, a memory leak, or insufficient swap. The kernel OOM killer selects a process to kill to free memory. Check free -h and dmesg.
- How do I see OOM killer activity?
- Run dmesg | grep -i oom or journalctl -k | grep -i oom. The kernel logs which process was killed and why.
- When should I escalate OOM errors?
- If OOM kills continue after adding swap and limiting processes, or you need to add physical RAM. Provide free -h and dmesg OOM output.
Rate this guide
Was this helpful?
Thanks for your feedback.