One Linux command per day (--vmstat) command

Source: Internet
Author: User

Vmstat is an abbreviation for virtual memory Statistics, which monitors virtual memory, process, and CPU activity of the operating system. He is a statistical analysis of the overall situation of the system, and the disadvantage is that a process cannot be analyzed in depth. The Vmstat tool provides a low-overhead way to observe system performance. Because Vmstat itself is a low-overhead tool, you need to view and monitor the health of your system on very high-load servers, or you can output results with Vmstat in the control window. Before learning the Vmstat command, let's look at the information about physical memory and virtual memory in the Linux system.

Physical memory and virtual memory differences:

We know that reading and writing data directly from physical memory is much faster than reading and writing data from a hard disk, so we want all of the data read and written to be done in memory, and memory is limited, which leads to the concept of physical and virtual memory.

Physical memory is the size of the memory provided by the system hard disk, is the real memory, relative to the physical memory, under Linux there is a virtual memory concept, virtual memory is to meet the lack of physical memory of the proposed strategy, it is the use of disk space virtual out of a piece of logical memory, The disk space used as virtual memory is called swap space.

As an extension of physical memory, Linux will use the virtual memory of the swap partition when the physical memory is low, in more detail, the kernel will write the memory block information temporarily unused to the swap space, so that the physical memory is released, this memory can be used for other purposes, when the original content needs to be used, This information is re-read into the physical memory from the swap space.

Linux memory Management is a paging access mechanism, in order to ensure that the physical memory can be fully utilized, the kernel will be in the physical memory of infrequently used data blocks automatically swapped into virtual memory, and the information often used to retain the physical memory.

To learn more about Linux memory operating mechanisms, you need to know the following:

First of all, Linux for the page Exchange conditional, not all pages in the use of the virtual memory, the Linux kernel based on the "most commonly used" algorithm, only some infrequently used paging files to virtual memory, sometimes we see a phenomenon: Linux physical memory is still many, But the swap space is also used a lot. In fact, this is not surprising, for example, a very large memory of the process run, it takes a lot of memory resources, there will be some infrequently used paging file is swapped into virtual memory, but later this memory resource-intensive process ended and released a lot of memory, The page file that was swapped out is not automatically swapped into physical memory, unless it is necessary, then the system physical memory will be idle a lot at the moment, while the exchange of space is also being used, there is a phenomenon just said. Don't worry about that, just know what's going on.

Finally, the Swap space page will be swapped to physical memory first, if there is not enough physical memory to accommodate these pages, they will be swapped out immediately, so that the virtual memory may not have enough space to store these exchange pages, resulting in a fake Linux crash, service anomalies and other issues, Linux, although it can restore itself in a period of time, the system has been largely unusable.

Therefore, it is very important to plan and design the use of Linux memory rationally.

Virtual Memory principle:

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. Although page-out does not occur frequently, if page-out occurs frequently, it is known that when the kernel manages paging more than the running time, the system performance drops sharply. At this point the system is already running very slowly or going into a paused state, which is also known as thrashing (bump).

1. Command format:

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]

2. Command function:

Information that is used to display virtual memory

3. Command parameters:

-a displays active and inactive memory

-F shows the number of fork from system start to date

-M Display Slabinfo

-N Displays only one field name at the beginning

-S displays memory-related statistics and number of system activities

Delay refresh interval, if not specified, displays only one result

Count refreshes, if no refresh count is specified, but the refresh interval is specified, the number of refreshes is infinite

-D displays disk-related statistics

-P displays specified disk partition statistics

-S displays the specified units. Parameters are K, K, M, M,

-V Display Vmstat version information

4. Usage examples:

Example 1: Displaying virtual memory usage

Command: Vmstat

        

Field Description:

Procs (Process) Memory (RAM) Swap Io System Cpu
R: Number of processes in the running queue SWPD: Using virtual memory size Buff: The amount of memory used as a buffer Si: Write to memory size per second from swap area BI: Number of blocks read per second In: Number of interrupts per second, including clock interrupts US: User Process Execution Time ID: Idle time (including IO wait time), CPU idle time
B: Number of processes waiting for IO Free: Available memory size Cache: The amount of memory used as a buffer So: The amount of memory written to the swap area per second Bo: Number of blocks written per second SY: System Process Execution time WA: Waiting for IO time

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 PI, PO is not equal to 0 for a long time, indicates insufficient memory, if disk is often not equal to 0, and the queue in B is greater than 3, indicates that the IO performance is not good. With high stability and reliability, Linux is scalable and scalable, adapting to different application and hardware environments to optimize performance for the needs of current applications. Therefore, it is important for enterprises to understand the system performance analysis tools when they are maintaining the Linux system and tuning the systems.

Command:

Vmstat 5 5 means that 5 samples are sampled every 5 seconds. Will get a summary of the data he can reflect the real system situation.

Example 2: Displaying active and inactive memory

Command:

Vmstat-a 2 5

When you use the-a option to display active and inactive memory, the content displayed is the same as Example 1, in addition to increasing inactive (inactive memory size) and active (active memory size).

Example 3: See how many times the system has been forked

Command:

Vmstat-f This data is obtained from the processes field in the/proc/stat

Example 4: View details of memory usage

Command:

Vmstat-s This information is from/proc/meminfo,/proc/stat and/proc/vmstat

Example 5: View disk read/write

Command:

Vmstat-d

Description: This information is mainly from/proc/diskstats

Merged: Represents a write/read request that comes from a merge, and the general system merges multiple connections/neighboring read/write requests into one operation.

Example 6: Viewing the read/write of a/dev/sda1 disk

Command: Vmstat-p/dev/sda1

This information is mainly from the/proc/diskstats

reads: The number of reads from this partition.

Read sectors: Number of Read sectors from this partition

Writes the number of writes from this partition

Requested writes the number of write requests from this partition

Example 7: Viewing the system's slab information

Command:

Vmstat-m

This group of information comes from/proc/slabinfo

Slab because the kernel will have a lot of small objects, these object constructs are destroyed very frequently, such as i-node,dentry, these objects if each time the construction of the memory to a page (4KB), and actually only a few bytes, so it is very wasteful, in order to solve this problem, A new mechanism is introduced to deal with how small stores are allocated in the same page box, and slab can allocate small objects so that there is no need to allocate a page box for each object, thus saving space, the kernel creates destructors for small objects very often, slab these small objects, and can be reused, Reduce the number of memory allocations.

  

  

  

One Linux command per day (--vmstat) command

Related Article

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.