LoginSignup
10
9

More than 3 years have passed since last update.

Linuxのfreeコマンドでサーバーのメモリ状況を確認する

Last updated at Posted at 2020-02-29

環境

  • OS:CentOS Linux release 7.7.1908
[root@CENTOS7 ~]# cat /etc/redhat-release
CentOS Linux release 7.7.1908 (Core)
[root@CENTOS7 ~]#

1. freeコマンドの出力内容の見方

freeコマンドでシステム内のメモリの状況を確認することができます。
出力結果は以下の通りです。

freeコマンドの出力結果
[root@CENTOS7 ~]# free
              total        used        free      shared  buff/cache   available
Mem:        1014820      184368      684116        6928      146336      683684
Swap:       1679356           0     1679356
[root@CENTOS7 ~]#

それぞれの項目は以下の通りです。

項目 内容
total 合計メモリ量
used メモリ使用量(実際にプロセスで使用されているメモリ量)
free 全く使われていない未割り当てのメモリ量
shared 共有メモリで使用しているメモリ量
buff/cache ファイルバッファ+キャッシュメモリに使われているメモリ量
available プロセスが利用できるメモリ量

2020/03/13 追記

注意事項

  • 「used」は「total - free - buffers - cache」の値となります。
  • 「free」に「buffers」と「cache」は含まれません。
  • 空きメモリがある限り、基本的に「buff/cache」はどんどん増加します。
  • 空きメモリが無くなれば、使用中のメモリの増加に応じて、「buff/cache」が減ります。

2. freeコマンドのオプション

短いオプション 長いオプション 内容
-b --bytes メモリ量をバイト単位で表示
-k --kilo メモリ量をキロバイト単位で表示
-m --mega メモリ量をメガバイト単位で表示
-g --giga メモリの量をギガバイト単位で表示
--tera メモリの量をテラバイト単位で表示
--peta メモリ量をペタバイト単位で表示
-h --human 人が読みやすい単位で表示
-w --wide ワイドモードで表示
-c 回数 --count 回数 出力する回数を指定(デフォルトは1回出力して終了)
-l --lohi LowメモリとHighメモリの状況を表示
Lowメモリ:Linuxカーネルが使用する領域
Highメモリ:プロセスが使用するメモリ領域
-s 間隔 --seconds 間隔 出力の間隔を「ss.tt秒」で指定(デフォルトは1回出力して終了)
--si 単位を換算する際に1024ではなく1000で割って計算
-t --total 物理メモリとスワップメモリの合計を示す行を表示

参考

manコマンドのマニュアル(英文)

FREE(1)                          User Commands                         FREE(1)



NAME
       free - Display amount of free and used memory in the system

SYNOPSIS
       free [options]

DESCRIPTION
       free  displays the total amount of free and used physical and swap mem‐
       ory in the system, as well as the buffers and caches used by  the  ker‐
       nel.  The  information  is  gathered by parsing /proc/meminfo. The dis‐
       played columns are:

       total  Total installed memory (MemTotal and SwapTotal in /proc/meminfo)

       used   Used memory (calculated as total - free - buffers - cache)

       free   Unused memory (MemFree and SwapFree in /proc/meminfo)

       shared Memory used (mostly) by tmpfs (Shmem in /proc/meminfo, available
              on kernels 2.6.32, displayed as zero if not available)

       buffers
              Memory used by kernel buffers (Buffers in /proc/meminfo)

       cache  Memory used by the page cache and slabs (Cached and SReclaimable
              in /proc/meminfo)

       buff/cache
              Sum of buffers and cache

       available
              Estimation of how much memory  is  available  for  starting  new
              applications,  without swapping. Unlike the data provided by the
              cache or free fields, this field takes into account  page  cache
              and also that not all reclaimable memory slabs will be reclaimed
              due to items being in use (MemAvailable in /proc/meminfo, avail‐
              able on kernels 3.14, emulated on kernels 2.6.27+, otherwise the
              same as free)

OPTIONS
       -b, --bytes
              Display the amount of memory in bytes.

       -k, --kilo
              Display the amount of memory in kilobytes.  This is the default.

       -m, --mega
              Display the amount of memory in megabytes.

       -g, --giga
              Display the amount of memory in gigabytes.

       --tera Display the amount of memory in terabytes.

       --peta Display the amount of memory in petabytes.

       -h, --human
              Show all output fields automatically scaled  to  shortest  three
              digit  unit and display the units of print out.  Following units
              are used.

                B = bytes
                K = kilos
                M = megas
                G = gigas
                T = teras
                P = petas

              If unit is missing, and you have exabyte of  RAM  or  swap,  the
              number  is  in  terabytes  and columns might not be aligned with
              header.

       -w, --wide
              Switch to the wide mode. The wide  mode  produces  lines  longer
              than  80 characters. In this mode buffers and cache are reported
              in two separate columns.

       -c, --count count
              Display the result count times.  Requires the -s option.

       -l, --lohi
              Show detailed low and high memory statistics.

       -s, --seconds seconds
              Continuously display the result delay seconds  apart.   You  may
              actually  specify any floating point number for delay, usleep(3)
              is used for microsecond resolution delay times.

       --si   Use power of 1000 not 1024.

       -t, --total
              Display a line showing the column totals.

       --help Print help.

       -V, --version
              Display version information.

