Understanding the Error
System has no available memory for new process/request.
Check Memory Status
free -h
cat /proc/meminfo
sudo dmesg | tail -20 | grep -i "out of memory"
Fix 1: Kill Memory-Hogging Processes
# Find top memory users
ps aux --sort=-%mem | head -10
# Kill process
sudo kill -9 PID
Fix 2: Add Swap Space
# Create 2GB swap
sudo fallocate -l 2G /swapfile
sudo chmod 600 /swapfile
sudo mkswap /swapfile
sudo swapon /swapfile
# Make permanent
echo "/swapfile none swap sw 0 0" | sudo tee -a /etc/fstab
Fix 3: Enable Overcommit Memory
sudo sysctl -w vm.overcommit_memory=1
sudo sysctl -w vm.overcommit_ratio=90
echo "vm.overcommit_memory=1" >> /etc/sysctl.conf
Fix 4: Reduce Application Memory Usage
- PHP: Lower memory_limit
- MySQL: Reduce buffer pool
- Apache: Reduce MaxClients
- Node.js: Use --max-old-space-size
Fix 5: Clear Caches
sudo sync && echo 3 > /proc/sys/vm/drop_caches
Fix 6: Check for Memory Leak
# Monitor over time
watch -n 5 "ps aux --sort=-%mem | head -5"
# If memory grows continuously, find and fix leak
Prevent Future Issues
# Monitor memory alerts
0 * * * * free -h | awk 'NR==2{if($7<200) system("echo Low memory | mail -s Alert admin@example.com")}'