Virtual Memory Statistics and System Performance Monitoring
Command Overview
vmstat (Virtual Memory Statistics) reports information about processes, memory, paging, block I/O, traps, disks, and CPU activity. It provides a snapshot of system performance and is one of the most important tools for diagnosing performance issues, identifying bottlenecks, and monitoring system resources over time.
Understanding vmstat Output Fields
Category
Field
Description
Procs
r
Number of runnable processes (running or waiting for CPU)
b
Number of processes in uninterruptible sleep (blocked)
Memory
swpd
Amount of virtual memory used (KB)
free
Amount of idle memory (KB)
buff
Memory used as buffers (KB)
cache
Memory used as cache (KB)
Swap
si
Swap in - memory swapped from disk (KB/s)
so
Swap out - memory swapped to disk (KB/s)
I/O
bi
Blocks received from block device (blocks/s)
bo
Blocks sent to block device (blocks/s)
System
in
Interrupts per second (including clock)
cs
Context switches per second
CPU
us
Time spent running user code (%)
sy
Time spent running kernel code (%)
id
Time spent idle (%)
wa
Time spent waiting for I/O (%)
st
Time stolen from VM (virtualized environment) (%)
Key Insight: High values in 'r' (runnable processes) indicate CPU pressure, while high 'wa' (I/O wait) suggests disk bottlenecks. Non-zero 'si' and 'so' indicate memory pressure requiring swap usage.
Example 1: Basic System Statistics Snapshot
vmstat
procs -----------memory---------- ---swap-- -----io---- -system-- ------cpu-----
r b swpd free buff cache si so bi bo in cs us sy id wa st
1 0 0 1024576 156432 2048000 0 0 45 120 450 980 15 5 78 2 0
Explanation:
Displays a single snapshot of current system statistics.
r: 1: One process waiting for CPU (normal)
b: 0: No blocked processes
swpd: 0: No swap space in use (good)
free: 1024576 KB: About 1GB free memory
cache: 2048000 KB: About 2GB used for cache
si/so: 0: No swap activity (healthy)
wa: 2%: Low I/O wait (good)
id: 78%: CPU mostly idle
Tip: The first line of vmstat output shows averages since system boot. Run with an interval to see real-time statistics.
Example 2: Continuous Monitoring with Intervals
vmstat 2 5
procs -----------memory---------- ---swap-- -----io---- -system-- ------cpu-----
r b swpd free buff cache si so bi bo in cs us sy id wa st
2 0 0 1024576 156432 2048000 0 0 45 120 450 980 15 5 78 2 0
1 0 0 1022340 156440 2049120 0 0 142 256 520 1120 18 6 75 1 0
0 0 0 1021890 156448 2050000 0 0 98 180 485 1050 16 5 77 2 0
1 0 0 1020450 156456 2051230 0 0 120 200 495 1080 17 5 76 2 0
2 0 0 1019870 156464 2052100 0 0 105 190 510 1095 19 6 73 2 0
Explanation:
Updates statistics every 2 seconds for 5 iterations.
2: Update interval in seconds
5: Number of updates (omit for continuous)
Pattern analysis: Watch for trends over time
First line: Shows averages since boot (ignore for current state)
Following lines: Real-time statistics
Use case: Monitor system during load tests or troubleshooting
Example 3: Memory Statistics in Megabytes
vmstat -S M
procs -----------memory---------- ---swap-- -----io---- -system-- ------cpu-----
r b swpd free buff cache si so bi bo in cs us sy id wa st
1 0 0 1000 152 2000 0 0 45 120 450 980 15 5 78 2 0
Explanation:
Displays memory values in megabytes instead of kilobytes.
-S M: Unit option (M=megabytes, k=kilobytes, K=1000 bytes)
free: 1000 M: 1000 MB (1 GB) free memory
cache: 2000 M: 2000 MB (2 GB) cache
Easier reading: More human-friendly for systems with lots of RAM
Use case: Quick assessment on high-memory systems
Example 4: Display Active and Inactive Memory
vmstat -a
procs -----------memory---------- ---swap-- -----io---- -system-- ------cpu-----
r b swpd free inact active si so bi bo in cs us sy id wa st
1 0 0 1024576 512000 1536000 0 0 45 120 450 980 15 5 78 2 0
Explanation:
Shows active and inactive memory instead of buffer and cache.
-a option: Display active/inactive memory columns
inact: Inactive memory (pages not recently used)
active: Active memory (pages in active use)
Memory management: Helps understand which memory can be reclaimed
Use case: Detailed memory pressure analysis
Example 5: Detailed Disk Statistics
vmstat -d
disk- ------------reads------------ ------------writes----------- -----IO------
total merged sectors ms total merged sectors ms cur sec
sda 45620 12340 2456890 34500 98760 45230 5678900 67800 0 120
sdb 12340 3450 456780 12300 23450 8900 789000 23400 0 45
nvme0n1 78900 23450 4567890 23400 156780 67890 9876543 45600 0 180
Explanation:
Displays detailed statistics for all disk devices.
-d option: Disk statistics mode
reads total: Total read operations completed
merged: Grouped I/O operations (higher is more efficient)
procs -----------memory---------- ---swap-- -----io---- -system-- ------cpu----- -----timestamp-----
r b swpd free buff cache si so bi bo in cs us sy id wa st
1 0 0 1024576 156432 2048000 0 0 45 120 450 980 15 5 78 2 0 2025-11-11 14:23:15
2 0 0 1022340 156440 2049120 0 0 142 256 520 1120 18 6 75 1 0 2025-11-11 14:23:18
1 0 0 1021890 156448 2050000 0 0 98 180 485 1050 16 5 77 2 0 2025-11-11 14:23:21
0 0 0 1020450 156456 2051230 0 0 120 200 495 1080 17 5 76 2 0 2025-11-11 14:23:24
1 0 0 1019870 156464 2052100 0 0 105 190 510 1095 19 6 73 2 0 2025-11-11 14:23:27
Explanation:
Adds timestamps to each line of output for correlation with events.
-t option: Append timestamp to each line
Format: YYYY-MM-DD HH:MM:SS
Logging: Essential for saving output to files
Correlation: Match performance issues with specific times
Use case: Production monitoring, incident investigation
Pro Tip: Combine with output redirection for long-term monitoring: vmstat -t 60 >> /var/log/vmstat.log &
Example 8: Wide Output Format
vmstat -w
procs -----------------------memory---------------------- ---swap-- -----io---- -system-- --------cpu--------
r b swpd free buff cache si so bi bo in cs us sy id wa st
1 0 0 1024576 156432 2048000 0 0 45 120 450 980 15 5 78 2 0
Explanation:
Uses wide output format with better spacing and alignment.
-w option: Wide mode for better readability
Column spacing: More space between columns
Alignment: Right-aligned numbers for easier comparison
Large values: Prevents number truncation on high-memory systems
Use case: High-resolution displays, detailed analysis
Example 9: Summary Statistics
vmstat -s
8165264 K total memory
6234560 K used memory
3456789 K active memory
2145678 K inactive memory
1930704 K free memory
156432 K buffer memory
2048568 K swap cache
4194300 K total swap
0 K used swap
4194300 K free swap
234567 non-nice user cpu ticks
5678 nice user cpu ticks
123456 system cpu ticks
1234567 idle cpu ticks
23456 IO-wait cpu ticks
456 IRQ cpu ticks
1234 softirq cpu ticks
0 stolen cpu ticks
5678901 pages paged in
8901234 pages paged out
0 pages swapped in
0 pages swapped out
45678901 interrupts
89012345 CPU context switches
1699999999 boot time
123456 forks
Explanation:
Displays comprehensive summary of system statistics since boot.
-s option: Summary mode with cumulative statistics
-S unit - Output unit (k=1000, K=1024, m=1000000, M=1048576)
-t - Append timestamp to each line
-w - Wide output mode (better readability)
-V - Display version information
Interpreting Results
Key Performance Indicators:
CPU Bound System:
- High 'r' value (> number of CPU cores)
- High 'us' or 'sy' percentages
- Low 'id' percentage
Memory Pressure:
- Non-zero 'si' and 'so' (swap in/out)
- Low 'free' with high 'swpd'
- Increasing swap usage over time
I/O Bottleneck:
- High 'b' value (blocked processes)
- High 'wa' percentage (I/O wait)
- High 'bi' and 'bo' values
Healthy System:
- Low 'r' and 'b' values
- Zero or minimal swap activity
- High 'id' percentage when not under load
- Low 'wa' percentage
Related Commands
top/htop - Interactive process monitoring
iostat - Detailed I/O statistics
mpstat - Per-CPU statistics
sar - System activity reporter (historical data)
free - Memory usage overview
ps - Process status
dstat - Versatile resource statistics tool
atop - Advanced system monitor
Common Use Cases
Performance baseline: Run vmstat during normal operations to establish baseline