An acronym for “Virtual Memory Statistics”, the vmstat command is a Linux utility for displaying statistics related to memory consumption, disk usage, and other system information. Without any further ado, let us get down to the analysis of vmstat command.
In case your system does not have the vmstat command, then no worries, as it comes under the package of
Debian/Ubuntu users can install the package by using the apt command:
sudo apt install sysstat
Whereas other Linux distribution users can install
'sysstat' using their standard installation commands.
Before moving onto the explanation stuff, we first need to get root access as some information might be off-limits for certain users. This can be done by
'sudo -s' or
Table of Contents
Basic output of the vmstat command
After completing all the obligations required for the setup, let us run
'vmstat' on the terminal.
At first, the shady output is beyond comprehension for any Linux user. Let us try to cast some light on it. There are six sections in the output, with some non-indented statistics below:
- procs – Process Statistics
- r – The number of processes that are active in the system.
- b – The number of sleeping processes.
- memory – Memory statistics
- swpd – The amount of virtual memory being used by the system. The swap space is initially unoccupied. but as the system’s physical memory is about the reach its limit, the kernel decides to use the swap partition.
- free – The amount of free memory.
- buff – The amount of memory that has been temporarily occupied as buffers.
- cache – The amount of cache memory.
- swap – Swap space Statistics
- si – The rate at which memory is swapped in from disk.
- so – The rate at which memory is swapped out to disk.
- io – Input/Output Statistics
- bi – The rate at which blocks are read from disk.
- bo – The rate at which blocks are written to disk.
- system – Scheduling statistics
- in – The rate of system interrupts.
- cs – The rate of context switches done by the scheduler.
- cpu – CPU Statistics
- us – The percentage of CPU time spent on user processes.
- sy – The percentage of CPU time spent on kernel processes.
- id – The percentage of idle CPU time.
- wa – The percentage of CPU time spent waiting for Input/Output.
- st – The percentage of CPU time stolen by a virtual machine.
The above statistics provided by the basic output are instantaneous, that is, the system information at that particular point of time. To get a timestamp along with the output, we can make use of
Continuous statistical output
In order to get a series of
'vmstat' outputs, we need to run the following command:
vmstat <DELAY> <ITERATIONS>
This procedure is not very difficult to understand.
- <DELAY> – Since,
'vmstat'provides discrete values we can specify the delay between each statistic, the command displays.
- <ITERATIONS> – The number of times we need the command to print the information.
Note: To run the command infinite number of times, (basically an infinite loop), we can omit the
'vmstat 1'displays statistics with a one-second delay indefinite number of times.
Memory and Scheduling Statistics
We can display some extended information related to Memory, by running:
These summary statistics are self-explainable.
- The first set of lines deals with the amount of memory being used in the system:
- Total physical memory
- Currently used memory
- Active memory – used recently
- Inactive memory – not used recently
- Free memory
- Buffer memory
- Cache memory
- Swap memory information
- The following set of lines represents the CPU used in various ways:
- CPU used for high priority user processes (not-nice)
- Processor time used for less priority user processes (nice)
- CPU for kernel processes
- Idle CPU
- Processor for input/output management
- CPU for interrupt requests
- Processor time used for software interrupts
- CPU stolen by some virtual machine
- Next up are values related paging in Operating System:
- Number of pages paged in from virtual memory
- The number of pages paged out to virtual memory
- Number of pages read from swap memory
- Number of pages written to swap memory
- The last set of numbers denote:
- Number of interrupts since boot-time
- Number context switches done by the system scheduler
- The timestamp for the last boot-time
- The number of forks done to create child processes. (This information can directly be obtained by running
Display Disk Statistics Using vmstat Command
The command provides a similar kind of statistics for disk usage. It can be accessed by:
Each entry displays some crucial information:
- The number of disks present in the system.
- The number of partitions in the system.
- The total number of requested reads.
- The number of merged reads for increasing performance.
- The number of sectors already read from the disk.
- The period of time spent on reading the disk in milliseconds.
- The total number of requested writes.
- The number of merged writes for increasing performance.
- The number of sectors already written to the disk.
- The period of time spent on writing to the disk in milliseconds.
- The number of Input/Output currently inprogress.
- The period of time spent waiting for Input/Output.
Note: In certain versions of
'vmstat', the last two entries in the above output have been implemented incorrectly.
For detailed statistics on each disk usage, we can use
The above output displays the same statistics for every specific disk present in the system.
Memory usage by Linux kernel
Linux kernel implements a slab-level of memory management, for efficient use of memory in the system. The vmstat command provides information related to slabs maintained by the Linux kernel.
This sort of output can be obtained by:
The columns in the output means:
- The first column denotes the name of the slab (Cache).
- It is followed by the number of objects currently held in the slab (Num).
- Next up, is the total number of available objects present in the slab (Total).
- The next value is the size of the slab in bytes (Size).
- The last value is the number of pages present in each slab (Pages).
This pretty much sums up the important information presented by the
This concludes the guide to the usage of
'vmstat' command in Linux. In case, you are curious about some specifications of the command, then the manual pages will be the right path to follow.
The manual pages can be accessed by running
'man vmstat' on the terminal. We hope this article provided enough information to the reader.