FILES
       /proc/meminfo
              memory information

SEE ALSO
       ps(1), slabtop(1), top(1), vmstat(8).

AUTHORS
       Written by Brian Edmonds.

REPORTING BUGS
       Please send bug reports to ?procps@freelists.org?



procps-ng                          July 2014                           FREE(1)

manコマンドのマニュアル(日本語)(google翻訳)

FREE(1)                          User Commands                         FREE(1)



NAME
       free - システムの空きメモリと使用済みメモリの量を表示する


SYNOPSIS
       free [options]

DESCRIPTION
       freeは、システム内の空きおよび使用済みの物理メモリとスワップメモリの合計量、
       およびカーネルが使用するバッファとキャッシュを表示します。
       情報は、「/proc/meminfo」を解析することにより収集されます。 
       表示される列は次のとおりです。

       total  合計インストール済みメモリ(「/proc/meminfo」の「MemTotal」および「SwapTotal」)

       used   使用済みメモリ(「total - free - buffers - cache」として計算)

       free   未使用メモリ(「/proc/meminfo」の「MemFree」および「SwapFree」)

       shared (主に)tmpfsが使用するメモリ(「/proc/meminfo」の「Shmem」、カーネル2.6.32で使用可能、使用不可の場合はゼロとして表示)

       buffers
              カーネルバッファーが使用するメモリ(「/proc/meminfo」の「Buffers」)

       cache  ページキャッシュとスラブで使用されるメモリ(「/proc/meminfo」の「Cached」および「SReclaimable」)

       buff/cache
              バッファーとキャッシュの合計

       available
              スワップなしで、新しいアプリケーションを開始するために使用可能なメモリの量の推定。
              キャッシュまたは空きフィールドによって提供されるデータとは異なり、
              このフィールドはページキャッシュを考慮し、使用中のアイテムのために
              すべての回収可能なメモリスラブが回収されるわけではありません
              (「/proc/meminfo」の「MemAvailable」、カーネル3.14で利用可能、
                 エミュレート カーネル2.6.27以降、それ以外はfreeと同じ)
OPTIONS
       -b, --bytes
              メモリ量をバイト単位で表示します。

       -k, --kilo
              メモリ量をキロバイト単位で表示します。 これがデフォルトです。

       -m, --mega
              メモリ量をメガバイト単位で表示します。

       -g, --giga
              メモリの量をギガバイト単位で表示します。

       --tera メモリの量をテラバイト単位で表示します。

       --peta メモリ量をペタバイト単位で表示します。

       -h, --human
              最短3桁単位に自動的にスケーリングされたすべての出力フィールドを表示し、
              印刷単位を表示します。 以下のユニットが使用されます。

                B = bytes
                K = kilos
                M = megas
                G = gigas
                T = teras
                P = petas

              ユニットがなく、エクサバイトのRAMまたはスワップがある場合、
              数値はテラバイト単位であり、列はヘッダーと整列していない可能性があります。

       -w, --wide
              ワイドモードに切り替えます。 ワイドモードでは、80文字より長い行が生成されます。
              このモードでは、バッファーとキャッシュは2つの別々の列で報告されます。

       -c, --count count
              結果のカウント回数を表示します。 -sオプションが必要です。

       -l, --lohi
              詳細なlowおよびhighメモリ統計を表示します。

       -s, --seconds seconds
              結果の遅延を秒単位で継続的に表示します。 
              実際には遅延に任意の浮動小数点数を指定できます。
              usleep(3)はマイクロ秒の解像度遅延時間に使用されます。

       --si   Use power of 1000 not 1024.
              1024ではなく1000の累乗を使用します。

       -t, --total
              列の合計を示す行を表示します。

       --help Print help.
              ヘルプを印刷します。

       -V, --version
              バージョン情報を表示します。

FILES
       /proc/meminfo
              memory information

SEE ALSO
       ps(1), slabtop(1), top(1), vmstat(8).

AUTHORS
       Written by Brian Edmonds.

REPORTING BUGS
       Please send bug reports to ⟨procps@freelists.org⟩



procps-ng                          July 2014                           FREE(1)

以上

10
9
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
10
9