Linux Vmstat command

Mar 20, 2024 pm 01:49 PM
linux ram Virtual Memory Linux operating system

Linux Vmstat命令

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!

Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

AI Hentai Generator

AI Hentai Generator

Generate AI Hentai for free.

Hot Article

R.E.P.O. Energy Crystals Explained and What They Do (Yellow Crystal)
4 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. Best Graphic Settings
4 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. How to Fix Audio if You Can't Hear Anyone
4 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
WWE 2K25: How To Unlock Everything In MyRise
1 months ago By 尊渡假赌尊渡假赌尊渡假赌

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

What is Linux actually good for? What is Linux actually good for? Apr 12, 2025 am 12:20 AM

Linux is suitable for servers, development environments, and embedded systems. 1. As a server operating system, Linux is stable and efficient, and is often used to deploy high-concurrency applications. 2. As a development environment, Linux provides efficient command line tools and package management systems to improve development efficiency. 3. In embedded systems, Linux is lightweight and customizable, suitable for environments with limited resources.

How to start apache How to start apache Apr 13, 2025 pm 01:06 PM

The steps to start Apache are as follows: Install Apache (command: sudo apt-get install apache2 or download it from the official website) Start Apache (Linux: sudo systemctl start apache2; Windows: Right-click the "Apache2.4" service and select "Start") Check whether it has been started (Linux: sudo systemctl status apache2; Windows: Check the status of the "Apache2.4" service in the service manager) Enable boot automatically (optional, Linux: sudo systemctl

What to do if the apache80 port is occupied What to do if the apache80 port is occupied Apr 13, 2025 pm 01:24 PM

When the Apache 80 port is occupied, the solution is as follows: find out the process that occupies the port and close it. Check the firewall settings to make sure Apache is not blocked. If the above method does not work, please reconfigure Apache to use a different port. Restart the Apache service.

How to monitor Nginx SSL performance on Debian How to monitor Nginx SSL performance on Debian Apr 12, 2025 pm 10:18 PM

This article describes how to effectively monitor the SSL performance of Nginx servers on Debian systems. We will use NginxExporter to export Nginx status data to Prometheus and then visually display it through Grafana. Step 1: Configuring Nginx First, we need to enable the stub_status module in the Nginx configuration file to obtain the status information of Nginx. Add the following snippet in your Nginx configuration file (usually located in /etc/nginx/nginx.conf or its include file): location/nginx_status{stub_status

How to start monitoring of oracle How to start monitoring of oracle Apr 12, 2025 am 06:00 AM

The steps to start an Oracle listener are as follows: Check the listener status (using the lsnrctl status command) For Windows, start the "TNS Listener" service in Oracle Services Manager For Linux and Unix, use the lsnrctl start command to start the listener run the lsnrctl status command to verify that the listener is started

How to set up a recycling bin in Debian system How to set up a recycling bin in Debian system Apr 12, 2025 pm 10:51 PM

This article introduces two methods of configuring a recycling bin in a Debian system: a graphical interface and a command line. Method 1: Use the Nautilus graphical interface to open the file manager: Find and start the Nautilus file manager (usually called "File") in the desktop or application menu. Find the Recycle Bin: Look for the Recycle Bin folder in the left navigation bar. If it is not found, try clicking "Other Location" or "Computer" to search. Configure Recycle Bin properties: Right-click "Recycle Bin" and select "Properties". In the Properties window, you can adjust the following settings: Maximum Size: Limit the disk space available in the Recycle Bin. Retention time: Set the preservation before the file is automatically deleted in the recycling bin

How to restart the apache server How to restart the apache server Apr 13, 2025 pm 01:12 PM

To restart the Apache server, follow these steps: Linux/macOS: Run sudo systemctl restart apache2. Windows: Run net stop Apache2.4 and then net start Apache2.4. Run netstat -a | findstr 80 to check the server status.

How to optimize the performance of debian readdir How to optimize the performance of debian readdir Apr 13, 2025 am 08:48 AM

In Debian systems, readdir system calls are used to read directory contents. If its performance is not good, try the following optimization strategy: Simplify the number of directory files: Split large directories into multiple small directories as much as possible, reducing the number of items processed per readdir call. Enable directory content caching: build a cache mechanism, update the cache regularly or when directory content changes, and reduce frequent calls to readdir. Memory caches (such as Memcached or Redis) or local caches (such as files or databases) can be considered. Adopt efficient data structure: If you implement directory traversal by yourself, select more efficient data structures (such as hash tables instead of linear search) to store and access directory information

See all articles