vmstat

  • Post author:
  • Post last modified:November 14, 2024
  • Reading time:6 mins read

The vmstat command prints the system virtual memory statistics for Linux and Unix systems. vmstat prints information about system processes, memory, swap, I/O blocks, interrupts and context switches and the CPU activity. The most common command format is,

vmstat [delay [count]]

The optional delay parameter tells the time interval between periodic vmstat outputs. If the count number is given, vmstat prints output count times and exits. If count is not given, vmstat prints output forever, or till the time you interrupt it with a control-C. For example,

$ vmstat 4 5
procs ----------memory---------- --swap-- ----io--- -system-- ----cpu----  
 r  b   swpd   free  buff  cache   si  so   bi   bo   in   cs us sy id wa
 1  0 816344  75968  2724  94612    8   8   35   18   11   49  8  2 89  1
 0  0 816332  78680  2744  94668    0   0    0   33 1430 2408 39  8 52  0  
 0  0 816324  79080  2752  94648    8   0    8   11  791 1537  5  2 93  1
 0  0 816284  78708  2760  94652    8   0    8    9  829 1306  4  2 94  0
 0  0 816236  78584  2768  94652   16   0   16    5  805 1559 10  2 88  1

We asked for 5 times of vmstat output, each after a delay of 4 seconds. So there are 5 lines of data in the output, each line giving the averages for the last 4 seconds. The first line gives the summary information since the system boot time. The procs columns give information about the processes in the system. The number under the r sub-column gives the number of processes that are ready to run. The b sub-column indicates the processes that are blocked in uninterruptible sleep. Then, we have the memory columns. The swpd column gives the amount of virtual memory used. The free column gives the amount of idle memory. The buff and the cache columns give the amount of memory used as buffers and cache respectively. All figures are in kilobytes, by default. Next, there are the swap columns. The si column gives the memory swapped in from the hard disk(s) in kilobytes per second. Similarly, so is the memory swapped out to disk(s), also in Kb/sec. Swapping indicates a memory bottleneck; since there is a shortage of main memory, the kernel has to make space by swapping out pages to hard disk to satisfy the requirement of memory from demanding processes. Next, there are the I/O columns under the heading io. The bi column gives the blocks received from block input devices per second. Similarly, the bo column indicates the blocks sent out to devices per second. Under the system column, the in sub-column gives the interrupts per second. This includes the clock interrupt. The cs sub-column gives the number of context switches per second. Then, there is the cpu column with four sub-columns. The us column gives the user time, the time the CPU has been working in the user mode, executing non-kernel code. The sy column is for the system time, when the CPU is working in the kernel mode, executing the kernel code. The id column indicates the CPU idle time and the wa column is for the time CPU has been waiting for the I/O.

Options

-a

The -a option displays the active and inactive memory columns. Active memory is the memory which has been used recently, whereas the inactive memory, allocated for some processes earlier, has not been used of late. For example,

$ vmstat -a 2 
procs -----------memory---------- ---swap-- -----io---- -system-- ----cpu----  
 r  b   swpd   free  inact active   si   so    bi    bo   in   cs us sy id wa
 1  0 787772  99252 379092 288488    8    8    38    18   56  126  8  2 88  1
 0  0 787760  99128 379092 288556    0    0     0     0  840 2649  7  2 92  0
 1  0 787760  99128 379092 288560    0    0     0     0  774 1592  5  2 94  0
 3  0 787756  99096 379096 289596    0    0     0    12 2824 6823 48 10 42  0  
 ....

-f

The -f option gives the number of forks since the system boot. This is the number of processes created since the time of boot. For example,

$ vmstat -f
        11106 forks
$ ps
  PID TTY          TIME CMD
 3903 pts/0    00:00:01 bash
11107 pts/0    00:00:00 ps

vmstat reports 11106 forks and the process id of the next process ps is 11107.

-S

By default, the memory figures are reported in the units of Kilobytes (1024 bytes). It is possible to change this to 1000, 1024, 1000000 or 1048576 bytes using k, K, m or M parameter respectively after the -S option. For example to get memory figures in megabytes,

vmstat -S M 2 4
procs -----------memory---------- ---swap-- -----io---- -system-- ----cpu----  
 r  b   swpd   free   buff  cache   si   so    bi    bo   in   cs us sy id wa  
 1  0    773     81      6    132    9    9    39    19   88   60  9  2 88  1
 0  0    773     81      6    132    0    0     0    36  910 1939 13  3 82  1  
 0  0    773     81      6    132    0    0     0     0  883 3197  7  3 90  0
 0  0    773     81      6    132    0    0     0    24  788 1603  4  3 92  1

The figures given under memory are only affected. The data under the swap or io columns is not affected

-p

The -p option, followed by a partition name, gives the statistics for that partition. For example,

$ vmstat -p /dev/sda3
sda3          reads   read sectors  writes    requested writes
              436726   19349941      43142    1284936

-s

The -s option prints the summary data for the system. For example,

$ vmstat -s
       960268 K total memory
       816984 K used memory
       260124 K active memory
       383400 K inactive memory
       143284 K free memory
         2720 K buffer memory
       120820 K swap cache
      2996116 K total swap
       845476 K used swap
      2150640 K free swap
      3112928 non-nice user cpu ticks
        22571 nice user cpu ticks
       813661 system cpu ticks
     31530824 idle cpu ticks
       475094 IO-wait cpu ticks
          309 IRQ cpu ticks
        18264 softirq cpu ticks
            0 stolen cpu ticks
     14124326 pages paged in
      6729681 pages paged out
       772468 pages swapped in
       784699 pages swapped out
    159151678 interrupts
    319674149 CPU context switches
   1332562573 boot time
        11564 forks

Karunesh Johri

Software developer, working with C and Linux.
0 0 votes
Article Rating
Subscribe
Notify of
guest
0 Comments
Newest
Oldest Most Voted
Inline Feedbacks
View all comments