Linux 使用 vmstat 查看虚拟内存状态

Linux vmstat 诊断工具 About 2,958 words

介绍

vmstat(Virtual Memory Statistics虚拟内存统计) 命令用来显示Linux系统虚拟内存状态。

常用命令

vmstat

打印当前vm信息

[root@root ~]$ 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  0 704784 2889756 366676 8683336    0    0     0     4    0    0  1  1 98  0  0

vmstat 2 20

每隔两秒打印一次,共打印20

[root@root ~]$ 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
 3  0 704784 2859332 366840 8712436    0    0     0     4    0    0  1  1 98  0  0    
 3  0 704784 2857896 366840 8713560    0    0     0     0 10898 16823 15  2 83  0  0    
11  0 704784 2857856 366844 8713564    0    0     0     6 2909 2659 12  1 88  0  0    
 3  0 704784 2855784 366844 8714872    0    0     0  1176 14089 24199 34  4 62  0  0    
 5  0 704784 2856032 366844 8715212    0    0     0     0 8492 12366 15  2 83  0  0    
 2  0 704784 2854672 366848 8716184    0    0     0     6 9962 12163 13  2 85  0  0    
 1  0 704784 2854244 366852 8716188    0    0     0   754 6612 8334 13  2 86  0  0    
 3  0 704784 2854232 366852 8717012    0    0     0     0 19148 33322 40  4 55  0  0    
 2  0 704784 2853380 366856 8718296    0    0     0  1070 3888 4656  9  1 90  0  0    
 1  0 704784 2852692 366856 8719324    0    0     0     0 5191 6966 10  1 90  0  0

参数

  • procs 进程
    • r:运行队列中进程数量。进程数越多,意味着CPU非常繁忙。如果该参数长期大于和等于逻辑cpu个数,则CPU资源可能存在较大的瓶颈。
    • b:被阻塞进程数量。主要是指被资源阻塞的进程对列数(比如IO资源、页面调度等),当这个值较大时,需要根据应用程序来进行分析,比如数据库产品,中间件应用等。
  • memory 内存
    • swpd:使用虚拟内存大小,如果swpd的值不为0,但是SI,SO的值长期为0,这种情况不会影响系统性能。
    • free:空闲物理内存大小。
    • buff:用作缓冲的内存大小。
    • cache:用作缓存的内存大小,如果cache的值大的时候,说明cache处的文件数多,如果频繁访问到的文件都能被cache处,那么磁盘的读IO bi会非常小。
  • swap 交换区
    • si:每秒从交换区写到内存的大小,由磁盘调入内存。
    • so:每秒写入交换区的内存大小,由内存调入磁盘。
    • 注意:内存够用的时候,这2个值都是0,如果这2个值长期大于0时,系统性能会受到影响,磁盘IO和CPU资源都会被消耗。不能光看空闲内存(free)很少或接近于0时,就认为内存不够用了,还要结合si和so,如果free很少,但是si和so也很少(大多时候是0),那么不用担心,系统性能这时不会受到影响的。因为Linux总是先把内存用光。
  • io 读写
    • bi:每秒读取的块数。
    • bo:每秒写入的块数。
  • system 系统
    • in:每秒中断数,包括时钟中断。
    • cs:每秒上下文切换数。
  • cpu
    • us:用户进程执行时间百分比(user time) us的值比较高时,说明用户进程消耗的CPU时间多,但是如果长期超50%的使用,那么就该考虑优化程序算法或者进行加速。
    • sy:内核系统进程执行时间百分比(system time) sy的值高时,说明系统内核消耗的CPU资源多,这并不是良性表现,应该检查原因。
    • wa:IO等待时间百分比wa的值高时,说明IO等待比较严重,这可能由于磁盘大量作随机访问造成,也有可能磁盘出现瓶颈(块操作)。
    • id:空闲时间百分比。

帮助文档

usage: vmstat [-V] [-n] [delay [count]]
              -V prints version.
              -n causes the headers not to be reprinted regularly.
              -a print inactive/active page stats.
              -d prints disk statistics
              -D prints disk table
              -p prints disk partition statistics
              -s prints vm table
              -m prints slabinfo
              -t add timestamp to output
              -S unit size
              delay is the delay between updates in seconds. 
              unit size k:1000 K:1024 m:1000000 M:1048576 (default is K)
              count is the number of updates.
Views: 6,384 · Posted: 2019-09-03

————        END        ————

Give me a Star, Thanks:)

https://github.com/fendoudebb/LiteNote

扫描下方二维码关注公众号和小程序↓↓↓

扫描下方二维码关注公众号和小程序↓↓↓


Today On History
Browsing Refresh