teal/s %vmeff
03:20:01 PM 6.22 3.99 93.05 0.04 22.89 0.00 0.00 0.00 0.00
Average: 6.22 3.99 93.05 0.04 22.89 0.00 0.00 0.00 0.00
[root@localhost ~]# sar -B 2 3
Linux 2.6.32-504.el6.i686 (localhost.localdomain) 10/01/2015 _i686_ (1 CPU)
03:24:05 PM pgpgin/s pgpgout/s fault/s majflt/s pgfree/s pgscank/s pgscand/s pgsteal/s %vmeff
03:24:07 PM 0.00 0.00 26.63 0.00 30.15 0.00 0.00 0.00 0.00
03:24:09 PM 0.00 0.00 19.70 0.00 30.30 0.00 0.00 0.00 0.00
03:24:11 PM 0.00 0.00 15.00 0.00 30.00 0.00 0.00 0.00 0.00
Average: 0.00 0.00 20.44 0.00 30.15 0.00 0.00 0.00 0.00
?
?
sar -B 取的是从系统启动到目前的平均值;sar -B 2 3 是指每隔2秒取值,总共取值3次。输出字段的含义如下:
-B Report paging statistics. Some of the metrics below are available only with post 2.5
kernels. The following values are displayed:
pgpgin/s
Total number of kilobytes the system paged in from disk per second. Note: With
old kernels (2.2.x) this value is a number of blocks per second (and not kilo-
bytes).
pgpgout/s
Total number of kilobytes the system paged out to disk per second. Note: With
old kernels (2.2.x) this value is a number of blocks per second (and not kilo-
bytes).
fault/s
Number of page faults (major + minor) made by the system per second. This is
not a count of page faults that generate I/O, because some page faults can be
resolved without I/O.
majflt/s
Number of major faults the system has made per second, those which have
required loading a memory page from disk.
pgfree/s
Number of pages placed on the free list by the system per second.
pgscank/s
Number of pages scanned by the kswapd daemon per second.
pgscand/s
Number of pages scanned directly per second.
pgsteal/s
Number of pages the system has reclaimed from cache (pagecache and swapcache)
per second to satisfy its memory demands.
%vmeff
Calculated as pgsteal / pgscan, this is a metric of the efficiency of page
reclaim. If it is near 100% then almost every page coming off the tail of the
inactive list is being reaped. If it gets too low (e.g. less than 30%) then the
virtual memory is having some difficulty. This field is displayed as zero if
no pages have been scanned during the interval of time.
?
pgpgout/s 表示就是每秒的page out 的KB数量。majflt/s 也是极为重要的指标,该指标涉及到虚拟内存的 page fault机制。
?
虚拟内存的 page fault机制:
?
linux 使用虚拟内存层来映射物理地址空间,这种映射在某种意义上是说当一个进程开始运行,内核仅仅映射其需要的那部分,内核首先会搜索 CPU缓存和物理内存,如果没有找到内核则开始一次 MPF, 一次 MPF 即是一次对磁盘子系统的请求,它将数据页从磁盘和缓存读入 RAM。一旦内存页被映射到高速缓冲区,内核便会试图使用这些页,被称作 MnPF,MnPF 通过重复使用内存页而缩短了内核时间。
?
文件缓冲区(disk cache)可使内核减少对 MPFs 和 MnPFs 的使用, 随着系统不断地 IO 操作, 缓冲区会随之增大, 直至内存空闲空间不足并开始回收.
?
使用 free 查看空闲内存:
[root@localhost ~]# free
total used free shared buffers cached
Mem: 1030548 630284 400264 220 55388 82428
-/+ buffers/cache: 492468 538080
Swap: 1048572 0 1048572
[root@localhost ~]# free -m
total used free shared buffers cached
Mem: 1006 616 390 0 54 80
-/+ buffers/cache: 481 524
Swap: 1023 0 1023
?
?
1g的内存,1g的swap分区,使用了616M,空闲390M; swap分区没有被使用,全部空闲。
?
其实free内存很小不能说明问题,但是free比较大,却能说明内存充足。
?
swap如果大部分被使用,或者全部使用也能说明 swap 严重,当然最好结合 vmstat 来综合考虑。
?
使用 ?ps -mp 1959 -o THREAD,pmem,rss,vsz,tid,pid 查看mysqld的内存和CPU使用情况:
[root@localhost ~]# pidof -s mysqld
1959
[root@localhost ~]# ps -mp 1959 -o THREAD,pmem,rss,vsz,tid,pid
USER %CPU PRI SCNT WCHAN USER SYSTEM %MEM RSS VSZ TID PID
mysql 0.6 - - - - - 42.8 441212 752744 - 1959
mysql 0.1 19 - - - - - - - 1959 -
mysql 0.0 19 - - - - - - - 1962 -
mysql 0.