Is your server running slow? One of the most common causes is a shortage of Random Access Memory (RAM), forcing the system to use the much slower disk swap.
Here are the best tools to diagnose memory issues on your Linux VPS.
1. The Quick Check: free
The fastest way to see your total available memory is the free command. We recommend using the -h (human-readable) flag.
free -h
Understanding the output:
- Total: Your total physical RAM.
- Used: RAM actively used by processes.
- Available: The most important number! This is the actual RAM available for starting new applications (including buffers/cache).
- Swap: If the "Used" swap value is high, your server is out of RAM and is swapping to disk. This kills performance.
2. Detailed Process View: htop
To see exactly which program is eating your memory, we recommend htop. It is a colorful, interactive alternative to the standard top.
Installation:
# Ubuntu / Debian
apt install htop
# CentOS / AlmaLinux
dnf install htop
Usage:
htop
- Click on the column header MEM% to sort processes by memory usage.
- Press F10 to exit.
3. Legacy Method: top
If you cannot install htop, the standard top command is always available.
- Run
top. - Press Shift + M to sort the list by Memory usage.
4. Deep Dive: vmstat
If you suspect memory issues are causing disk I/O lag (thrashing), use vmstat.
vmstat 1 5
(This runs the check 5 times with a 1-second interval).
Look at the si (swap in) and so (swap out) columns. If these numbers are consistently high (non-zero), your server is actively swapping and needs more RAM.