vmstat reports information about processes, memory, paging, block IO, traps, disks and CPU activity. The output of vmstat command use to help identify system bottlenecks. Here are some commond examples:

Note: The first report produced gives averages since the last reboot. Additional reports give information on a sampling period of length delay. And, it doesn't count itself as a running process.

the examples were tested on RHEL7, kernel 3.10.0-327.28.2.el7.x86_64

$ vmstat -V
vmstat from procps-ng 3.3.10

Default output

# vmstat
procs -----------memory---------- ---swap-- -----io---- -system-- ------cpu-----
 r  b   swpd   free   buff  cache   si   so    bi    bo   in   cs us sy id wa st
 2  4  12280 170668    540 11053024    0    0   311   323    3    1  0  0 99  0  0

Where

  • The fist line shows six different categories.
  • The second line gives more information about each category.

Switch output unit

# 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
 7  0     11    162      0  10810    0    0   308   321    2    4  0  0 99  0  0

Where,

  • -S M: vmstat lets you choose units (k, K, m, M) default is K (1024 bytes).

Output Field Description For Vm Mode

(a) procs is the process-related fields are:

  • r: The number of processes waiting for run time.
  • b: The number of processes in uninterruptible sleep.

(b) memory is the memory-related fields are:

  • swpd: the amount of virtual memory used.
  • free: the amount of idle memory.
  • buff: the amount of memory used as buffers.
  • cache: the amount of memory used as cache.

(c) swap is swap-related fields are:

  • si: Amount of memory swapped in from disk (/s).
  • so: Amount of memory swapped to disk (/s).

(d) io is the I/O-related fields are:

  • bi: Blocks received from a block device (blocks/s).
  • bo: Blocks sent to a block device (blocks/s).

(e) system is the system-related fields are:

  • in: The number of interrupts per second, including the clock.
  • cs: The number of context switches per second.

(f) cpu is the CPU-related fields are:

These are percentages of total CPU time.

  • us: Time spent running non-kernel code. (user time, including nice time)
  • sy: Time spent running kernel code. (system time)
  • id: Time spent idle. Prior to Linux 2.5.41, this includes IO-wait time.
  • wa: Time spent waiting for IO. Prior to Linux 2.5.41, shown as zero.

Reports information in repeat mode

SYNOPSIS
       vmstat [options] [delay [count]]

The last two optional arguments can be used to generate repeat reports with specified length of intervals.

  delay  The delay between updates in seconds.  If no delay is specified, only one report is printed with the average values since boot.
  count  Number of updates.  In absence of count, when delay is defined, default is infinite.

For example collect data every 2 seconds (or collect data every 2 second 5 times only):

# vmstat -S M 2
OR
# 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
 1  4  12340 2801408    356 8454616    0    0   317   330    4    1  0  0 99  0  0
 5  1  12340 2037864    360 9219308    0    0 210766 70713 48316 155227 32 36 18 13  0
 6  0  12340 1698120    360 9559116    0    0 213202 79681 48781 149179 32 41 22  5  0
12  1  12340 1090016    364 10169032    0    0 152650 109849 38176 114467 34 28 19 19  0
 1  6  12340 304500    364 10952132    0    0 195146 212382 45587 145251 33 37 18 11  0

Note: As you see the first output produced gives averages data since the last reboot. Additional reports give information on a sampling period of length delay. You need to sample data using delays i.e. collect data by setting intervals.

vmstat – Display active and inactive memory

By default vmstat doesn’t display this information. Use option -a, to display active and inactive memory information as shown below.

$ vmstat -a 2 2
procs -----------memory---------- ---swap-- -----io---- -system-- ------cpu-----
 r  b   swpd   free  inact active   si   so    bi    bo   in   cs us sy id wa st
 5  0  17028 167896 6242484 9129768    0    0   346   358    2    3  0  0 99  0  0
 4  1  17028 181148 6185624 9172748    0    0 246168 72426 53921 157314 13 48 29 10  0

vmstat – Display number of forks since last boot

This displays all the fork system calls made by the system since the last boot. This displays all fork, vfork, and clone system call counts.

$ vmstat -f
      3081840 forks

 vmstat – Display timestamp

When you use vmstat to monitor the memory usage repeately, it would be nice to see the timestap along with every line item. Use option -t to display the time stamp as shown below.

