Linux Vmstat command
In this guide, we will demonstrate various ways to use the “vmstat” command in Linux.
prerequisites:
To perform the steps demonstrated in this guide, you will need the following components:
- Configure the correct Linux system. For testing purposes, consider using a Linux VM.
- Access to non-root users with sudo privileges
- Basic understanding of command line interface
Virtual memory in Linux
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.
vmstat command
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
Basic usage
If run without any parameters, "vmstat" will print system information since the last startup:
$vmstat
The output is divided into six parts:
- procs: Statistics of currently running processes
- r: Number of active processes
- b: Number of sleep processes
- memory: memory usage statistics
- Swpd: Total virtual memory (swap space)
- Free: available swap space
- buff: Amount of swap space used as temporary buffer memory
- Cache: Total cache memory
- swap: Statistics about swap space
- si: exchange rate
- So: swap-out ratio
- io: I/O statistics
- bi: number of blocks received from block device
- bo: Number of blocks sent to the block device
- System: Schedule Statistics
- in: System interrupt count
- cs: context switch rate
- CPU: Various CPU statistics
- United States: CPU time spent on non-kernel processes
- sy: CPU time spent on kernel processes
- id: CPU spends time idle
- wa: The CPU spends time waiting for the I/O operation to complete
- st: CPU time used by the virtual machine
Change display unit
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:
- M: 1048576 bytes (2^20 bytes)
- M: 1000000 bytes (1000 kilobytes)
- K: 1024 bytes (1 megabyte)
- k: 1000 bytes (1 byte)
Continuous statistics updates
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 and inactive memory
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.
Memory and Scheduling
To get a more detailed report on memory and scheduling, use the following command:
$vmstat—s
here:
- Section 1: This section introduces basic system information, such as total physical memory, active/inactive memory, free/buffer/cache memory, etc.
- Section 2: Various CPU Statistics
- Non-good CPU beats: The number of times a high-priority process uses the CPU.
- NICE CPU TICK: The number of times low-priority processes use the CPU.
- System CPU count: The number of times the kernel process uses the CPU.
- Idle CPU ticks: The number of times the CPU is idle.
- IO—wait CPU ticks: The number of times the CPU waits for I/O management.
- IRQ: The number of times the CPU receives interrupt requests.
- softirq: The number of times the CPU receives software interrupt requests.
- Stolen CPU Time: The number of times the VM stole CPU time.
- Section 3: Memory paging status
- Section 4: Event Counter
Post-boot fork
Forks refer to processes spawned from existing processes. To get statistics on fork count, run the following command:
$vmstat-f
Disk and Partition Statistics
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:
- reading
- total: total disk reads
- Mergeed: Total number of group reads
- sectors: Total number of sectors read
- ms: Total time to read data from disk (milliseconds)
- wrote
- total: disk write count
- Mergeed: Total number of group writes
- sectors: Total number of sectors written
- ms: Total time to write to disk (milliseconds)
- io
- cur: Current total disk read/write count
- Seconds: The amount of time (seconds) spent on the ongoing read/write operation
The "vmstat" command can also generate reports for specific disk partitions. To obtain a partition report, use the following command structure:
$vmstat-p
Plate statistics
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:
- Cache: Name of cached data
- Num: The number of active objects in the Num cache
- Total: Total number of objects in a specific cache
- Size: The size of the cache object
- Pages: Memory page count containing cached objects
in conclusion
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!

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics

VS Code system requirements: Operating system: Windows 10 and above, macOS 10.12 and above, Linux distribution processor: minimum 1.6 GHz, recommended 2.0 GHz and above memory: minimum 512 MB, recommended 4 GB and above storage space: minimum 250 MB, recommended 1 GB and above other requirements: stable network connection, Xorg/Wayland (Linux)

The five basic components of the Linux system are: 1. Kernel, 2. System library, 3. System utilities, 4. Graphical user interface, 5. Applications. The kernel manages hardware resources, the system library provides precompiled functions, system utilities are used for system management, the GUI provides visual interaction, and applications use these components to implement functions.

Although Notepad cannot run Java code directly, it can be achieved by using other tools: using the command line compiler (javac) to generate a bytecode file (filename.class). Use the Java interpreter (java) to interpret bytecode, execute the code, and output the result.

The reasons for the installation of VS Code extensions may be: network instability, insufficient permissions, system compatibility issues, VS Code version is too old, antivirus software or firewall interference. By checking network connections, permissions, log files, updating VS Code, disabling security software, and restarting VS Code or computers, you can gradually troubleshoot and resolve issues.

To view the Git repository address, perform the following steps: 1. Open the command line and navigate to the repository directory; 2. Run the "git remote -v" command; 3. View the repository name in the output and its corresponding address.

VS Code is available on Mac. It has powerful extensions, Git integration, terminal and debugger, and also offers a wealth of setup options. However, for particularly large projects or highly professional development, VS Code may have performance or functional limitations.

vscode built-in terminal is a development tool that allows running commands and scripts within the editor to simplify the development process. How to use vscode terminal: Open the terminal with the shortcut key (Ctrl/Cmd). Enter a command or run the script. Use hotkeys (such as Ctrl L to clear the terminal). Change the working directory (such as the cd command). Advanced features include debug mode, automatic code snippet completion, and interactive command history.

Writing code in Visual Studio Code (VSCode) is simple and easy to use. Just install VSCode, create a project, select a language, create a file, write code, save and run it. The advantages of VSCode include cross-platform, free and open source, powerful features, rich extensions, and lightweight and fast.
