Linux Monitoring Tools Vmstat command Detailed

Source: Internet
Author: User

The relationship between virtual memory and swap partitions

First, these two concepts correspond to Windows and Linux respectively, namely:
Windows: Virtual memory
Linux:swap partition

Windows uses virtual memory even when physical memory is not exhausted, while Linux does not use virtual memory (that is, swap partitions) only when physical memory is exhausted

Swap is similar to Windows virtual memory, except that Windows can be set under any of the drive characters in Windows, by default in the C drive, and with system files in a single partition. While Linux is a separate partition, convenient due to insufficient memory requirements, a portion of the content in the swap partition, to be kept free of the situation to continue to execute, also known as swap partition, swap space is part of the
The virtual memory of Windows is automatically set by the computer
The swap partition for Linux is good for you when you install the system.



First, preface

Obviously, from the name, we know that Vmstat is a tool for viewing virtual memory usage, but how can you find bottlenecks in the system through Vmstat? Before answering this question, let's review the virtual memory-related content in Linux.

Second, the principle of virtual memory

Each process running in the system needs to use memory, but not every process needs to use the system's allocated memory space every moment. When the system is running more memory than the actual physical memory, the kernel frees some or all of the physical memory that some processes occupy but unused, stores that data on disk until the next call to the process, and provides the freed memory for use by the required process.

In the Linux memory management, mainly through "paging paging" and "exchange swapping" to complete the above memory scheduling. Paging algorithm is to swap the most recently used pages in memory to disk, leaving the active page in memory for the process to use. The switching technique is to swap the entire process, not some pages, 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. Paging error (page Fault) occurs when the kernel needs a paging, but finds that the paging is not in physical memory (because it has been page-out).

When the system kernel discovers that it is running out of memory, it releases a portion of the physical memory through Page-out. Operating page-out is not a frequent occurrence, but if the page-out occurs frequently, the system's performance will drop sharply until the kernel manages paging more than the time the program is running. At this point the system is already running very slowly or going into a paused state, which is also known as thrashing (bump).

Three, Vmstat detailed

1. Usage

Vmstat [-A] [-n] [-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]

-A: Show active and inactive memory

- F: Displays the number of fork from the system since it was started.

- m: display Slabinfo

- N: Displays the field names only once at the beginning.

- S: displays memory-related statistics and the number of system activities.

delay: Refresh time interval. If not specified, only one result is displayed.

Count: number of refreshes. If you do not specify the number of refreshes, but the refresh interval is specified, the number of refreshes is infinite.

- D: displays disk-related statistics.

- P: display specified disk partition statistics

- S: displayed using the specified units. The parameters are K, K, M, M, respectively, representing 1000, 1024, 1000000, 1048576 bytes (byte). The default unit is K (1024x768 bytes)

- V: displays Vmstat version information.
2. Instructions for use

Example 1: Output a result every 3 seconds

Field Description:

Procs (Process):

R: The number of processes running in the queue, this value can also determine whether to increase the CPU. (longer than 1)
B: Number of processes waiting for IO

Memory (RAM):

SWPD: Using virtual memory size

Note: If the value of SWPD is not 0, but the Si,so value is 0 long, this situation does not affect system performance.
Free: idle physical memory size
Buff: The amount of memory used as a buffer
Cache: The amount of memory used as a buffer

Note: If the cache value is large, it indicates that there are many files in the cache, and if the files that are accessed frequently can be located in the cache, then the disk's read IO bi will be very small.

Swap:

Si: Writes from swap to memory size per second, disk into memory
So: The amount of memory written to the swap area per second, which is transferred from memory to disk

Note: When memory is sufficient, these 2 values are 0, and if these 2 values are longer than 0 o'clock, system performance will be affected and both disk IO and CPU resources will be consumed. Some friends see that free memory is very small or close to 0 o'clock, think that memory is not enough, not to see this, but also to combine SI and so, if it is very small, but Si and so are very few (mostly 0), then do not worry, the system performance will not be affected.

