vmstat (Virtual Memory Statistics)
Table of Contents
1. vmstat
vmstat (virtual memory statistics) is a computer system monitoring tool that collects and displays summary information about operating system memory, processes, interrupts, paging and block I/O.
下面是运行 vmstat
的输出例子:
$ vmstat 1 6 # 1表示采集间隔为1秒,6表示共采集6次 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 4615096 3038056 38104728 0 0 2 32 5 4 6 1 92 0 0 1 0 0 4595820 3038056 38104728 0 0 0 8 6349 5219 17 25 58 0 0 3 0 0 4489904 3038056 38106224 0 0 0 308 4182 5663 61 13 25 0 0 3 0 0 4446832 3038056 38105612 0 0 0 460 3124 3228 78 13 9 0 0 2 0 0 4388312 3038056 38105612 0 0 0 4 3193 4439 88 12 0 0 0 2 0 0 4354088 3038056 38105612 0 0 0 0 2817 2873 77 5 18 0 0
默认地(不加参数时), vmstat
的输出信息分为了 6 组(procs/memory/swap/io/system/cpu),下面分别解释这 6 组报告:
(1) Procs
r: The number of processes waiting for CPU time. (r=running queue)
b: The number of processes in uninterruptible sleep. (b=blocked queue, waiting for resource (e.g. filesystem I/O blocked, inode lock))
Tip 1: 当 r
值大于系统中的 CPU 核数,则往往意味着“CPU 是性能瓶颈”。
Tip 2: b
值表示处于“uninterruptible sleep”状态下的进程数,一般在等待 I/O 时进程会处于“uninterruptible sleep”状态。 当 b
值比较大时,则往往意味着“磁盘是性能瓶颈”。 处于“uninterruptible sleep”状态下的进程,是无法用 kill -9
命令杀掉(因为它不会被信号中断)。处于“uninterruptible sleep”状态的进程在 ps
输出的 STAT 列会被标记为字母 D,如:
$ vmstat # 这个例子中有 2 个处于“uninterruptible sleep”状态下的进程 procs -----------memory---------- ---swap-- -----io---- -system-- ------cpu----- r b swpd free buff cache si so bi bo in cs us sy id wa st 0 2 0 189292 691572 10832264 0 0 144 137 0 0 6 0 93 1 0 $ ps aux | awk '$8 ~ /D/' # 查看所有处于“uninterruptible sleep”状态的进行 root 6708 0.0 0.0 0 0 ? D Oct29 0:03 [kworker/u8:3] root 18506 0.0 0.0 0 0 ? D Jun15 24:02 [jbd2/vdc1-8]
(2) 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.
Tips:上面 4 项内存相关输出在命令 free
的输出中都可以找到。
(3) Swap
si: Amount of memory swapped in from disk (/s). 每秒由内存进入内存交换区数量。
so: Amount of memory swapped to disk (/s). 每秒由内存交换区进入内存数量。
(4) IO
bi: Blocks received from (read) a block device (blocks/s). 每秒读磁盘的数据。
bo: Blocks sent to (write) a block device (blocks/s). 每秒写磁盘的数据。
(5) System
in: The number of interrupts per second, including the clock.
cs: The number of context switches per second.
(6) CPU
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.
参考:
https://linux.die.net/man/8/vmstat
https://www.thomas-krenn.com/en/wiki/Linux_Performance_Measurements_using_vmstat
http://nonfunctionaltestingtools.blogspot.jp/2013/03/vmstat-output-explained.html