As we all know, computers must have a memory called RAM (Random Access to memory) to make computers work. RAM refers to physical storage inserted on the computer motherboard. RAM is used to load programs such as browsers and word processors. In fact, all the programs you use run in the memory.
Let's assume you have 2 GB of memory. When you are running the operating system, your available memory may only be 1.5 GB. Then you use a large number of programs. When the memory usage is full, you may no longer be able to load more programs. Simply put, the computer may say, "Sorry, you cannot run more programs. If you want to run other programs, close them first. "
To solve this problem, various operating systems, including Linux, use a method called virtual memory. This method searches for the memory areas of programs that are not in use recently, and then copies them to the hard disk of the computer. This will free up some memory space for you to run more programs.
To monitor virtual memory activity, we use the vmstat tool.
What is vmstat?
Vmstat is a tool for reporting virtual memory statistics. It includes system memory, swap, and real-time processor utilization.
How to run vmstat
Like mpstat, vmstat is included in the sysstat package. If you do not have one, install the sysstat package.
To run vmstat, you only need to enter vmstat in the console. Running vmstat without parameters will display the default result of vmstat.
Let's take a look at how vmstat provides information:
Procs
Procs has the r column and B column. The r column indicates the number of CPU processes waiting to be accessed. Column B indicates the number of sleep processes. Below these columns are their values. From the above, we have two processes waiting to access the CPU and zero sleep processes.
Memory
Memory has swpd, free, buff, and cache columns. The information is the same as the free-m command. The swpd column shows how much memory has been exchanged to swap files or disks. The free column shows unallocated available memory. The buff column shows the memory in use. The cache column shows how much memory can be exchanged to swap files or disks if some applications need them.
Swap
Swap shows how much memory is sent or retrieved from the swap system. The si column tells us how much memory is transferred from swap to real memory (In) per second ). The so column tells us how much memory is transferred from the real memory to the swap (Out) every second ).
I/O
Io displays input/output activities per second based on the read/write of the block. The bi column tells us the number of received blocks, and the bo column tells us the number of sent blocks.
System
System displays the number of system operations per second. The in column shows the number of system interruptions per second. The cs column shows the number of context switches for the system to process the task.
CPU
CPU tells us the usage of CPU resources. The us column shows the time consumed by the processor in a non-kernel program. The sy column shows the time consumed by the processor on Kernel-related tasks. The id column shows the idle time of the processor. The wa column shows the time when the processor waited for the completion of the IO operation to continue processing the task.
Linux vmstat command details
Detailed description of vmstat display results in Linux
Vmstat for Linux monitoring tools
Linux vmstat commands
Linux vmstat monitors system load