free — Check memory usage
💬 "free command"
free shows memory and swap usage. The available value is the indicator used to judge actual available memory.
buff/cache is reclaimable, so a low free value can still be fine.
- total: Total physical memory.
- used: Memory used by processes.
- free: Completely unused memory. This value alone is misleading.
- available: An estimate of what a new process can use, so look at this value.
Commonly used options
| Option | Description |
|---|---|
| -h | Output in human-readable units |
| -m / -g | Output in MB / GB units |
| -s <seconds> | Repeat output every specified number of seconds |
| -t | Add a total line |
3 essential command combinations
free -h— Check current memory status (most basic)free -h -s 5— Repeat every 5 seconds to check trendsfree -m | awk 'NR==2{print $7}'— Extract the available value for monitoring
💬 "Show me just one example of checking a long-running server"
Here are situations commonly encountered on real production servers, organized in order.
Step 1 · Current status
Check available memory and swap usage.
free -h
Step 2 · Check trends
Use repeated output to see the decreasing trend.
free -h -s 5
Step 3 · Identify the cause
Find processes using a lot of memory.
ps -eo pid,%mem,rss,comm --sort=-%mem | head
How it is used in practice
1. OOM prevention check
Situation — Processes keep dying because memory is low.
free -h && dmesg -T | grep -i oom | tail -3
Result — If available is very low and swap usage is high, the system is short on memory.
Point — Review application memory limits (php-fpm pm.max_children, etc.) or scale the server.
2. Don't panic over cache
Situation — free was nearly 0, so it was mistaken for a failure.
free -h
Result — Confirm that buff/cache accounts for a large portion and that available is sufficient.
Point — Linux uses spare memory as cache, so judge by available.
Important notes
- A low free value does not immediately mean memory is short. Use available as the basis.
- Heavy swap usage sharply degrades performance (increased iowait).
- In container environments, host memory and cgroup limits differ, so be careful.
Actual output
This is the result of checking memory and swap usage.
!free command output: memory and swap usage
An actual production server
Source (HTML): https://games.aidebatehub.com/programs/linux/services/free.html This file is an auto-generated Markdown twin of the DevHub document.
AI Knowledge Hub
Visitor Comments