Facebook Twitter Instagram
    Facebook Twitter Instagram
    Techtown
    • General
    • Linux
      • Linux Commands
      • Debian
      • Ubuntu
      • Linux Mint
      • Centos
      • OpenSUSE
      • Fedora
    • Text Editors
      • Notepad++
      • Sublime Text
    • Resources
      • Books
    • Write for Us
    Techtown
    Home » How to use Vmstat command in Linux explained with examples
    Linux

    How to use Vmstat command in Linux explained with examples

    By AMJuly 28, 2021Updated:July 28, 2021No Comments5 Mins Read
    Share
    Facebook Twitter LinkedIn Pinterest Email

    Thanks to the potential of the Linux terminal, we can enjoy tools that allow us to keep an eye on the performance of the computer. This time we will talk about the vmstat command and you will also learn how to use it with some examples.

    In a nutshell, the vmstat command provides information about the computer’s virtual memory.

    What is virtual memory?

    As virtual memory, we should not understand it as an additional module that our computer has but as a technique of computer memory management, whose use lies in the joint use of the main memory of the system and our storage unit, such as a hard disk.

    So it is nothing more than a trick used by the system to use part of our storage as an additional memory module. Something like the Linux swap.

    As this space is used, it can have an impact on the speed of the computer because the RAM will always be faster than other types of storage.

    So, thanks to the incredible potential of the Linux terminal, we can monitor it quickly and easily, and all thanks to the vmstat command.

    The vmstat command

    The vmstat command is used in UNIX operating systems, it provides data about virtual memory, gives information about processes, memory, paging, block I/O, traps, and CPU activity.

    The first report produced gives averages since the last reboot. Additional reports give information on a sampling period of length delay. The process and memory reports are instantaneous in either case.

    The basic syntax of the vmstat command is as follows

    vmstat [options] [delay [count]]]

    By default, the command comes to give a single report but we can modify it with the options and by setting a refreshing time.

    Using the vmstat commmand

    If you run the command without any options or parameters you will get an output screen similar to this one

    vmstat

    Output:

    procs -----------memory---------- ---swap-- -----io---- -system-- ------cpu-----
     r  b   swpd   free   buff  cache   si   so    bi    bo   in   cs us sy id wa st
     1  0 114432 212660  76392 650036    0    4    60    97  579  155 16  6 77  2  0
    

    Where you will immediately notice that it is divided into some sections along with some values.

    In the procs section are the system processes and these two indicators

    • r: The number of runnable processes (running or waiting for run time).
    • b: The number of processes blocked waiting for I/O to complete.

    Then, we have the Memory section that examines the virtual memory itself:

    • swpd: the amount of swap memory used.
    • free: the amount of idle memory.
    • buff: the amount of memory used as buffers.
    • cache: the amount of memory used as cache.

    As you can see, these are simple values and information.

    Follow the Swap section:

    • si: Amount of memory swapped in from disk (/s).
    • so: Amount of memory swapped to disk (/s).

    Immediately follows the Input / Output section:

    • bi: Blocks received from a block device (blocks/s).
    • bo: Blocks sent to a block device (blocks/s).

    Next is the System section:

    • in: The number of interrupts per second, including the clock.
    • cs: The number of context switches per second.

    Finally, there is the CPU section:

    • us: Time spent running non-kernel code. (user time, including nice time)
    • sy: Time spent running kernel code. (system time)
    • id: Time spent idle.
    • wa: Time spent waiting for IO.
    • st: Time stolen from a virtual machine.

    Some examples

    Although the vmstat command is so easy to use, it is possible to get a lot out of it, so here are some examples.

    Adding a time interval

    It is possible to obtain values and results by adding a refreshing time that we can define. By default, the time is expressed in seconds.

    For example, to get reports every 3 seconds you can run

    vmstat 3

    When you run the command with an interval time you will get infinite reports. To stop the command press the CTRL + C keys.

    Interval time with a limit

    But you can change this behavior and add another parameter that will print a defined number of reports.

    vmstat 3 2

    In this case, two reports will be printed at an interval of 3 seconds.

    Making the report more readable

    By default, the values shown by vmstat are expressed in blocks. You can change this to Mb or Kb by using the -S option.

    To get expressions in Kb, use after the -S option the letter K or k.

    vmstat 3 2 -S K

    And then you will get the output on the screen expressed in Kb.

    In the case of Mb, you can use the letters M and m

    vmstat 3 2 -S M

    And this way we can easily understand even more the generated reports.

    Conclusion

    A terminal is an incredible tool and in Unix, there are commands for everything. In this case, we have presented you with a command to monitor virtual memory usage. This kind of command helps us not to miss anything about our computer. Sysadmins appreciate this kind of command that does not consume resources and provides useful information.

    More info: vmstat documentation

    linux commands
    Share. Facebook Twitter Pinterest LinkedIn Tumblr Email
    Previous ArticleHow to use iostat command in Linux explained with examples
    Next Article How to Install and Configure Varnish on Ubuntu 20.04?
    AM

    Related Posts

    How to Set the Time zone in Debian 11

    May 25, 2022

    How to Open a Terminal in Linux Mint

    May 24, 2022

    How to Restart Ubuntu From the Terminal

    May 23, 2022
    Add A Comment

    Comments are closed.

    Recent Posts
    • How to Set the Time zone in Debian 11
    • How to Open a Terminal in Linux Mint
    • How to Restart Ubuntu From the Terminal
    • How to Install Zoom on openSUSE
    • How to Install xArchiver on Debian 11
    Affiliate Disclosure
    This website contains Affiliate Links. We get small commission for purchases made through affiliate links (at no extra cost to you)
    Facebook Twitter Instagram Pinterest
    • Debian
    • Ubuntu
    • Mint
    • Fedora
    • CentOS
    • openSUSE
    • Chrome
    • XAMPP
    • Forums
    • Notepad++
    • Privacy Policy
    • About Me
    © 2022 ThemeSphere. Designed by ThemeSphere.

    Type above and press Enter to search. Press Esc to cancel.