Skip to main content
Engineering LibreTexts

08-E.10.2: CPU and Memory Troubleshooting - free / vmstat Commands

  • Page ID
  • The free Command

    Linux provides the free command which displays the total amount of free space available, along with the amount of memory used and swap memory in the system, and also the buffers used by the kernel. The free command actually gets this information from the /proc/meminfo file discussed above.


    free [ OPTION ]

    As free displays the details of the memory related to your system, its syntax doesn’t need any arguments to be passed, but only options which you can use according to your wish.

    pbmac@pbmac-server $ free
                  total        used        free      shared  buff/cache   available
    Mem:       12228648    10094296      549120      656608     1585232     1195616
    Swap:          8188        8188           0

    When no option is used then free command produces the columnar output as shown above, where column:

    • total displays the total installed memory (MemTotal and SwapTotal i.e present in /proc/meminfo).
    • used displays the used memory.
    • free displays the unused memory.
    • shared displays the memory used by tmpfs(Shmen i.epresent in /proc/meminfo and displays zero in case not available).
    • buffers displays the memory used by kernel buffers.
    • cached displays the memory used by the page cache and slabs (Cached and Slab available in /proc/meminfo).
    • buffers/cache displays the sum of buffers and cache.


    Options Option Meaning
    -b, – -bytes Displays the memory in bytes.
    -k, – -kilo Displays the amount of memory in kilobytes (default).
    -m, – -mega Displays the amount of memory in megabytes.
    -g, – -giga Displays the amount of memory in gigabytes.
    – – tera Displays the amount of memory in terabytes.
    -h, – -human Shows all output columns automatically scaled to shortest three digit unit and displays the units also of print out. The units used are B(bytes), K(kilos), M(megas), G(gigas), and T(teras).
    -l, – -lohi Shows the detailed low and high memory statistics.
    -o, – -old Disables the display of the buffer adjusted line.
    -s, – -seconds Allows you to display the output continuously after s seconds delay. In actual, the usleepsystem call is used for microsecond resolution delay times.
    -t, – -total Adds an additional line in the output showing the column totals.

    The vmstat Command

    The vmstat command in Linux gives information about processes, memory, paging, block IO, disk and CPU scheduling.


    vmstat [ OPTIONS ][delay [count]]

    Delay: This is the time interval in between two updates. It can be termed as a sampling period after each interval of the sampling period report that will be printed with the updated details. If there will be no delay specified only one report will be printed with average value since boot.

    Count: This is the number of updates which is printed after each interval (sampling period). In the absence of count and delay is specified, the default value of count is infinite.

    pbmac@pbmac-server $ vmstat
    procs -----------memory---------- ---swap-- -----io---- -system-- ------cpu-----
     r  b   swpd   free   buff  cache   si   so    bi    bo   in   cs us sy id wa st
     0  0   8188 1114688  54256 1023088    0    0    20    69   15    0  8  2 89  1  0

    There are two main stats shown in this example: 1) Memory stats - which includes the swap data and 2) CPU stats.

    • Free: Specifies the amount of free memory/idle memory spaces which are not being used.
    • si: Memory that is swapped in every second from disk in kilobytes.
    • so: Memory that is swapped out every second to disk in kilobytes.
    • In the given figure we can see the process, memory, swap in memory, swap out memory, io, system and cpu update.

    Adapted from:
    "free Command in Linux with examples" by Kartik Thakral, Geeks for Geeks is licensed under CC BY-SA 4.0"
    vmstat command in Linux with Examples"
    by Bhumika_Rani, Geeks for Geeks is licensed under CC BY-SA 4.0

    • Was this article helpful?