Master Linux Performance: Deep Dive into top, free, and vmstat Commands
This guide thoroughly explains Linux performance monitoring commands—top, free, and vmstat—covering their syntax, key options, sample outputs, and detailed interpretation of CPU, memory, swap, and I/O statistics to help administrators diagnose system health.
1. top command
top is a common Linux performance analysis tool that shows real‑time resource usage of processes, similar to Windows Task Manager.
Usage: top [options] Options:
-b batch mode
-c show full command line
-I ignore idle processes
-s secure mode
-S cumulative mode
-i<seconds> set delay
-u<user> show only processes of a user
-p<pid> monitor specific PID
-n<count> number of iterations
Example – display process information: top Sample output (truncated) shows system time, uptime, load average, task counts, CPU states, memory usage, swap usage and a list of processes with columns PID, USER, PR, NI, VIRT, RES, SHR, S, %CPU, %MEM, TIME+, COMMAND.
Explanation of the first five lines:
Line 1 – current time, uptime, number of users, load average (1, 5, 15 min).
Line 2 – task summary: total, running, sleeping, stopped, zombie.
Line 3 – CPU states: %us (user), %sy (system), %ni (nice), %id (idle), %wa (IO wait), %hi (hardware IRQ), %si (software IRQ), %st (steal).
Line 4 – memory: total, used, free, buffers.
Line 5 – swap: total, used, free, cached.
Additional tips:
Press 1 to toggle per‑CPU view.
Press b to highlight the running process.
Press x to toggle column highlighting.
Use Shift > or Shift < to change the sort column (e.g., to %MEM).
2. free command
free displays the amount of free and used physical memory, swap space and kernel buffers.
Usage: free [options] Options:
-b display in bytes
-k display in kilobytes (default)
-m display in megabytes
-g display in gigabytes
-o omit the buffer/cache line
-s<seconds> continuously monitor
-t show total line (memory + swap)
-V show version
Example – show memory usage: free Typical output includes rows “Mem:” and “Swap:” with columns total, used, free, shared, buffers, cached, and a “-/+ buffers/cache” line that reflects memory available to applications.
Key points:
“used” in the first “Mem:” line counts kernel buffers and cache; the “-/+ buffers/cache” line subtracts them to show actual used/free memory for applications.
Available memory for an application can be approximated as free + buffers + cached.
When swap usage rises, the kernel is moving pages to disk, which may indicate insufficient RAM.
3. vmstat command
vmstat (Virtual Memory Statistics) reports statistics about processes, memory, paging, block I/O, traps and CPU activity.
Usage examples:
vmstat vmstat 5 5 vmstat -a 2 5 vmstat -f vmstat -s vmstat -dCommon options:
-a show active and inactive memory
-f display fork count since boot
-s display memory‑related statistics
-d display disk statistics
-m display slab cache information
-n suppress repeated header lines
-S<unit> set output unit (k, K, m, M)
-t show total memory line
-V show version
Output fields (first line of a typical run):
procs: r (running), b (blocked on I/O)
memory: swpd, free, buff, cache
swap: si (swap‑in), so (swap‑out)
io: bi (blocks in), bo (blocks out)
system: in (interrupts), cs (context switches)
cpu: us, sy, id, wa, st
Interpretation notes:
High r > 4 or id < 40 % indicates heavy CPU load.
Non‑zero si/so suggests memory pressure.
Non‑zero bi/bo with b > 3 points to I/O bottlenecks.
Additional examples: vmstat -f – shows total number of forks. vmstat -s – prints a list of memory statistics (total memory, used, free, buffers, cached, swap, page‑ins/outs, interrupts, context switches, etc.). vmstat -d – displays per‑device read/write statistics. vmstat -m – shows slab allocator caches.
Understanding these tools helps administrators monitor system health, detect CPU, memory or I/O saturation, and make informed tuning decisions.
Signed-in readers can open the original source through BestHub's protected redirect.
This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactand we will review it promptly.
Open Source Linux
Focused on sharing Linux/Unix content, covering fundamentals, system development, network programming, automation/operations, cloud computing, and related professional knowledge.
How this landed with the community
Was this worth your time?
0 Comments
Thoughtful readers leave field notes, pushback, and hard-won operational detail here.
