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}}\)

    \( \newcommand{\vectorA}[1]{\vec{#1}}      % arrow\)

    \( \newcommand{\vectorAt}[1]{\vec{\text{#1}}}      % arrow\)

    \( \newcommand{\vectorB}[1]{\overset { \scriptstyle \rightharpoonup} {\mathbf{#1}} } \)

    \( \newcommand{\vectorC}[1]{\textbf{#1}} \)

    \( \newcommand{\vectorD}[1]{\overrightarrow{#1}} \)

    \( \newcommand{\vectorDt}[1]{\overrightarrow{\text{#1}}} \)

    \( \newcommand{\vectE}[1]{\overset{-\!-\!\rightharpoonup}{\vphantom{a}\smash{\mathbf {#1}}}} \)

    \( \newcommand{\vecs}[1]{\overset { \scriptstyle \rightharpoonup} {\mathbf{#1}} } \)

    \( \newcommand{\vecd}[1]{\overset{-\!-\!\rightharpoonup}{\vphantom{a}\smash {#1}}} \)

    \(\newcommand{\avec}{\mathbf a}\) \(\newcommand{\bvec}{\mathbf b}\) \(\newcommand{\cvec}{\mathbf c}\) \(\newcommand{\dvec}{\mathbf d}\) \(\newcommand{\dtil}{\widetilde{\mathbf d}}\) \(\newcommand{\evec}{\mathbf e}\) \(\newcommand{\fvec}{\mathbf f}\) \(\newcommand{\nvec}{\mathbf n}\) \(\newcommand{\pvec}{\mathbf p}\) \(\newcommand{\qvec}{\mathbf q}\) \(\newcommand{\svec}{\mathbf s}\) \(\newcommand{\tvec}{\mathbf t}\) \(\newcommand{\uvec}{\mathbf u}\) \(\newcommand{\vvec}{\mathbf v}\) \(\newcommand{\wvec}{\mathbf w}\) \(\newcommand{\xvec}{\mathbf x}\) \(\newcommand{\yvec}{\mathbf y}\) \(\newcommand{\zvec}{\mathbf z}\) \(\newcommand{\rvec}{\mathbf r}\) \(\newcommand{\mvec}{\mathbf m}\) \(\newcommand{\zerovec}{\mathbf 0}\) \(\newcommand{\onevec}{\mathbf 1}\) \(\newcommand{\real}{\mathbb R}\) \(\newcommand{\twovec}[2]{\left[\begin{array}{r}#1 \\ #2 \end{array}\right]}\) \(\newcommand{\ctwovec}[2]{\left[\begin{array}{c}#1 \\ #2 \end{array}\right]}\) \(\newcommand{\threevec}[3]{\left[\begin{array}{r}#1 \\ #2 \\ #3 \end{array}\right]}\) \(\newcommand{\cthreevec}[3]{\left[\begin{array}{c}#1 \\ #2 \\ #3 \end{array}\right]}\) \(\newcommand{\fourvec}[4]{\left[\begin{array}{r}#1 \\ #2 \\ #3 \\ #4 \end{array}\right]}\) \(\newcommand{\cfourvec}[4]{\left[\begin{array}{c}#1 \\ #2 \\ #3 \\ #4 \end{array}\right]}\) \(\newcommand{\fivevec}[5]{\left[\begin{array}{r}#1 \\ #2 \\ #3 \\ #4 \\ #5 \\ \end{array}\right]}\) \(\newcommand{\cfivevec}[5]{\left[\begin{array}{c}#1 \\ #2 \\ #3 \\ #4 \\ #5 \\ \end{array}\right]}\) \(\newcommand{\mattwo}[4]{\left[\begin{array}{rr}#1 \amp #2 \\ #3 \amp #4 \\ \end{array}\right]}\) \(\newcommand{\laspan}[1]{\text{Span}\{#1\}}\) \(\newcommand{\bcal}{\cal B}\) \(\newcommand{\ccal}{\cal C}\) \(\newcommand{\scal}{\cal S}\) \(\newcommand{\wcal}{\cal W}\) \(\newcommand{\ecal}{\cal E}\) \(\newcommand{\coords}[2]{\left\{#1\right\}_{#2}}\) \(\newcommand{\gray}[1]{\color{gray}{#1}}\) \(\newcommand{\lgray}[1]{\color{lightgray}{#1}}\) \(\newcommand{\rank}{\operatorname{rank}}\) \(\newcommand{\row}{\text{Row}}\) \(\newcommand{\col}{\text{Col}}\) \(\renewcommand{\row}{\text{Row}}\) \(\newcommand{\nul}{\text{Nul}}\) \(\newcommand{\var}{\text{Var}}\) \(\newcommand{\corr}{\text{corr}}\) \(\newcommand{\len}[1]{\left|#1\right|}\) \(\newcommand{\bbar}{\overline{\bvec}}\) \(\newcommand{\bhat}{\widehat{\bvec}}\) \(\newcommand{\bperp}{\bvec^\perp}\) \(\newcommand{\xhat}{\widehat{\xvec}}\) \(\newcommand{\vhat}{\widehat{\vvec}}\) \(\newcommand{\uhat}{\widehat{\uvec}}\) \(\newcommand{\what}{\widehat{\wvec}}\) \(\newcommand{\Sighat}{\widehat{\Sigma}}\) \(\newcommand{\lt}{<}\) \(\newcommand{\gt}{>}\) \(\newcommand{\amp}{&}\) \(\definecolor{fillinmathshade}{gray}{0.9}\)

    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?