Skip to main content
Engineering LibreTexts

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

  • Page ID
    38092
  • \( \newcommand{\vecs}[1]{\overset { \scriptstyle \rightharpoonup} {\mathbf{#1}} } \) \( \newcommand{\vecd}[1]{\overset{-\!-\!\rightharpoonup}{\vphantom{a}\smash {#1}}} \)\(\newcommand{\id}{\mathrm{id}}\) \( \newcommand{\Span}{\mathrm{span}}\) \( \newcommand{\kernel}{\mathrm{null}\,}\) \( \newcommand{\range}{\mathrm{range}\,}\) \( \newcommand{\RealPart}{\mathrm{Re}}\) \( \newcommand{\ImaginaryPart}{\mathrm{Im}}\) \( \newcommand{\Argument}{\mathrm{Arg}}\) \( \newcommand{\norm}[1]{\| #1 \|}\) \( \newcommand{\inner}[2]{\langle #1, #2 \rangle}\) \( \newcommand{\Span}{\mathrm{span}}\) \(\newcommand{\id}{\mathrm{id}}\) \( \newcommand{\Span}{\mathrm{span}}\) \( \newcommand{\kernel}{\mathrm{null}\,}\) \( \newcommand{\range}{\mathrm{range}\,}\) \( \newcommand{\RealPart}{\mathrm{Re}}\) \( \newcommand{\ImaginaryPart}{\mathrm{Im}}\) \( \newcommand{\Argument}{\mathrm{Arg}}\) \( \newcommand{\norm}[1]{\| #1 \|}\) \( \newcommand{\inner}[2]{\langle #1, #2 \rangle}\) \( \newcommand{\Span}{\mathrm{span}}\)\(\newcommand{\AA}{\unicode[.8,0]{x212B}}\)

    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.

    Syntax:

    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.

    Command Options:

    Options 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.

    Syntax:

    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.

    Command Optionssssss

    Options Meaning
    delay The delay between updates in seconds. If no delay is specified, only one report is printed with the average values since boot.
    count Number of updates. In absence of count, when delay is defined, default is infinite.
    -a, --active Display active and inactive memory, given a 2.5.41 kernel or better.
    -f, --forks The -f switch displays the number of forks since boot.
    -m, --slabs Displays slabinfo.
    -n, --one-header Display the header only once rather than periodically.
    -s, --stats Displays a table of various event counters and memory statistics. This display does not repeat.
    -d, --disk Report disk statistics (2.5.70 or above required).
    -t, --timestamp Append timestamp to each line
    -w, --wide Wide output mode. The output is wider than 80 characters per line.
    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


    08-E.10.2: CPU and Memory Troubleshooting - free / vmstat Commands is shared under a CC BY-SA 4.0 license and was authored, remixed, and/or curated by LibreTexts.

    • Was this article helpful?