10+ “vmstat” Command
Usage Examples in Linux
----------------------------------------------
This tutorial
explains Linux “vmstat” command, options and its usage with examples.
vmstat – Virtual
Memory Statistics
Description:
vmstat command is
used to report virtual memory statistics. vmstat reports information about
processes, memory, paging, block IO, traps, and cpu activity.
Synopsis:
vmstat [-a] [-n]
[-t] [-S unit] [delay [ count]] vmstat [-s] [-n] [-S unit] vmstat [-m] [-n]
[delay [ count]] vmstat [-d] [-n] [delay [ count]] vmstat [-p disk partition]
[-n] [delay [ count]] vmstat [-f] vmstat [-V]
OPTIONS:
-a
switch displays
active/inactive memory, given a 2.5.41 kernel or better.
-f
switch displays the
number of forks since boot. This includes the fork, vfork, and clone system
calls, and is equivalent to the total number of tasks created. Each process is
represented by one or more tasks, depending on thread usage. This display does not
repeat.
-t
switch adds
timestamp to the output.
-m
switch displays
slabinfo.
-n
switch causes the
header to be displayed only once rather than periodically.
-s
switch displays a
table of various event counters and memory statistics. This display does not
repeat.
delay
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.
If no count is specified and delay is defined, count defaults to infinity.
-d
reports disk
statistics (2.5.70 or above required)
-w
enlarges field width
for big memory sizes
-p
followed by some
partition name for detailed statistics (2.5.70 or above required)
-S
followed by k or K
or m or M switches outputs between 1000, 1024, 1000000, or 1048576 bytes
-V
switch results in
displaying version information.
Examples:
1) Simple example
along-with field descriptions
------------------------------------------------
$ vmstat
procs
-----------memory---------- ---swap-- -----io---- --system-- -----cpu------
r
b swpd free
buff cache si
so bi bo
in cs us sy id wa st
0 0
305416 260688 29160 2356920 2 2 4
1 0 0
6 1 92 2 0
Field Description
For Vm Mode
-------------------------------
Procs
r: The number of
processes waiting for run time.
b: The number of
processes in uninterruptible sleep.
Memory
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.
inact: the amount of
inactive memory. (-a option)
active: the amount
of active memory. (-a option)
Swap
si: Amount of memory
swapped in from disk (/s).
so: Amount of memory
swapped to disk (/s).
IO
bi: Blocks received
from a block device (blocks/s).
bo: Blocks sent to a
block device (blocks/s).
System
in: The number of
interrupts per second, including the clock.
cs: The number of
context switches per second.
CPU
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, included in idle.
st: Time stolen from
a virtual machine. Prior to Linux 2.6.11, unknown.
2) To execute every
2 seconds for 10 times, do the following.
You don’t need to
press Ctrl-C in this case. After executing 10 times,
it will stop
automatically.
-------------------------------------------------------------
$ vmstat 2 10
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 537144 182736
6789320 0 0
0 0 1
1 0 0 100
0 0
0
0 0 537004 182736
6789320 0 0
0 0 50 32
0 0 100 0 0
..
3) Using vmstat,
this next command will grep the memory and give a good overview of the memory
used in the computer.
-------------------------------------------------------------
$ vmstat -s -S M |
grep mem
5965 M total memory
5136 M used memory
3580 M active memory
1176 M inactive
memory
829 M free memory
474 M buffer memory
4) 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
procs
-----------memory---------- ---swap-- -----io---- --system-- -----cpu------
r
b swpd free
inact active si so
bi bo in
cs us sy id wa st
0 0
305416 253820 1052680 2688928 2 2
4 1 0
0 6 1 92
2 0
5) 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
81651975 forks
6) 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 100
procs
-----------memory---------- ---swap-- -----io---- --system-- -----cpu------
---timestamp---
r
b swpd free
buff cache si
so bi bo
in cs us sy id wa st
0
0 0 3608728 148368
3898200 0 0
0 0 1
1 0 0 100
0 0 2011-07-09 21:16:28 PDT
0
0 0 3608728 148368
3898200 0 0
0 0 60
15 0 0 100
0 0 2011-07-09 21:16:29 PDT
0
0 0 3608712 148368
3898200 0 0
0 0 32
28 0 0 100
0 0 2011-07-09 21:16:30 PDT
7) Display slab info
--------------------
Use option -m, to
display the slab info as shown below.
$ vmstat -m
Cache Num Total
Size Pages
fib6_nodes 5 113
32 113
ip6_dst_cache 4 15
256 15
ndisc_cache 1 15
256 15
RAWv6 7 10
768 5
UDPv6 0 0
640 6
tw_sock_TCPv6 0 0
128 30
...
8) Display
statistics in a table format
----------------------------------------
Instead of displays
the values in the record format, you can display the output of vmstat in table
format using option -s as shown below.
$ vmstat -s
4149928
total memory
3864824
used memory
2606664
active memory
1098180
inactive memory
285104
free memory
19264
buffer memory
2326692
swap cache
4192956
total swap
274872
used swap
3918084
free swap
1032454000 non-nice user cpu ticks
14568 nice user cpu ticks
89482270 system cpu ticks
16674327143 idle cpu ticks
368965706 IO-wait cpu ticks
1180468 IRQ cpu ticks
..
9) 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 153189971 69093708 2719150864 737822879
329617713 157559204 3965687592 4068577985
0 1102243
sdb 501426305 97099356 2345472425 731613156
419220973 533565961 2661869460 1825174087
0 1510434
sdc 884213459 22078974 513390701 452540172
127474901 8993357 2411187300 2133226954
0 1569758
10) Changing width
of output
The default output
without increasing the width is shown below.
-------------------------------------------------------------
$ vmstat 1 3
procs
-----------memory---------- ---swap-- -----io---- --system-- -----cpu-----
r
b swpd free
buff cache si
so bi bo
in cs us sy id wa st
0
0 0 3608688 148368
3898204 0 0
0 0 1
1 0 0 100
0 0
0
0 0 3608804 148368
3898204 0 0
0 0 72
30 0 0 100
0 0
0
0 0 3608804 148368
3898204 0 0
0 0 60
27 0 0 100
0 0
Use option -w to
increase the width of the output columns as shown below. This give better
readability.
$ vmstat -w 1 3
procs
-------------------memory------------------ ---swap-- -----io---- --system--
-----cpu-------
r
b swpd free buff
cache si so
bi bo in
cs us sy id wa st
0
0 0 3608712
148368 3898204 0
0 0 0
1 1 0 0
100 0
0
0
0 0 3608712
148368 3898204 0
0 0 0
93 23 0 0
100 0
0
0
0 0 3608696
148368 3898204 0
0 0 0
35 34 0 0
100 0
0
11) 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 sdb1
sdb1 reads read sectors
writes requested writes
501423248 2345417917 419221612 2661885948
12) Display in MB
---------------------
By default vmstat
displays the memory information in kb. To disply in MB, use the option “-S m”
as shown below.
$ 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
0
0 281 288
19 2386 0
0 4 1
0 0 6 1
92 2
0
No comments:
Post a Comment