Detecting OOM Kills
# Check kernel log for OOM events
dmesg | grep -i "out of memory"
dmesg | grep -i "oom"
# Check system journal
journalctl -k | grep -i oomUnderstanding Memory Usage
# Overview
free -h
# Per-process memory usage
ps aux --sort=-%mem | head -15
# Detailed view
cat /proc/meminfoKey distinction: Linux uses free memory for disk caching. This is normal and healthy. Look at the "available" column in free -h, not "free".
Finding Memory Leaks
# Monitor a specific process over time
watch -n 5 "ps -o pid,vsz,rss,comm -p $(pgrep php-fpm | head -1)"
# VSZ = virtual memory, RSS = physical memory
# If RSS grows continuously without stopping, it is a memory leakImmediate Actions
# Find the most memory-hungry process
ps aux --sort=-%mem | head -5
# Restart it
sudo systemctl restart php8.2-fpm
# Clear filesystem cache (safe, non-destructive)
sync; echo 3 | sudo tee /proc/sys/vm/drop_cachesPrevention
- Set PHP-FPM
pm.max_requeststo recycle workers and prevent leaks - Configure MySQL
innodb_buffer_pool_sizeappropriately for available RAM - Add swap space as a safety net
- Set up monitoring alerts for memory usage above 85%