Linux vmstat Command

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)
  • sectors: Number of sectors read/written
  • ms: Milliseconds spent on I/O operations
  • cur: Current I/O operations in progress
  • Use case: Identify which disk is bottleneck

Example 6: Partition-Specific Statistics

vmstat -p sda1
sda1 reads read sectors writes requested writes 23450 1234567 45678 3456789
Explanation:

Shows statistics for a specific disk partition.

  • -p partition: Focus on single partition
  • reads: Number of read operations
  • read sectors: Sectors read from partition
  • writes: Number of write operations
  • requested writes: Write requests to partition
  • Use case: Monitor specific volume or mount point

Example 7: Display Timestamps with Statistics

vmstat -t 3 5
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
  • Memory breakdown: Total, used, free, active, inactive
  • CPU ticks: Time spent in different states
  • Pages: Memory paging activity
  • System events: Interrupts, context switches, forks
  • Use case: System overview, baseline establishment

Example 10: Monitor System Under Load

vmstat 1 10 | tee vmstat_load_test.txt
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 4 0 0 987654 156500 2048500 0 0 450 1200 1200 3400 45 15 35 5 0 8 1 0 876543 156550 2049000 0 0 890 2400 2100 5600 65 20 10 5 0 12 2 512 765432 156600 2049500 0 128 1200 3600 3500 7800 75 18 2 5 0 15 3 2048 654321 156650 2050000 64 256 1500 4800 4200 9200 80 15 0 5 0 18 4 5120 543210 156700 2050500 128 384 1800 6000 5100 11000 82 13 0 5 0 16 3 5120 556789 156750 2051000 0 0 1600 5200 4800 10500 79 16 0 5 0 10 2 5120 678901 156800 2051500 0 0 1100 3800 3900 8900 68 17 8 7 0 6 1 5120 789012 156850 2052000 0 0 780 2600 2800 6500 52 18 22 8 0 3 0 5120 890123 156900 2052500 0 0 450 1400 1600 3800 35 12 45 8 0
Explanation:

Monitors system during a load test, showing performance degradation and recovery.

  • Pattern observed: System goes from idle to heavily loaded
  • r increases: 1 → 18 runnable processes (CPU saturation)
  • b increases: 0 → 4 blocked processes (I/O bottleneck)
  • Swap activity: si/so show memory pressure forcing swap use
  • I/O spikes: bi/bo show heavy disk activity
  • CPU usage: id drops from 78% to 0% (fully utilized)
  • Recovery: Last lines show system returning to normal
  • tee command: Saves output while displaying it
Performance Issues Identified:
  • High 'r' value (>CPU count) = CPU bottleneck
  • Non-zero 'si'/'so' = Memory pressure requiring swap
  • High 'b' value = I/O bottleneck with blocked processes
  • High 'wa' value = Processes waiting for disk I/O

Additional Information

Command Options

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

Common Use Cases

Best Practices

Example: Long-term Monitoring Script

#!/bin/bash # vmstat_monitor.sh - Continuous monitoring with log rotation LOGDIR="/var/log/performance" LOGFILE="$LOGDIR/vmstat_$(date +%Y%m%d).log" mkdir -p $LOGDIR echo "=== vmstat monitoring started at $(date) ===" >> $LOGFILE vmstat -t -w 60 >> $LOGFILE 2>&1 & # Save PID for later stopping echo $! > /var/run/vmstat_monitor.pid

Troubleshooting Scenarios

# Scenario 1: System feels slow $ vmstat 1 10 # Look for: High 'r', high 'wa', or swap activity # Scenario 2: Check if memory is causing swapping $ vmstat -S M 2 20 # Look for: Non-zero 'si' and 'so' values # Scenario 3: Identify disk bottleneck $ vmstat -d # Compare across disks for highest I/O # Scenario 4: Monitor specific workload $ vmstat -t 1 > workload_test.log & # Run workload $ kill %1 # Stop vmstat when done

Performance Thresholds (General Guidelines)

Warning Thresholds:
  • r > 2x CPU cores: Severe CPU contention
  • b > 5: Significant I/O bottleneck
  • wa > 20%: I/O wait becoming problematic
  • si/so > 0: Memory pressure causing swap
  • free < 5% total: Low memory (but cache is reclaimable)

Note: Thresholds vary by workload and system configuration

Pro Tip: Create a simple performance dashboard:
watch -n 2 'vmstat 1 2 | tail -1'

This refreshes the screen every 2 seconds with current statistics, perfect for real-time monitoring during troubleshooting.