The vmstat command under Linux can be used to report the statistics of virtual memory. In addition, there are many usages of the vmstat command. The following version of the system home will give you a vmstat command. Detailed introduction so that you have an understanding.
It is the overall situation of the system statistics, the downside is not an in-depth analysis of a process. The vmstat tool provides a low-overhead way to observe system performance. Because vmstat itself is a low-overhead tool, on very high-load servers, you need to view and monitor the health of the system, and you can still use vmstat to output the results in the control window. Before learning the vmstat command, let's take a look at the information about physical memory and virtual memory in the Linux system.
The difference between physical memory and virtual memory:
We know that reading and writing data directly from physical memory is much faster than reading and writing data from the hard disk. Therefore, we want to read all data. And writes are done in memory, and memory is limited, which leads to the concept of physical memory and virtual memory.
Physical memory is the memory size provided by the system hardware. It is real memory. Compared with physical memory, there is also a concept of virtual memory under linux. Virtual memory is a strategy proposed to meet the shortage of physical memory. It is a piece of logical memory that is virtualized out of disk space. 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 insufficient. In more detail, the kernel will write the unused memory block information to the swap space, so that The physical memory is released, and the memory can be used for other purposes. When the original content is needed, the information is read back into the physical memory from the swap space.
The memory management of linux adopts the paging access mechanism. In order to ensure that the physical memory can be fully utilized, the kernel will automatically exchange the infrequently used data blocks in the physical memory to the virtual memory at an appropriate time. , while retaining frequently used information to physical memory.
To understand the Linux memory operation mechanism, you need to know the following aspects:
First, the Linux system will perform page swap operations from time to time to maintain as many free physics as possible. Memory, even if there is nothing that requires memory, Linux will swap out memory pages that are temporarily unused. This avoids the time required to wait for the exchange.
Secondly, linux page exchange is conditional. Not all pages are exchanged to virtual memory when not in use. The Linux kernel is based on the most frequently used algorithm. Only some pages that are not used frequently are used. File exchange to virtual memory, sometimes we will see such a phenomenon: Linux physical memory is still a lot, but the swap space is also used a lot. In fact, this is not surprising. For example, when a process that occupies a large amount of memory runs, it takes a lot of memory resources. At this time, some infrequently used page files are swapped into virtual memory, but later it takes up a lot of memory resources. When the process ends and a lot of memory is released, the page files that have just been swapped out are not automatically swapped into physical memory. Unless this is necessary, the system physical memory will be idle a lot at the moment, and the swap space is also used. The phenomenon just mentioned has appeared. Don't worry about this, just know what it is all about.
Finally, the pages of the swap space are first exchanged to physical memory when they are used. If there is not enough physical memory to accommodate these pages, they will be swapped out immediately, so in virtual memory. There may not be enough space to store these exchange pages, which will eventually lead to problems such as fake crashes and service exceptions in Linux. Although Linux can recover itself for a period of time, the restored system is basically unavailable.
Therefore, it is very important to plan and design the use of linux memory reasonably.
Virtual Memory Principle:
Every process running in the system needs to use memory, but not every process needs to use the system allocated memory every moment. 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 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 a page to a disk is called Page-Out, and the process of paging back to disk from disk is called Page-In. When the kernel needs a page, but finds that the page is not in physical memory (because it has been Page-Out), 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. This state is also called thrashing.
1. Command format:
The code is as follows:
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 for displaying virtual memory
3. Command parameters:
-a: Display active and inactive memory
-f: Display the number of forks since the system was started.
-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.
4. Example:
Instance 1: Displaying Virtual Memory Usage
Command: vmstat
Output:
The code is as follows:
[ Root@localhost ~]# vmstat 5 6
procs -----------memory---------- ---swap-- -----io ---- --system-- -----cpu------
rb swpd free buff cache si so bi bo in cs us sy id wa st
0 0 0 3029876 199616 690980 0 0 0 2 3 2 0 0 100 0 0
0 0 0 3029752 199616 690980 0 0 0 41 1009 39 0 0 100 0 0
0 0 0 3029752 199616 690980 0 0 0 3 1004 36 0 0 100 0 0
0 0 0 3029752 199616 690980 0 0 0 4 1004 36 0 0 100 0 0
0 0 0 3029752 199616 690980 0 0 0 6 1003 33 0 0 100 0 0
0 0 0 3029752 199616 690980 0 0 0 5 1003 33 0 0 100 0 0
The vmstat command output details:
Field Description:
Procs(process):
r: Number of processes in the run queue
b: Number of processes waiting for IO
Memory Memory):
swpd: use virtual memory size
free: available memory size
buff: memory size used as buffer
cache: used as Cache memory size
Swap:
si: Size written to memory from swap area per second
so: Memory size written to swap area per second
IO: (The 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: Free time (including IO wait time), idle time of the CPU. Expressed as a percentage.
wa: Waiting for IO time
Note: If r is often greater than 4 and the id is often less than 40, the CPU load is heavy. If pi,po does not equal 0 for a long time, it means that there is not enough memory. If disk is often not equal to 0, and the queue in b is greater than 3, it means that io performance is not good. Linux has high stability and reliability, and has good scalability and scalability. It can be adjusted for different applications and hardware environments to optimize the best performance for current applications. Therefore, it is crucial for enterprises to understand system performance analysis tools when maintaining Linux systems and tuning systems.
Command: vmstat 5 5
means 5 samples in 5 seconds. Will get a summary of the data he can reflect the real system situation.
Previous1234Next page Total 4 pages
Linux disk management is mainly implemented by commands. Today, Xiaobian will sort out the commands
Many users often confuse rpm and yum under Linux system, they have similar names and functions, and
Swap is a swap partition in Ubuntu systems that functions somewhat like the virtual memory of a Wind
When we use a computer, we always open many applications and processes. How do we c
Common usage summary of free commands under Linux
How do Linux systems delete icons on the gnome panel?
What should I do if Ubuntu prompts the list error when opening the software center?
Xfs Extension Method Guide for Linux
Ubuntu sudo error command not found how to do?
Linux how to use the command to update the file directory time
How does the Linux system send mail?
Linux to see if the system is attacked by cc
Ubuntu wireless network card search can not find a solution
How to connect wifi through the command line under Linux?
Linux grub2 startup failure solution
Linux when the program is prompted to error while loading shared?
Change the default size of Windows 8 Recycle Bin
How to recover files deleted by mistake in Win10 system?
Win10 Mobile version of "Groove Music" "Movies and TV" ushered in update
How to install personalized theme in win8
Tip: Fully master the compression function of Windows XP
Win10 Consumer Edition Release Details
Let the MSN icon "dock" in the Windows 7 notification area method