ウェブサイト検索

Smem - Linux のプロセスごとおよびユーザーごとのメモリ消費量をレポートします


メモリ使用量の監視という点でのメモリ管理は、Linux システムで行うべき重要なことの 1 つです。さまざまな Linux ディストリビューションでメモリ使用量を監視するために利用できるツールが多数あります。しかし、それらは異なる方法で動作します。このガイドでは、smem と呼ばれるそのようなツールの 1 つをインストールして使用する方法を見ていきます。

お見逃しなく: Linux パフォーマンスを監視する 20 のコマンド ライン ツール

Smem は、Linux システム上のメモリ使用量に関するさまざまなレポートをユーザーに提供するコマンドライン メモリ レポート ツールです。 smem にはユニークな点が 1 つあり、他の従来のメモリ レポート ツールとは異なり、アプリケーションやライブラリによるメモリ使用量をより意味のある表現であるPSS (比例セット サイズ) をレポートします。仮想メモリの設定。

既存の従来型ツールは主に、物理メモリ スキームにおけるメモリ使用量を監視するための標準的な手段であるRSS (常駐セット サイズ) の読み取りに重点を置いていますが、アプリケーションによるメモリ使用量を過大評価する傾向があります。 。

一方、PSS は、仮想メモリ スキームでアプリケーションとライブラリが使用するメモリの「公平なシェア」を決定することにより、合理的な尺度を提供します。

Linux システムでのメモリ消費を理解するには、このガイド (メモリ RSS および PSS に関する) を読むことができますが、smem の機能のいくつかを見てみましょう。

Smemツールの特徴

  1. システム概要一覧
  2. リスト、およびプロセス、マッピング、またはユーザーによるフィルタリング
  3. /proc ファイルシステムからのデータの使用
  4. 複数のデータソースからの構成可能なリスト列
  5. 構成可能な出力単位とパーセンテージ
  6. リストのヘッダーと合計を簡単に設定できます
  7. ディレクトリミラーまたは圧縮tarファイルからのデータスナップショットの使用
  8. 組み込みのチャート生成メカニズム
  9. 組み込みシステムで使用される軽量キャプチャツール

Linux に Smem – メモリレポートツールをインストールする方法

smem のインストールを続行する前に、システムが次の要件を満たしている必要があります。

  1. 最新のカーネル (> 2.6.27 程度)
  2. Python の最新バージョン (2.4 程度)
  3. チャート生成用のオプションの matplotlib ライブラリ

現在の Linux ディストリビューションのほとんどには、Python 2 または 3 をサポートする最新のカーネル バージョンが付属しているため、唯一の要件はmatplotlib ライブラリをインストールすることです。素敵なチャートを生成するために使用されます。

RHEL、CentOS、Fedora 上

まず EPEL (Extra Packages for Enterprise Linux) リポジトリを有効にしてから、次のようにインストールします。

yum install smem python-matplotlib python-tk

Debian と Ubuntu について

sudo apt-get install smem

Linux Mint について

sudo apt-get install smem python-matplotlib python-tk

Arch Linux 上で

この AUR リポジトリを使用します。

Linux のメモリ レポート ツール Smem の使用方法

すべてのシステム ユーザーによるシステム全体のメモリ使用量のレポートを表示するには、次のコマンドを実行します。

