free — Memory and Swap Usage
free provides a fast snapshot of RAM and swap usage. Use it when your WordPress site feels slow, when PHP-FPM or MariaDB is getting killed by the OOM killer, or when you want to confirm whether the VPS has enough available memory for peak traffic. The most important column for day-to-day troubleshooting is usually available, not free.
Start with free -h and focus on available (RAM you can use without heavy swapping). If swap is growing and available is near zero, you're under memory pressure.
Reading the Output (Mental Model)
total -> total installed memory
used -> memory in use (includes some cache depending on mode)
free -> unused memory (often small on healthy Linux systems)
buff/cache -> filesystem cache/buffers
available -> best estimate of memory available for new apps
swap used -> swapping indicates memory pressure
Prerequisites
free is provided by procps/procps-ng and is installed by default on most Linux servers.
Verify it exists:
which free
free --version
Core Syntax
free [OPTIONS]
Key Options
| Option | What it does | Example | WordPress / VPS use case |
|---|---|---|---|
-h, --human | Human-readable sizes | free -h | Fast interactive checks |
-m, --mebi | Show in MiB | free -m | Consistent units for tickets |
-g, --gibi | Show in GiB | free -g | High-level planning |
-w, --wide | Wide output (more detail) | free -h -w | Better signal on buffers/cache |
-t, --total | Add RAM+swap totals | free -h -t | Quick "overall pressure" view |
-s N | Repeat every N seconds | free -h -s 2 | Watch memory during load |
-c N | Stop after N repeats | free -h -s 2 -c 5 | Bounded sampling |
-L | Print on a single line | free -h -L | Logging / monitoring output |
-v | Show committed memory | free -h -v | Check overcommit behavior |
Examples (Commands + Expected Output)
Values depend on traffic and active services. Use the patterns, not the exact numbers.
Basic output
free
Expected output:
total used free shared buff/cache available
Mem: 2048000 900000 100000 20000 1048000 900000
Swap: 1048576 20000 1028576
Use case: Quick raw snapshot.
Human-readable output
free -h
Expected output:
total used free shared buff/cache available
Mem: 2.0G 900M 100M 20M 1.0G 900M
Swap: 1.0G 20M 1.0G
Use case: Fast troubleshooting during incidents.
Wide output (more accurate breakdown)
free -h -w
Expected output:
total used free shared buffers cache available
Mem: 2.0G 700M 120M 20M 60M 1.1G 900M
Swap: 1.0G 20M 1.0G
Use case: Better visibility into cache/buffer behavior.
Include totals for RAM + swap
free -h -t
Expected output:
total used free shared buff/cache available
Mem: 2.0G 900M 100M 20M 1.0G 900M
Swap: 1.0G 20M 1.0G
Total: 3.0G 920M 1.1G
Use case: A single view of overall memory pressure.
Sample memory over time
free -h -s 2 -c 3
Expected output:
total used free shared buff/cache available
Mem: 2.0G 900M 100M 20M 1.0G 900M
Swap: 1.0G 20M 1.0G
total used free shared buff/cache available
Mem: 2.0G 950M 80M 20M 1.0G 850M
Swap: 1.0G 40M 1.0G
Use case: Observe memory changes during a load test or backup job.
Single-line output for logging
free -h -L
Expected output:
Mem: 2.0G 900M 100M 20M 1.0G 900M Swap: 1.0G 20M 1.0G
Use case: Store a compact record in logs.
WordPress VPS Use Cases
| Symptom | What to check | Command | What to look for |
|---|---|---|---|
| Random 502/504 errors | Memory pressure | free -h | Low available, swap growing |
| PHP processes killed | OOM risk | free -h -t | RAM nearly exhausted |
| Slow admin/dashboard | Background tasks | free -h -s 2 -c 5 | Memory dipping during cron jobs |
| Capacity planning | Baseline usage | free -h | Compare baseline to peak |
Troubleshooting
| Confusion / problem | Explanation | What to do |
|---|---|---|
| "free memory is low" | Linux uses RAM for cache; this is normal | Focus on available |
| Swap used is non-zero | Swap can be used even on healthy systems | Watch if swap keeps increasing |
| Site slows under load | Memory pressure leads to swapping | Confirm with free + vmstat |
Best Practices
- Look at
available, not justfree. - If swap is growing during normal traffic, investigate long-running processes (
top/htop). - Pair
freewithvmstat 1to confirm whether the system is actively swapping.
Cheat Sheet
free
free -h
free -h -w
free -h -t
free -m
free -h -s 2 -c 5
free -h -L
free -h -v