Linux system administrator must-have tool series vmstat

  
        

I. Preface

Obviously from the name we can know that vmstat is a tool to check the usage of virtual memory, but how to find the bottleneck in the system through vmstat? Before answering this question, let us review the virtual memory related content in Linux.

Second, the virtual memory operating principle

Each process running in the system needs to use memory, but not every process needs to use the system allocated memory space all the time. When the system requires more memory than the actual physical memory, the kernel will release some or all of the physical memory occupied by some processes, and store this part of the data on the disk until the next call of the process, and the memory will be released. Provided to processes that need it.

In Linux memory management, the above memory scheduling is mainly done through "Paging" and "Exchange Swapping". The paging algorithm replaces the recently infrequently used pages in memory to disk and keeps the active pages in memory for use by the process. Switching technology is to swap entire processes, not partial pages, to disk.

The process of writing to the disk is called Page-Out. The process of paging back from disk to memory is called Page-In. When the kernel needs a page, it finds This page break is not in physical memory (because it has been Page-Out), and a Page Fault occurs.

When the system kernel finds that there is less running memory, it will release some of the physical memory through Page-Out. The management of Page-Out does not happen often, but if Page-out occurs frequently, the system performance will drop dramatically until the time the kernel manages the paging exceeds the time of running the program. At this time, the system has been running very slowly or entering a pause state, which is also called thrashing.

Third, use vmstat

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: Display active and inactive memory

-f: Display the number of forks since system startup.

-m: Display slabinfo

-n: Display each field name only once at the beginning.

-s: Displays memory-related statistics and the number of various system activities.

delay: The refresh interval. If not specified, only one result is displayed.

count: The number of refreshes. If you do not specify the number of refreshes, but specify a refresh interval, then the number of refreshes is infinite.

-d: Display disk related statistics.

-p: Display the specified disk partition statistics

-S: Display using the specified unit. The parameters are k, K, m, and M, representing 1000, 1024, 1000000, and 1048576 bytes, respectively. The default unit is K (1024 bytes)

-V: Display vmstat version information.

2. Instructions for use

Example 1: Output a result every 2 seconds

Field Description:

Procs(process):

r: Number of processes in the run queue

b: Number of processes waiting for IO

Memory:

swpd: Use virtual memory size

Free: available memory size

buff: memory size used as buffer

cache: memory size used as cache

Swap:

si: per Seconds written from swap area to memory size

so: memory size written to swap area per second

IO: (current Linux version block size 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: Number of context switches per second.

CPU (in percent):

us: user process execution time (user time)

sy: system process execution time (system time)

id: Idle time (including IO wait time)

wa: Waiting for IO time

Example 2: Display active and inactive memory

Use the -a option to display active and In the case of inactive memory, the displayed content is the same as in Example 1 except that inact and active are added.

Field Description:

Memory:

inact: Inactive memory size (displayed when the -a option is used)

active: active Memory size (displayed when the -a option is used)

Copyright © Windows knowledge All Rights Reserved