$ sudo smem 
 PID User     Command                         Swap      USS      PSS      RSS 
 6367 tecmint  cat                                0      100      145     1784 
 6368 tecmint  cat                                0      100      147     1676 
 2864 tecmint  /usr/bin/ck-launch-session         0      144      165     1780 
 7656 tecmint  gnome-pty-helper                   0      156      178     1832 
 5758 tecmint  gnome-pty-helper                   0      156      179     1916 
 1441 root     /sbin/getty -8 38400 tty2          0      152      184     2052 
 1434 root     /sbin/getty -8 38400 tty5          0      156      187     2060 
 1444 root     /sbin/getty -8 38400 tty3          0      156      187     2060 
 1432 root     /sbin/getty -8 38400 tty4          0      156      188     2124 
 1452 root     /sbin/getty -8 38400 tty6          0      164      196     2064 
 2619 root     /sbin/getty -8 38400 tty1          0      164      196     2136 
 3544 tecmint  sh -c /usr/lib/linuxmint/mi        0      212      224     1540 
 1504 root     acpid -c /etc/acpi/events -        0      220      236     1604 
 3311 tecmint  syndaemon -i 0.5 -K -R             0      252      292     2556 
 3143 rtkit    /usr/lib/rtkit/rtkit-daemon        0      300      326     2548 
 1588 root     cron                               0      292      333     2344 
 1589 avahi    avahi-daemon: chroot helpe         0      124      334     1632 
 1523 root     /usr/sbin/irqbalance               0      316      343     2096 
  585 root     upstart-socket-bridge --dae        0      328      351     1820 
 3033 tecmint  /usr/bin/dbus-launch --exit        0      328      360     2160 
 1346 root     upstart-file-bridge --daemo        0      348      371     1776 
 2607 root     /usr/bin/xdm                       0      188      378     2368 
 1635 kernoops /usr/sbin/kerneloops               0      352      386     2684 
  344 root     upstart-udev-bridge --daemo        0      400      427     2132 
 2960 tecmint  /usr/bin/ssh-agent /usr/bin        0      480      485      992 
 3468 tecmint  /bin/dbus-daemon --config-f        0      344      515     3284 
 1559 avahi    avahi-daemon: running [tecm        0      284      517     3108 
 7289 postfix  pickup -l -t unix -u -c            0      288      534     2808 
 2135 root     /usr/lib/postfix/master            0      352      576     2872 
 2436 postfix  qmgr -l -t unix -u                 0      360      606     2884 
 1521 root     /lib/systemd/systemd-logind        0      600      650     3276 
 2222 nobody   /usr/sbin/dnsmasq --no-reso        0      604      669     3288 
....

通常のユーザーがsmemを実行すると、ユーザーが開始したプロセスごとのメモリ使用量が表示され、 プロセスはPSSの高い順に並べられます。

ユーザー aaronkilik によって開始されたプロセスによるメモリ使用量について、システム上の以下の出力を見てください。

$ smem
 PID User     Command                         Swap      USS      PSS      RSS 
 6367 tecmint  cat                                0      100      145     1784 
 6368 tecmint  cat                                0      100      147     1676 
 2864 tecmint  /usr/bin/ck-launch-session         0      144      166     1780 
 3544 tecmint  sh -c /usr/lib/linuxmint/mi        0      212      224     1540 
 3311 tecmint  syndaemon -i 0.5 -K -R             0      252      292     2556 
 3033 tecmint  /usr/bin/dbus-launch --exit        0      328      360     2160 
 3468 tecmint  /bin/dbus-daemon --config-f        0      344      515     3284 
 3122 tecmint  /usr/lib/gvfs/gvfsd                0      656      801     5552 
 3471 tecmint  /usr/lib/at-spi2-core/at-sp        0      708      864     5992 
 3396 tecmint  /usr/lib/gvfs/gvfs-mtp-volu        0      804      914     6204 
 3208 tecmint  /usr/lib/x86_64-linux-gnu/i        0      892     1012     6188 
 3380 tecmint  /usr/lib/gvfs/gvfs-afc-volu        0      820     1024     6396 
 3034 tecmint  //bin/dbus-daemon --fork --        0      920     1081     3040 
 3365 tecmint  /usr/lib/gvfs/gvfs-gphoto2-        0      972     1099     6052 
 3228 tecmint  /usr/lib/gvfs/gvfsd-trash -        0      980     1153     6648 
 3107 tecmint  /usr/lib/dconf/dconf-servic        0     1212     1283     5376 
 6399 tecmint  /opt/google/chrome/chrome -        0      144     1409    10732 
 3478 tecmint  /usr/lib/x86_64-linux-gnu/g        0     1724     1820     6320 
 7365 tecmint  /usr/lib/gvfs/gvfsd-http --        0     1352     1884     8704 
 6937 tecmint  /opt/libreoffice5.0/program        0     1140     2328     5040 
 3194 tecmint  /usr/lib/x86_64-linux-gnu/p        0     1956     2405    14228 
 6373 tecmint  /opt/google/chrome/nacl_hel        0     2324     2541     8908 
 3313 tecmint  /usr/lib/gvfs/gvfs-udisks2-        0     2460     2754     8736 
 3464 tecmint  /usr/lib/at-spi2-core/at-sp        0     2684     2823     7920 
 5771 tecmint  ssh -p 4521 [email         0     2544     2864     6540 
 5759 tecmint  /bin/bash                          0     2416     2923     5640 
 3541 tecmint  /usr/bin/python /usr/bin/mi        0     2584     3008     7248 
 7657 tecmint  bash                               0     2516     3055     6028 
 3127 tecmint  /usr/lib/gvfs/gvfsd-fuse /r        0     3024     3126     8032 
 3205 tecmint  mate-screensaver                   0     2520     3331    18072 
 3171 tecmint  /usr/lib/mate-panel/notific        0     2860     3495    17140 
 3030 tecmint  x-session-manager                  0     4400     4879    17500 
 3197 tecmint  mate-volume-control-applet         0     3860     5226    23736 
...

smem の使用中に呼び出すオプションは多数あります。たとえば、システム全体のメモリ消費量を表示するには、次のコマンドを実行します。

$ sudo smem -w
Area                           Used      Cache   Noncache 
firmware/hardware                 0          0          0 
kernel image                      0          0          0 
kernel dynamic memory       1425320    1291412     133908 
userspace memory            2215368     451608    1763760 
free memory                 4424936    4424936          0 

ユーザーごとのメモリ使用量を表示するには、以下のコマンドを実行します。

$ sudo smem -u
User     Count     Swap      USS      PSS      RSS 
rtkit        1        0      300      326     2548 
kernoops     1        0      352      385     2684 
avahi        2        0      408      851     4740 
postfix      2        0      648     1140     5692 
messagebus     1        0     1012     1173     3320 
syslog       1        0     1396     1419     3232 
www-data     2        0     5100     6572    13580 
mpd          1        0     7416     8302    12896 
nobody       2        0     4024    11305    24728 
root        39        0   323876   353418   496520 
tecmint     64        0  1652888  1815699  2763112 

次のようにマッピングしてメモリ使用量をレポートすることもできます。

$ sudo smem -m
Map                                       PIDs   AVGPSS      PSS 
/dev/fb0                                     1        0        0 
/home/tecmint/.cache/fontconfig/7ef2298f    18        0        0 
/home/tecmint/.cache/fontconfig/c57959a1    18        0        0 
/home/tecmint/.local/share/mime/mime.cac    15        0        0 
/opt/google/chrome/chrome_material_100_p     9        0        0 
/opt/google/chrome/chrome_material_200_p     9        0        0 
/usr/lib/x86_64-linux-gnu/gconv/gconv-mo    41        0        0 
/usr/share/icons/Mint-X-Teal/icon-theme.    15        0        0 
/var/cache/fontconfig/0c9eb80ebd1c36541e    20        0        0 
/var/cache/fontconfig/0d8c3b2ac0904cb8a5    20        0        0 
/var/cache/fontconfig/1ac9eb803944fde146    20        0        0 
/var/cache/fontconfig/3830d5c3ddfd5cd38a    20        0        0 
/var/cache/fontconfig/385c0604a188198f04    20        0        0 
/var/cache/fontconfig/4794a0821666d79190    20        0        0 
/var/cache/fontconfig/56cf4f4769d0f4abc8    20        0        0 
/var/cache/fontconfig/767a8244fc0220cfb5    20        0        0 
/var/cache/fontconfig/8801497958630a81b7    20        0        0 
/var/cache/fontconfig/99e8ed0e538f840c56    20        0        0 
/var/cache/fontconfig/b9d506c9ac06c20b43    20        0        0 
/var/cache/fontconfig/c05880de57d1f5e948    20        0        0 
/var/cache/fontconfig/dc05db6664285cc2f1    20        0        0 
/var/cache/fontconfig/e13b20fdb08344e0e6    20        0        0 
/var/cache/fontconfig/e7071f4a29fa870f43    20        0        0 
....

smem 出力をフィルタリングするオプションもあります。ここでは 2 つの例を見ていきます。

ユーザー名で出力をフィルタリングするには、以下のように -u または --userfilter="regex" オプションを呼び出します。

$ sudo smem -u
User     Count     Swap      USS      PSS      RSS 
rtkit        1        0      300      326     2548 
kernoops     1        0      352      385     2684 
avahi        2        0      408      851     4740 
postfix      2        0      648     1140     5692 
messagebus     1        0     1012     1173     3320 
syslog       1        0     1400     1423     3236 
www-data     2        0     5100     6572    13580 
mpd          1        0     7416     8302    12896 
nobody       2        0     4024    11305    24728 
root        39        0   323804   353374   496552 
tecmint     64        0  1708900  1871766  2819212 

出力をプロセス名でフィルターするには、次のように -P または --processfilter="regex" オプションを呼び出します。

$ sudo smem --processfilter="firefox"
PID User     Command                         Swap      USS      PSS      RSS 
 9212 root     sudo smem --processfilter=f        0     1172     1434     4856 
 9213 root     /usr/bin/python /usr/bin/sm        0     7368     7793    11984 
 4424 tecmint  /usr/lib/firefox/firefox           0   931732   937590   961504 

出力の書式設定は非常に重要な場合があり、メモリ レポートの書式設定に役立つオプションがあり、以下でいくつかの例を見ていきます。

レポートに目的の列を表示するには、次のように -c または --columns オプションを使用します。

$ sudo smem -c "name user pss rss"
Name                     User          PSS      RSS 
cat                      tecmint       145     1784 
cat                      tecmint       147     1676 
ck-launch-sessi          tecmint       165     1780 
gnome-pty-helpe          tecmint       178     1832 
gnome-pty-helpe          tecmint       179     1916 
getty                    root          184     2052 
getty                    root          187     2060 
getty                    root          187     2060 
getty                    root          188     2124 
getty                    root          196     2064 
getty                    root          196     2136 
sh                       tecmint       224     1540 
acpid                    root          236     1604 
syndaemon                tecmint       296     2560 
rtkit-daemon             rtkit         326     2548 
cron                     root          333     2344 
avahi-daemon             avahi         334     1632 
irqbalance               root          343     2096 
upstart-socket-          root          351     1820 
dbus-launch              tecmint       360     2160 
upstart-file-br          root          371     1776 
xdm                      root          378     2368 
kerneloops               kernoops      386     2684 
upstart-udev-br          root          427     2132 
ssh-agent                tecmint       485      992 
...

以下のコマンドのように、-p オプションを呼び出してメモリ使用量をパーセンテージでレポートできます。

$ sudo smem -p
 PID User     Command                         Swap      USS      PSS      RSS 
 6367 tecmint  cat                            0.00%    0.00%    0.00%    0.02% 
 6368 tecmint  cat                            0.00%    0.00%    0.00%    0.02% 
 9307 tecmint  sh -c { sudo /usr/lib/linux    0.00%    0.00%    0.00%    0.02% 
 2864 tecmint  /usr/bin/ck-launch-session     0.00%    0.00%    0.00%    0.02% 
 3544 tecmint  sh -c /usr/lib/linuxmint/mi    0.00%    0.00%    0.00%    0.02% 
 5758 tecmint  gnome-pty-helper               0.00%    0.00%    0.00%    0.02% 
 7656 tecmint  gnome-pty-helper               0.00%    0.00%    0.00%    0.02% 
 1441 root     /sbin/getty -8 38400 tty2      0.00%    0.00%    0.00%    0.03% 
 1434 root     /sbin/getty -8 38400 tty5      0.00%    0.00%    0.00%    0.03% 
 1444 root     /sbin/getty -8 38400 tty3      0.00%    0.00%    0.00%    0.03% 
 1432 root     /sbin/getty -8 38400 tty4      0.00%    0.00%    0.00%    0.03% 
 1452 root     /sbin/getty -8 38400 tty6      0.00%    0.00%    0.00%    0.03% 
 2619 root     /sbin/getty -8 38400 tty1      0.00%    0.00%    0.00%    0.03% 
 1504 root     acpid -c /etc/acpi/events -    0.00%    0.00%    0.00%    0.02% 
 3311 tecmint  syndaemon -i 0.5 -K -R         0.00%    0.00%    0.00%    0.03% 
 3143 rtkit    /usr/lib/rtkit/rtkit-daemon    0.00%    0.00%    0.00%    0.03% 
 1588 root     cron                           0.00%    0.00%    0.00%    0.03% 
 1589 avahi    avahi-daemon: chroot helpe     0.00%    0.00%    0.00%    0.02% 
 1523 root     /usr/sbin/irqbalance           0.00%    0.00%    0.00%    0.03% 
  585 root     upstart-socket-bridge --dae    0.00%    0.00%    0.00%    0.02% 
 3033 tecmint  /usr/bin/dbus-launch --exit    0.00%    0.00%    0.00%    0.03% 
....

以下のコマンドは、出力の各列の最後に合計を表示します。

$ sudo smem -t
PID User     Command                         Swap      USS      PSS      RSS 
 6367 tecmint  cat                                0      100      139     1784 
 6368 tecmint  cat                                0      100      141     1676 
 9307 tecmint  sh -c { sudo /usr/lib/linux        0       96      158     1508 
 2864 tecmint  /usr/bin/ck-launch-session         0      144      163     1780 
 3544 tecmint  sh -c /usr/lib/linuxmint/mi        0      108      170     1540 
 5758 tecmint  gnome-pty-helper                   0      156      176     1916 
 7656 tecmint  gnome-pty-helper                   0      156      176     1832 
 1441 root     /sbin/getty -8 38400 tty2          0      152      181     2052 
 1434 root     /sbin/getty -8 38400 tty5          0      156      184     2060 
 1444 root     /sbin/getty -8 38400 tty3          0      156      184     2060 
 1432 root     /sbin/getty -8 38400 tty4          0      156      185     2124 
 1452 root     /sbin/getty -8 38400 tty6          0      164      193     2064 
 2619 root     /sbin/getty -8 38400 tty1          0      164      193     2136 
 1504 root     acpid -c /etc/acpi/events -        0      220      232     1604 
 3311 tecmint  syndaemon -i 0.5 -K -R             0      260      298     2564 
 3143 rtkit    /usr/lib/rtkit/rtkit-daemon        0      300      324     2548 
 1588 root     cron                               0      292      326     2344 
 1589 avahi    avahi-daemon: chroot helpe         0      124      332     1632 
 1523 root     /usr/sbin/irqbalance               0      316      340     2096 
  585 root     upstart-socket-bridge --dae        0      328      349     1820 
 3033 tecmint  /usr/bin/dbus-launch --exit        0      328      359     2160 
 1346 root     upstart-file-bridge --daemo        0      348      370     1776 
 2607 root     /usr/bin/xdm                       0      188      375     2368 
 1635 kernoops /usr/sbin/kerneloops               0      352      384     2684 
  344 root     upstart-udev-bridge --daemo        0      400      426     2132 
.....
-------------------------------------------------------------------------------
  134 11                                          0  2171428  2376266  3587972 

さらに、使用できるグラフィカル レポートのオプションもあり、このサブセクションで詳しく説明します。

プロセスとそのPSS 値とRSS 値の棒グラフを作成できます。以下の例では、root ユーザーが所有するプロセスの棒グラフを作成します。

垂直面はプロセスのPSSRSSの測定値を示し、水平面は各ルート ユーザー プロセスを表します。

$ sudo smem --userfilter="root" --bar pid -c"pss rss"

PSS または RSS の値に基づいて、プロセスとそのメモリ消費量を示す円グラフを作成することもできます。以下のコマンドは、 値を測定しているルート ユーザーが所有するプロセスの円グラフを出力します。

--pie 名は名前によるラベルを意味し、-s オプションは PSS 値による並べ替えに役立ちます。

$ sudo smem --userfilter="root" --pie name -s pss

グラフのラベル付けに使用される PSSRSS 以外にも、次のような既知のフィールドが多数あります。

ヘルプが必要な場合は、「smem -h」と入力するか、手動入力ページにアクセスしてください。

smem についてはここで終了しますが、それをよりよく理解するには、マニュアルページにある他の多くのオプションと組み合わせて使用してください。いつものように、以下のコメントセクションを使用して、考えや懸念を表明できます。

参考リンク: https://www.selenic.com/smem/