$ vmstat -t 1 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                 PDT
 6  1 17100 183728 680 11101540 0 0   349   361    3    0  0  0 99  0  0 2016-09-19 13:52:17
 9  2 17100 171792 680 11112820 0 0 209172 105701 39958 147054 45 40 13  2  0 2016-09-19 13:52:18
 2  6 17100 167576 680 11116204 0 0 127308 201316 28400 95875 56 32  5  7  0 2016-09-19 13:52:19
16  0 17100 152568 676 11128796 0 0 71892 112261 17002 59072 65 20  3 13  0 2016-09-19 13:52:20
11  1 17100 159240 676 11118924 0 0 116588 100924 19562 79912 68 29  1  1  0 2016-09-19 13:52:21

vmstat – Display slab info

Use option -m, to display the slab info as shown below. Note it requires permissions

# vmstat -m
Cache                       Num  Total   Size  Pages
nfs_direct_cache              0      0    352     23
nfs_commit_data              23     23    704     23
...
kvm_vcpu                      0      0  16256      2
kvm_mmu_page_header           0      0    168     24
nfsd4_openowners              0      0    440     18
rpc_inode_cache             100    100    640     25
xfs_dqtrx                     0      0    528     31
...
scsi_cmd_cache              327    432    448     18
qla2xxx_srbs                850    850    320     25
kcopyd_job                    0      0   3312      9
dm_uevent                     0      0   2608     12
...
UDP                          64     64   1024     16
tw_sock_TCP                  96    160    256     16
TCP                         220    289   1920     17
blkdev_queue                154    225   2088     15
blkdev_requests            6040   7686    384     21
blkdev_ioc                  468    468    104     39
...
dentry                    31111  48699    192     21
iint_cache                    0      0     80     51
...
dma-kmalloc-2048              0      0   2048     16
...
kmalloc-192                3746   4158    192     21
kmalloc-128                6866   9088    128     32
kmalloc-96                 2189   3024     96     42
...
kmem_cache_node             320    320     64     64
kmem_cache                  144    144    256     16


vmstat – Display statistics

Display the output of vmstat in table format using option -s as shown below.

$ vmstat -s
     16268500 K total memory
      5047880 K used memory
      9237788 K active memory
      6116252 K inactive memory
       172972 K free memory
          520 K buffer memory
     11047128 K swap cache
      2097148 K total swap
        20348 K used swap
      2076800 K free swap
      4086222 non-nice user cpu ticks
        33130 nice user cpu ticks
      3501885 system cpu ticks
    887486064 idle cpu ticks
      2435043 IO-wait cpu ticks
            0 IRQ cpu ticks
       265405 softirq cpu ticks
            0 stolen cpu ticks
   3331246304 pages paged in
   3444384095 pages paged out
          259 pages swapped in
         5151 pages swapped out
   1576470688 interrupts
   3714146307 CPU context switches
   1472073294 boot time
      3109561 forks

vmstat – Display disk statistics

Use option -d to display the disk statistics as shown below. This displays the reads, writes, and I/O statistics of the disk.

$ vmstat -d
disk- ------------reads------------ ------------writes----------- -----IO------
       total merged sectors      ms  total merged sectors      ms    cur    sec
sda   189241    468 7255408  539645 1449729 123037 40513388 33026386      0    444
sdb      267      0    6878     269      0      0       0       0      0      0
sr0        0      0       0       0      0      0       0       0      0      0
sdc   851225      0 217468024 1335527 904738      0 454656603 82047045      0   2005

vmstat – Increase the width of the display

Use option -w to increase the width of the output columns as shown below. This give better readability.

$ vmstat -w 1 2
procs -------------memory--------------- ---swap-- -----io---- -system-- --------cpu--------
 r  b    swpd    free    buff      cache   si   so    bi    bo   in   cs  us  sy  id  wa  st
 3  0   20452  167460     720   11034000    0    0   374   387    4    4   0   0  99   0   0
 0  6   20452  170000     720   11024700    0    0 224716 131184 47388 143665  22  41  22  16   0

vmstat – Display summary statistics about disk activity

$ vmstat  -D
           54 disks
            7 partitions
     60691679 total reads
        13583 merged reads
  15203018154 read sectors
    203634789 milli reading
     31530618 writes
       528642 merged writes
  15684341854 written sectors
   2653498015 milli writing
            0 inprogress IO
        66080 milli spent IO

vmstat – Display statistics for a partition

To display the disk I/O statistics of a specific disk partition use option -p as shown below.

$ vmstat  -p sda1 2 3
sda1          reads   read sectors  writes    requested writes
                2823      42159       2275       6704
                2823      42159       2275       6704
                2823      42159       2275       6704