← Volver al blog

How to Fix “Out of Memory” Error in Linux

  • Xernode
  • 1 min de lectura
  • 3 de abril de 2026
Linux linux troubleshooting memory out of memory swap

Introduction

The “Out of Memory” (OOM) error in Linux can cause processes to crash or the server to become unresponsive. This guide shows you how to diagnose and fix OOM errors to keep your system stable.

Step-by-step Guide

  1. Check system logs for OOM events
    • dmesg | grep -i oomn
      • or
    • grep -i 'killed process' /var/log/syslog
  2. Check current memory and swap usage
    • free -h
  3. Identify memory-hungry processes
    • ps aux --sort=-%mem | head -10
  4. Add or increase swap space (if needed)
    • Create a 2GB swap file:n
      • sudo fallocate -l 2G /swapfile
      • sudo chmod 600 /swapfile
      • sudo mkswap /swapfile
      • sudo swapon /swapfile
    • Make it permanent:n
      • echo '/swapfile none swap sw 0 0' | sudo tee -a /etc/fstab
  5. Kill or restart problematic processes
    • sudo kill -9 PIDn
      • (Replace PID with the process ID from step 3)
  6. Optimize applications and services
    • Reduce memory usage in configs (e.g., lower PHP, MySQL, or Java memory limits).
    • Restart heavy services after clearing cache.
  7. Reboot the server if it’s unresponsive
    • sudo reboot

Recommendations

  • Monitor memory usage regularly with htop or free -h.
  • Set up swap space on all VPS with low RAM.
  • Optimize or upgrade applications that use excessive memory.
  • Consider upgrading your VPS if OOM errors persist.

Call To Action

eed more RAM or a more powerful VPS? Check out our hosting plans! https://xernode.com/#pricing

Related Guides