46
50

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

Linux で「メモリが!」というときに叩きたいコマンド

Posted at

vmstat とか top もあるけどね。

free

free があると心が落ち着きますね。cached が大きいだけだと安心しますね。

$ free
             total       used       free     shared    buffers     cached
Mem:       3860692    1521364    2339328          0      85388    1049928
-/+ buffers/cache:     386048    3474644
Swap:            0          0          0

ps auxwwO-r

プロセスごとのメモリはこれで見れるかな。まぁ O-r はソートなので好きなのに変えたら良い。

$ ps auxwwO-r | head
USER       PID %CPU %MEM    VSZ   RSS TTY      STAT START   TIME COMMAND
root      6912  0.0  0.1 111688  4276 ?        Ss   Apr01   0:00 sshd: ec2-user [priv]
ec2-user  6914  0.0  0.0 111820  2540 ?        S    Apr01   0:02 sshd: ec2-user@pts/0,pts/1,pts/2
ec2-user  8151  0.4  0.0 121992  2420 pts/1    Ss+  Apr01   5:13 -bash
ec2-user  9257  0.0  0.0 117488  2188 pts/0    Ss+  Apr01   0:00 -bash
ec2-user 29292  0.0  0.0 117384  2132 pts/2    Ss   04:11   0:00 -bash
root      1593  0.0  0.0  89044  2116 ?        Ss   Mar13   0:27 sendmail: accepting connections
smmsp     1600  0.0  0.0  80500  1692 ?        Ss   Mar13   0:00 sendmail: Queue runner@01:00:00 for /var/spool/clientmqueue
root     23677  0.0  0.0 183768  1416 ?        Sl   Mar29   0:00 /sbin/rsyslogd -i /var/run/syslogd.pid -c 5
root     23590  0.0  0.0  77936  1288 ?        Ss   Mar29   0:00 /usr/sbin/sshd

cat /proc/meminfo

結果が長いし何だか良く分からないぜ! でも Active とか Inactive とか字面に騙されちゃいけないってじっちゃんが言ってました。きっと /proc/meminfoを考える - めもめも を通りすがると色々分かるようになるに違いありません。

$ cat /proc/meminfo | head -n 25
MemTotal:        3860692 kB
MemFree:         2339320 kB
Buffers:           85388 kB
Cached:          1049928 kB
SwapCached:            0 kB
Active:           443068 kB
Inactive:         704024 kB
Active(anon):      11788 kB
Inactive(anon):      392 kB
Active(file):     431280 kB
Inactive(file):   703632 kB
Unevictable:           0 kB
Mlocked:               0 kB
SwapTotal:             0 kB
SwapFree:              0 kB
Dirty:                 0 kB
Writeback:             0 kB
AnonPages:         11824 kB
Mapped:             7440 kB
Shmem:               404 kB
Slab:             329724 kB
SReclaimable:     318664 kB
SUnreclaim:        11060 kB
KernelStack:         544 kB
PageTables:         1976 kB

dstat -tclmgdnpy --tcp 5

ぼーっと眺めていると、それだけで癒されますね。もぉ熱帯魚なんて飼わなくても大丈夫です。どんだけ増すかはターミナルの幅と相談しましょう

$ dstat -tclmgdnpy --tcp 5
----system---- ----total-cpu-usage---- ---load-avg--- ------memory-usage----- ---paging-- -dsk/total- -net/total- ---procs--- ---system-- ----tcp-sockets----
  date/time   |usr sys idl wai hiq siq| 1m   5m  15m | used  buff  cach  free|  in   out | read  writ| recv  send|run blk new| int   csw |lis act syn tim clo
02-04 04:42:15|  0   0 100   0   0   0|   0 0.01 0.05| 381M 83.5M 1026M 2279M|   0     0 |2750B 3152B|   0     0 |  0   0 1.3|  27    20 |  3   1   0   0   0
02-04 04:42:20|  0   0 100   0   0   0|   0 0.01 0.05| 381M 83.5M 1026M 2279M|   0     0 |   0     0 |  66B  133B|  0   0   0|  22    13 |  3   1   0   0   0
02-04 04:42:25|  0   0 100   0   0   0|   0 0.01 0.05| 381M 83.5M 1026M 2279M|   0     0 |   0     0 |  66B  120B|  0   0   0|  21    13 |  3   1   0   0   0
02-04 04:42:30|  0   0 100   0   0   0|   0 0.01 0.05| 381M 83.5M 1026M 2279M|   0     0 |   0     0 |  66B  120B|  0   0   0|  19    12 |  3   1   0   0   0
02-04 04:42:35|  0   0 100   0   0   0|   0 0.01 0.05| 381M 83.5M 1026M 2279M|   0     0 |   0     0 |  66B  117B|  0   0   0|  21    12 |  3   1   0   0   0

sudo slabtop -o -s c

こっちはあんまり癒されませんね。dentry め!! という感じです。

$ sudo slabtop -o -s c | head -n 15
 Active / Total Objects (% used)    : 1695897 / 1700554 (99.7%)
 Active / Total Slabs (% used)      : 71781 / 71781 (100.0%)
 Active / Total Caches (% used)     : 67 / 96 (69.8%)
 Active / Total Size (% used)       : 323362.33K / 325133.74K (99.5%)
 Minimum / Average / Maximum Object : 0.01K / 0.19K / 8.00K

  OBJS ACTIVE  USE OBJ SIZE  SLABS OBJ/SLAB CACHE SIZE NAME
1297464 1297464 100%    0.19K  61784       21    247136K dentry
 37074  37074 100%    0.86K   1002       37     32064K ext4_inode_cache
263913 263913 100%    0.10K   6767       39     27068K buffer_head
 14287  14287 100%    0.55K    511       28      8176K radix_tree_node
  5336   4999  93%    0.55K    184       29      2944K inode_cache
 26860  25982  96%    0.05K    316       85      1264K shared_policy_node
  8604   8604 100%    0.11K    239       36       956K sysfs_dir_cache
  2912   1971  67%    0.25K     91       32       728K kmalloc-256

while true; do date '+%H:%M:%S ' | tr -d '\n'; cat /proc/sys/fs/dentry-state; sleep 5; done

こんなもんそうそう叩く機会は無いか....

$ while true; do date '+%H:%M:%S ' | tr -d '\n'; cat /proc/sys/fs/dentry-state; sleep 5; done
05:01:00 1297322        1291697 45      0       0       0
05:01:05 1297322        1291697 45      0       0       0
05:01:10 1297322        1291697 45      0       0       0
05:01:15 1297322        1291697 45      0       0       0
46
50
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
46
50

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?