What the message looks like
Out of memory: Killed process 2314 (php-fpm8.3) total-vm:812344kB, anon-rss:402112kB, file-rss:0kB, shmem-rss:20480kB, UID:33 pgtables:1240kB oom_score_adj:0Common causes
- Too many PHP-FPM workers or database buffers for the available RAM.
- A memory leak in an application that grows over hours.
- No or too little swap, so load spikes are not absorbed.
- cgroup limit (
MemoryMax, Docker--memory) reached – then “Memory cgroup out of memory”. - One-off jobs like backups, imports or image processing need a lot of memory briefly.
Check
- Find OOM events in the kernel log
- Show free memory and swap
free -h; swapon --show - Show processes using the most memory
ps -eo pid,user,rss,comm --sort=-rss | head -n 10 - Show the memory limits of the affected service
systemctl show php8.3-fpm.service -p MemoryMax -p MemoryCurrent -p OOMPolicy
Fix
- Match
pm.max_childrento RAM: available memory divided by average worker size. - Limit database buffers, e.g.
innodb_buffer_pool_sizeto fit the rest of the system. - Add some swap so short spikes do not cause an immediate kill.
- Protect critical services with
OOMScoreAdjust=-500in the unit, cap non-critical ones withMemoryMax. - Monitor memory usage over time to spot leaks early.
Typical scenario
A VPS with 2 GB RAM runs nginx, PHP-FPM with pm.max_children = 50 and MariaDB. During a traffic spike at night the database vanishes, and the journal says 'Out of memory: Killed process … (mariadbd)'. The victim was not the culprit; the PHP workers had consumed the memory. First add up with ps -C php-fpm8.3 -o rss= | awk '{s+=$1} END {print s/1024 " MB"}' how much memory all workers occupy together and compare it with the free RAM.
FAQ
Why was the database killed although PHP used the memory?
The OOM killer picks by size and oom_score_adj, not by who caused it. Large services like MariaDB are therefore often hit first.
Does disabling overcommit help?
Rarely. With vm.overcommit_memory=2 applications fail when allocating instead. Better set per-service limits and match usage to RAM.
Why is another process often killed than the one at fault?
The kernel picks based on a score that mainly rates a process's memory use. Large, long-lived processes such as databases score badly. The real consumer, many small workers, goes unnoticed.
How do I calculate a sensible pm.max_children?
RAM available to PHP divided by the average size of one worker. From 2 GB subtract the operating system, database and cache. At 80 MB per worker and 1 GB for PHP, about twelve workers are realistic. More workers raise the risk, not the performance.
Does swap help against the OOM killer?
Swap gives breathing room and delays the intervention, but makes the system very slow under lasting shortage. It does not replace limiting the workers. Important services can also be made less of a target with OOMScoreAdjust= in the systemd unit.