Skip to main content

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.

Quick Summary

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)

free-output-mental-model.txt
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:

verify-free-installed.sh
which free
free --version

Core Syntax

free-syntax.sh
free [OPTIONS]

Key Options

OptionWhat it doesExampleWordPress / VPS use case
-h, --humanHuman-readable sizesfree -hFast interactive checks
-m, --mebiShow in MiBfree -mConsistent units for tickets
-g, --gibiShow in GiBfree -gHigh-level planning
-w, --wideWide output (more detail)free -h -wBetter signal on buffers/cache
-t, --totalAdd RAM+swap totalsfree -h -tQuick "overall pressure" view
-s NRepeat every N secondsfree -h -s 2Watch memory during load
-c NStop after N repeatsfree -h -s 2 -c 5Bounded sampling
-LPrint on a single linefree -h -LLogging / monitoring output
-vShow committed memoryfree -h -vCheck overcommit behavior

Examples (Commands + Expected Output)

Output varies

Values depend on traffic and active services. Use the patterns, not the exact numbers.

Basic output

free-basic.sh
free

Expected output:

example-output-free-basic.txt
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-human-readable.sh
free -h

Expected output:

example-output-free-h.txt
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-wide-output.sh
free -h -w

Expected output:

example-output-free-wide.txt
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-total-ram-plus-swap.sh
free -h -t

Expected output:

example-output-free-total.txt
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-sample-over-time.sh
free -h -s 2 -c 3

Expected output:

example-output-free-sampling.txt
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-single-line.sh
free -h -L

Expected output:

example-output-free-single-line.txt
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

SymptomWhat to checkCommandWhat to look for
Random 502/504 errorsMemory pressurefree -hLow available, swap growing
PHP processes killedOOM riskfree -h -tRAM nearly exhausted
Slow admin/dashboardBackground tasksfree -h -s 2 -c 5Memory dipping during cron jobs
Capacity planningBaseline usagefree -hCompare baseline to peak

Troubleshooting

Confusion / problemExplanationWhat to do
"free memory is low"Linux uses RAM for cache; this is normalFocus on available
Swap used is non-zeroSwap can be used even on healthy systemsWatch if swap keeps increasing
Site slows under loadMemory pressure leads to swappingConfirm with free + vmstat

Best Practices

  • Look at available, not just free.
  • If swap is growing during normal traffic, investigate long-running processes (top/htop).
  • Pair free with vmstat 1 to confirm whether the system is actively swapping.
Cheat Sheet
free-cheat-sheet.sh
free
free -h
free -h -w
free -h -t
free -m
free -h -s 2 -c 5
free -h -L
free -h -v

What's Next