IO: (the size of the current Linux version block is 1kb)

BI: Number of blocks read per second
Bo: Number of blocks written per second

Note: When the random disk reads and writes, these 2 values are larger (such as exceeding 1024k), you can see the CPU in the IO waiting value will be greater.

System:

In: Number of interrupts per second, including clock interrupts.
CS: The number of context switches per second.

Note: The larger the 2 values above, the greater the CPU time that is consumed by the kernel.

CPU (expressed as a percentage):

US: Percentage of user Process Execution time

Note: When the value of us is higher, it indicates that the user process consumes more CPU time, but if it is used over a long period of 50%, then we should consider optimizing the program algorithm or accelerating it.

Sy: Percentage of kernel system Process Execution (System time)

Note: When the value of SY is high, it indicates that the system kernel consumes more CPU resources, which is not a benign performance, we should check the cause.

Wa:io Wait Time percentage

Note: When the value of WA is high, the IO wait is more severe, which may be caused by random access to the disk, or it may be a bottleneck (block operation) of the disk.

ID: Percentage of idle time

Example 2: Show active and inactive memory

When you use the-a option to display both active and inactive memory, the displayed content is the same as example 1 except for adding inact and active.

Field Description:

Memory (RAM):

Inact: Inactive memory Size (displayed when the-a option is used)
Active: Active memory size (displayed when the-a option is used)

Summarize:

For now, the metrics that are useful for server monitoring include:

R (Run queue)
Pi (page import)
US (user CPU)
Sy (System CPU)
ID (Idle)
Note: If R is often greater than 4 and the ID is often less than 40, it indicates that the CPU is heavily loaded. If the Bi,bo is not equal to 0 for a long time, it indicates insufficient memory.

Identify CPU bottlenecks with Vmstat:
R (Run queue) shows the number of tasks that are executing and waiting for CPU resources. When this value exceeds the number of CPUs, there is a CPU bottleneck.

Commands to view the number of CPU cores under Linux:
cat /proc/cpuinfo|grep processor|wc -l

When the R value exceeds the number of CPUs, there will be CPU bottlenecks, the solution is broadly several:

1. The simplest is to increase the number of CPUs and the number of cores
2. Balance system tasks by adjusting task execution times, such as when large tasks are put to the system for no busy operation
3. Adjust priority of existing tasks

Identify CPU full load with Vmstat:

The first thing to declare is that the CPU metric in Vmstat is a percentage. When the value of Us+sy is close to 100, it means that the CPU is nearing full-load operation. It is important to note, however, that theCPU workload does not explain anything, and Linux always tries to maximize the throughput of the task by making the CPU as busy as possible. The only value that can determine the CPU bottleneck is the R (running queue).

Identify Ram bottlenecks with Vmstat:

The database server has only limited RAM, and memory contention is a common problem for Oracle.

First, use free to view the amount of RAM:
[[email protected] ~]$ free
Total used free shared buffers Cached
mem:2074924 2071112 3812 0 40616 1598656
-/+ buffers/cache:431840 1643084
swap:3068404 195804 2872600

When the demand for memory is greater than the amount of RAM, the server initiates a virtual memory mechanism through which the RAM segment can be moved to a special disk segment of swap disk, where the page export and page import of virtual memory occur, and page export does not indicate a ram bottleneck. The virtual memory system often makes page exports to the memory segment, but the page import operation indicates that the server needs more memory, and the page import needs to copy the memory segment from swap disk back to RAM, causing the server to become slower.

There are several ways to solve this problem:

1. The simplest, increase the RAM;
2. Reduce the need for RAM by changing the SGA;
3. Reduce the need for RAM. (e.g., reduction of PGA)

Reference Documentation:

Http://hi.baidu.com/imlidapeng/blog/item/51872329329ab8335243c1c9.html

http://qa.taobao.com/?p=2269


Linux Monitoring Tools Vmstat command Detailed

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.