Home >Computer Tutorials >Computer Knowledge >Linux Vmstat command
In this guide, we will demonstrate various ways to use the “vmstat” command in Linux.
To perform the steps demonstrated in this guide, you will need the following components:
RAM, or physical memory, is a limited resource allocated by the operating system to running programs. All programs, including the operating system itself, need to occupy this space.
When memory requirements exceed available memory, the system may crash or a program may request more memory space. In most cases, this situation is undesirable. Hence the concept of virtual memory, which allows the system to store part of the data on the hard disk so that it can be swapped to RAM when needed. In this way, the system can manage memory resources more efficiently, ensuring that programs run normally without crashing due to insufficient memory. The use of virtual memory makes the system face memory requirements
Virtual memory is a technology in computer systems that uses space on a hard drive or solid-state drive to expand the capacity of memory to act as additional memory when needed. Virtual memory is actually a way of using part of your hard drive space as temporary storage so that it can be replenished when the processor needs more memory. In UNIX and Linux operating systems, this technology is called swap space and is used to manage the allocation and exchange of memory resources. Although virtual memory is not real physical memory, it can improve the performance and stability of the system and ensure that the system can handle larger workloads.
The Linux kernel moves blocks of memory to swap space and retrieves them back to RAM when necessary.
Virtual memory is usually slower than physical memory and depends on the performance of the storage device. But under certain hardware settings (such as using NVMe SSD), the performance of virtual memory may be comparable to RAM.
The "vmstat" command is a utility tool for monitoring virtual memory related information. It is available on all Linux systems as part of the "sysstat" package.
The command structure of "vmstat" is as follows:
$vmstat
If run without any parameters, "vmstat" will print system information since the last startup:
$vmstat
The output is divided into six parts:
By default, "vmstat" reports memory values in bytes. To change units, use the "-S" flag:
$vmstat-S
Here, "vmstat" prints the value in MB.
There are several memory units available:
By default, "vmstat" prints a report once. However, we can instruct "vmstat" to provide continuous reports at specified intervals (in seconds).
The command structure is as follows:
$vmstat
For example, to obtain updated statistics every 2 seconds, the command is as follows:
$vmstat 2
Output will not stop unless manually terminated using "Ctrl C".
Alternatively, we can specify "vmstat" to provide statistics for a specific number of times:
$vmstat
For example, to obtain statistics updated every 2 seconds, the command is as follows:
$vmstat 2 5
Active memory refers to the memory space currently used by the process. On the other hand, inactive memory refers to the memory space allocated to processes that are no longer running.
Using "vmstat" we can check the amount of active and inactive memory being used:
$vmstat—a
Here, the "buff" and "cache" columns are replaced by the "inact" and "active" columns respectively.
To get a more detailed report on memory and scheduling, use the following command:
$vmstat—s
here:
Forks refer to processes spawned from existing processes. To get statistics on fork count, run the following command:
$vmstat-f
The "vmstat" command can also provide information about disk activity. To get a quick summary of disk activity, run the following command:
$vmstat—D
To get a more detailed report of disk activity (including read/write statistics), use the following command instead:
$vmstat—d
here:
The "vmstat" command can also generate reports for specific disk partitions. To obtain a partition report, use the following command structure:
$vmstat-p
Board allocation is an efficient object memory allocation mechanism. Slab allocation provides reduced memory fragmentation (caused by memory allocation and deallocation) compared to previous mechanisms.
To check the slab statistics of the system, use the following "vmstat" command:
$sudo vmstat—m
Please note that it requires root access to view statistics.
here:
In this guide, we show various ways of using the "vmstat" command. In addition to virtual memory, "vmstat" can also report disk statistics, forks, shards, etc.
Interested in learning about other system monitoring tools? Learn more about HTOP, KILL, PS and more.
Happy computing!
The above is the detailed content of Linux Vmstat command. For more information, please follow other related articles on the PHP Chinese website!