Vmstat is a very useful Linux system monitoring tool that uses the Vmstat command to get information about processes, memory, memory paging, blocking IO, traps, and CPU activity.
First, the preface
It is clear from the name that we can see that Vmstat is a tool for viewing virtual Memory usage, but how to find bottlenecks in the system through Vmstat. Before answering this question, let's review Linux about virtual memory related content.
Second, the virtual memory operation principle
Every process running in the system requires memory, but not every process needs to use the system-allocated memory space all the time. When the system is running with more memory than actual physical memory, the kernel releases some or all of the physical memory occupied by some processes but not used, stores this part of the data on disk until the process is next called, and supplies the freed memory to the required process.
In Linux memory management, it is mainly through "paging paging" and "swap swapping" to complete the above memory scheduling. The paging algorithm is to swap pages in memory that are infrequently used to disk, leaving the active page in memory for the process to use. Exchange technology is the entire process, not part of the page, all switched to disk.
The process of paging (page) writing to disk is called Page-out, and Paging (page) back to memory from disk is called page-in. A paging error (page Fault) occurs when the kernel needs a paging, but finds that the page is not in physical memory (because it has been page-out).
When the system kernel discovers that running memory becomes smaller, it releases some of the physical memory through Page-out. Managing Page-out does not happen frequently, but if the page-out occurs frequently, the system will drop dramatically when the kernel manages paging more than the time it takes to run the program. The system is already running very slow or in a paused state, which is also called thrashing (bump).
Iii. Use of Vmstat
1. Usage
Vmstat [-A] [-n] [-S] [delay [count]]
Vmstat [-S] [-n] [-s]
Vmstat [M] [-n] [delay [count]]
Vmstat [-d] [-n] [delay [count]]
Vmstat [-P disk partition] [-n] [delay [count]]
Vmstat [F]
Vmstat [-v]
-A: Show active and inactive memory
-F: Displays the number of fork since the system started. Extended reading: http://www.cnblogs.com/leoo2sk/archive/2009/12/11/talk-about-fork-in-linux.html
-M: Show Slabinfo
-N: Displays the field names only once at the beginning.
-S: Displays memory-related statistics and a variety of system activity quantities.
Delay: Refresh time interval. If not specified, only one result is displayed.
Count: Number of refreshes. If you do not specify a refresh count, but the refresh interval is specified, the refresh count is infinite.
-D: Displays disk-related statistics.
-P: Display specified disk partition statistics
-S: Display with specified units. The parameters are K, K, M, and M, representing 1000, 1024, 1000000, 1048576 bytes (byte) respectively. The default unit is K (1024 bytes)
-V: Displays Vmstat version information.
2. Instructions for use
Example 1: Output one result every 2 seconds
Field Description:
Procs (Process):
R: Number of processes in run queue
B: Number of processes waiting for IO
Memory (memory):
SWPD: Using virtual memory size
Free: Available memory size
Buff: Memory size used as buffering
Cache: The amount of memory used for caching
Swap:
Si: The size of memory written from the swap area per second
So: the memory size of the swap area written per second
IO: (now the size of the Linux version block is 1024bytes)
BI: Number of blocks read per second
Bo: Number of blocks written per second
System:
In: Number of interrupts per second, including clock interrupts.
CS: The number of context switches per second.
CPU (expressed as a percentage):
US: User Process Execution Time
SY: System Process Execution time
ID: Idle time (including IO wait time)
WA: Wait io time
Example 2: Show active and inactive memory
When using the-a option to display active and inactive memory, the displayed content is the same as example 1 in addition to adding inact and active.
Field Description:
Memory (memory):
Inact: Inactive memory Size (displayed when the-a option is used)
Active: Active memory size (displayed when the-a option is used)