Smart Systems for Home

Plain how-to guides for smart home, security and home Wi-Fi

Find What's Using All Memory on a Small VPS

· 5 min read · Home Tech

In this article
  1. What You'll Need
  2. Step-by-Step
  3. Common Mistakes
  4. Tips
  5. Troubleshooting
  6. Frequently Asked Questions

This guide shows you how to pinpoint which processes are consuming memory on a small VPS, so you can decide whether to kill a runaway process, adjust an application, or upgrade your plan. You'll use standard Linux commands that work on most distributions (Ubuntu, Debian, CentOS, etc.). No prior experience is needed, but you should have SSH access to your server.

What You'll Need

  • SSH access to your VPS (username and password or SSH key).
  • Basic familiarity with the command line (typing commands and reading output).
  • Root or sudo privileges (to view all processes and free memory).

Step-by-Step

  1. Log in to your VPS. Open a terminal (on Windows, use PowerShell or PuTTY) and run: ssh user@your-server-ip. Replace user with your username and your-server-ip with your server's IP address.
  2. Check overall memory usage. Run free -h. This shows total, used, and available memory in human-readable format (e.g., 1.9G). Note the "available" column – it's the best indicator of how much memory is actually free for new processes.
  3. List processes sorted by memory usage. Run ps aux --sort=-%mem. This lists all running processes, sorted from highest to lowest memory percentage. The %MEM column shows the percentage of total RAM each process uses. The RSS column shows the actual memory in kilobytes (divide by 1024 to get MB).
  4. Identify the top memory consumers. Look at the first 10-15 lines. Focus on processes with high %MEM or RSS. Common culprits on a small VPS include: MySQL/MariaDB, Apache/Nginx, PHP-FPM, Node.js, Java, or a runaway script like a WordPress cron job.
  5. Get more detail on a specific process. Note the PID (second column). Run ps -p PID -o pid,user,cmd,%mem,rss to see the full command line and exact memory usage. For example: ps -p 1234 -o pid,user,cmd,%mem,rss.
  6. Check memory usage in real time. Run top (or htop if installed). This shows a live-updating list of processes. Press M to sort by memory usage. Press q to exit.
  7. Investigate the process. Use systemctl status PID (if it's a systemd service) or ls -l /proc/PID/cwd to see the working directory. This helps you identify what application the process belongs to.
  8. Decide what to do. If it's a service you don't need, stop it permanently: sudo systemctl disable --now service-name. If it's a temporary process, you can kill it with sudo kill -9 PID (use with caution). If it's a legitimate service, consider adjusting its configuration to use less memory (e.g., reduce PHP-FPM workers, MySQL buffer pool size).
  9. Monitor after action. Run free -h again to confirm memory is freed. If memory usage climbs again, the issue may be a memory leak or a service that needs tuning.

Common Mistakes

  • Misreading the free output. On Linux, "used" memory includes cache/buffers. The "available" column is what matters; it accounts for reclaimable cache. Don't panic if "used" is high – it's normal.
  • Killing a critical system process. Always verify what the process is before killing it. Killing sshd or systemd can lock you out or crash the server.
  • Ignoring swap usage. If your server is using swap heavily, it's a sign of memory pressure. Check with free -h; if the swap column is high, you need to free up RAM or add more.
  • Forgetting about cached memory. Linux uses free RAM for caching files. This is not a problem; it's a feature. Your "available" memory will be lower than "free" but that's fine.

Tips

  • Use htop if available. It's more user-friendly than top and allows you to kill processes with F9. Install it with sudo apt install htop (Debian/Ubuntu) or sudo yum install htop (CentOS).
  • Check for memory leaks. If a process's memory usage grows over time, it may be leaking. Use watch -n 5 'ps -p PID -o rss' to monitor it.
  • Look at logs. Check /var/log/syslog or /var/log/messages for OOM (Out of Memory) killer messages. The OOM killer kills processes when memory is exhausted; logs will show which process was killed.
  • Consider using a process manager. Tools like PM2 (for Node.js) or Supervisor can automatically restart services that crash due to memory issues.

Troubleshooting

  • If free shows low available memory but no process is using much: This could be due to kernel memory or slab cache. Run cat /proc/meminfo and look at Slab and SReclaimable. If they're huge, it's often due to a filesystem cache. Try echo 3 > /proc/sys/vm/drop_caches (as root) to drop caches temporarily.
  • If you can't log in because the server is unresponsive: Your VPS provider likely has a web console (e.g., VNC) that you can use to log in. From there, run the commands above. If the server is completely frozen, you may need to reboot from the provider's panel.
  • If a process you killed comes back: It's likely a service managed by systemd or a supervisor. Disable it with sudo systemctl disable service-name or stop the supervisor.
  • If memory usage is still high after killing processes: Check for zombie processes (state Z in ps). These are processes that have finished but haven't been cleaned up by their parent. You can't kill them, but they don't use memory. If they accumulate, it's a bug in the parent process.

Frequently Asked Questions

What is the difference between used and available memory in free -h?

Used memory includes memory used by processes and also memory used for caching and buffers. Available memory is the amount that can be allocated to new processes without swapping. It's the more reliable number to watch.

Why does my VPS show 1.9G total but only 1.5G available?

The kernel reserves some memory for its own use, and some memory is used for hardware reservations. This is normal; you can't use 100% of the RAM.

How can I see memory usage per user?

Run ps aux --sort=-%mem | awk '{print $1}' | sort | uniq -c to count processes per user, or use top and press u to filter by user.

What is the OOM killer and how do I know if it's active?

The OOM killer is a kernel feature that kills processes when memory is exhausted. Check dmesg | grep -i oom or journalctl -k | grep -i oom to see if it has been triggered.

Can I increase swap to fix memory issues?

Yes, adding swap can help, but it's not a substitute for enough RAM. Swap is much slower than RAM and can cause high load. It's better to reduce memory usage or upgrade your VPS.

Is it safe to kill a process with kill -9?

It's safe for user processes, but it doesn't allow the process to clean up. It can cause data loss or corruption for databases. Prefer kill (SIGTERM) first, and only use -9 if the process doesn't respond.