vmstat
- 仮想メモリの統計情報の表示
- 仮想メモリはコンピュータの黎明期よりある仕組み
- プロセスは 0 番地から始まる仮想メモリ上で動くように作られる (実メモリ上のどこに配置されるかは考えなくていい)
- 本当にCPUから使われるときだけ実メモリにマッピングされて CPU で実行される
- その仲立ちをやるのが OS ってやつ
7Vlbb9sgFP41lraXyhhfH3Nr97BJkbpp7SOxSYxGTIRJ4+zXD2p8d5s0cZpW2lPgcMDwfR+cAzHgZJ3dcbSJf7AIU8Myo8yAU8OygGP58kdZ9rnFN83csOIk0k6V4Z78xdpYuG1JhNOGo2CMCrJpGkOWJDgUDRvinO2abktGm1/doBXuGO5DRLvW3yQSsV6F5VX2b5is4uLLwA3yljUqnPVK0hhFbFczwZkBJ5wxkZfW2QRTBV6BS97v9oXWcmIcJ+KoDpqJJ0S3enF6YmJfrJazbRJh1cE04HgXE4HvNyhUrTvJr7TFYk1lDciiHg5zgbMX5wTKlUqJYLbGgu+lS9ZkuRRHXt1VSAeFXuIayranjUizuypHrgCQBY1BPx52F44ZNHxoBJ4ujKbPBcsYj4tCYMxujfHECMB52FG0wHTOUiIIS6QtlIBhLhsUnETK73vLQTA1AqJk1es+0g0LJgRbD0OO1SQHWF12bNjDDnAGYMc5i50zlf0Z2Cn3wFXosXrosRUTo5kxcxU9Y1jwBIpCQeFoJLt+ce2f46/n8bQklE4YZfy5L1wusRuG0p4Kzv7gWkvkBQvTHAZ4p4W763Rwh14P7u4AsMMO7JP5rw6GB1BD6SaPlEuSKaSHAAWasIGK7cAOKn4PKP4AoLg9WnSUEIPbAxL0785V4BDQtYIghN2NXPoMLSjvI+7jyMF+ZPftY99aQNcdah9fcSMPnYtd5SQslfqaci8EYHBZAN9HgtC7HoDFifIagjiJRuoOJWsJS3ATsSa8csV8/6AqNzJ30/VH7fpcmWZ11+m+qGVEPNTKj7Vy1UVVih75NHHUubi1YJdLYVse4saOE4ivsKglMV1yauA7PeAXNo4pEuSpOYk+RvQX5ozI6VXcB03uy1ytGCKfvO5Vv9e1BrLtlojaMTVfcmegZ4GUyz5OM2BYzWjqwdHUlyoDb5HYYIIB11VMm2j7RMUAp5msWdC5mGJ6LgqfL9AB+4hU4VLndDfn/4SRzrkmgj1vCcNEOmD6jXPoxrS9Q+FO1eaYE7kM9UbwrjEw6B5p3v8Y+MYTree6OZCa/IaazJvAP0VMx0vjw+jANl/Ig9+qA6f1OCOFcDEd9Fyd2zpIY7RRxSXFmRbEuKaNkKI0JXn0Qlx0zceo5rRkO+92waMGdiXmH5QY6HvsL40Dp0/2qelT+9Zmg6EOG1mt/g/K3at/1eDsHw==
$ vmstat -h Usage: vmstat [options] [delay [count]] Options: -a, --active active/inactive memory -f, --forks number of forks since boot -m, --slabs slabinfo -n, --one-header do not redisplay header -s, --stats event counter statistics -d, --disk disk statistics -D, --disk-sum summarize disk statistics -p, --partition <dev> partition specific statistics -S, --unit <char> define display unit -w, --wide wide output -t, --timestamp show timestamp -y, --no-first skips first line of output -h, --help display this help and exit -V, --version output version information and exit For more details see vmstat(8).
vmstat, vmstat -a メモリの状況を表示
- 引数無し、-a オプション付きで実行すると、現在のメモリの状況を取得できる
ubuntu@www4250uj:~$ vmstat procs -----------memory---------- ---swap-- -----io---- -system-- -------cpu------- r b swpd free buff cache si so bi bo in cs us sy id wa st gu 2 0 359168 97780 50032 713320 9 329 1144 435 803 3 2 1 97 0 0 0 ubuntu@www4250uj:~$ vmstat -a procs -----------memory---------- ---swap-- -----io---- -system-- -------cpu------- r b swpd free inact active si so bi bo in cs us sy id wa st gu 0 0 357632 93468 485080 587088 8 296 1037 397 781 3 2 1 97 0 0 0
- -S m オプションをつけると MB 単位で表示 (単位は k 1000, K 1024, m 1000000, M 1048576 が指定可能)
ubuntu@www4250uj:~$ vmstat -S m procs -----------memory---------- ---swap-- -----io---- -system-- -------cpu------- r b swpd free buff cache si so bi bo in cs us sy id wa st gu 1 0 371 91 52 760 0 0 910 354 760 3 2 1 97 0 0 0 ubuntu@www4250uj:~$ vmstat -a -S m procs -----------memory---------- ---swap-- -----io---- -system-- -------cpu------- r b swpd free inact active si so bi bo in cs us sy id wa st gu 1 0 371 91 493 610 0 0 908 354 760 3 2 1 97 0 0 0
-表示内容 (manより引用)
FIELD DESCRIPTION FOR VM MODE Procs r: The number of runnable processes (running or waiting for run time). b: The number of processes blocked waiting for I/O to complete. Memory These are affected by the --unit option. swpd: the amount of swap memory used. free: the amount of idle memory. buff: the amount of memory used as buffers. cache: the amount of memory used as cache. inact: the amount of inactive memory. (-a option) active: the amount of active memory. (-a option) Swap These are affected by the --unit option. si: Amount of memory swapped in from disk (/s). so: Amount of memory swapped to disk (/s). IO bi: Kibibyte received from a block device (KiB/s). bo: Kibibyte sent to a block device (KiB/s). System in: The number of interrupts per second, including the clock. cs: The number of context switches per second. CPU These are percentages of total CPU time. us: Time spent running non-kernel code. (user time, including nice time) sy: Time spent running kernel code. (system time) id: Time spent idle. Prior to Linux 2.5.41, this includes IO-wait time. wa: Time spent waiting for IO. Prior to Linux 2.5.41, included in idle. st: Time stolen from a virtual machine. Prior to Linux 2.6.11, unknown. gu: Time spent running KVM guest code (guest time, including guest nice).
vmstat -f fork回数
- システム稼働からの fork 回数 = 起動してからどんだけプロセスを作ったか
ubuntu@www4250uj:~$ vmstat -f 2738 forks
vmsrat -m メモリ断片化の状況
- Linuxカーネルが、プロセスに割り当てた ページ のうち未使用な領域 (slub)
- Linuxカーネルは、slub領域が30%を超えると、メモリのデフラグを行って、なるべく連続領域がプロセスにわたるようにする
ubuntu@www4250uj:~$ sudo vmstat -m
vmstart -s 統計情報の表示
- vmstat で出せるデータ全部盛り
ubuntu@www4250uj:~$ vmstat -s 2014808 K total memory 1646040 K used memory 466056 K active memory 572376 K inactive memory 126256 K free memory 19516 K buffer memory 550860 K swap cache 6291452 K total swap 397568 K used swap 5893884 K free swap 12462 non-nice user cpu ticks 0 nice user cpu ticks 3680 system cpu ticks 888314 idle cpu ticks 2601 IO-wait cpu ticks 0 IRQ cpu ticks 298 softirq cpu ticks 127 stolen cpu ticks 0 non-nice guest cpu ticks 0 nice guest cpu ticks 1590521 K paged in 654100 K paged out 3277 pages swapped in 100950 pages swapped out 2186383 interrupts 3109658 CPU context switches 1718467490 boot time 4227 forks
vmstat -d, -D ディスク情報表示
ubuntu@www4250uj:~$ vmstat -d disk- ------------reads------------ ------------writes----------- -----IO------ total merged sectors ms total merged sectors ms cur sec loop0 0 0 0 0 0 0 0 0 0 0 loop1 0 0 0 0 0 0 0 0 0 0 loop2 0 0 0 0 0 0 0 0 0 0 loop3 0 0 0 0 0 0 0 0 0 0 loop4 0 0 0 0 0 0 0 0 0 0 loop5 0 0 0 0 0 0 0 0 0 0 loop6 0 0 0 0 0 0 0 0 0 0 loop7 0 0 0 0 0 0 0 0 0 0 vda 62993 18928 3233706 28781 32493 116577 1344688 153725 0 43 sr0 0 0 0 0 0 0 0 0 0 0 ubuntu@www4250uj:~$ vmstat -D 10 disks 2 partitions 63078 total reads 18928 merged reads 3240170 read sectors 28805 milli reading 32498 writes 116779 merged writes 1346344 written sectors 153740 milli writing 0 inprogress IO 43 milli spent IO 182 milli weighted IO
- 表示内容 (manより引用)
Reads total: Total reads completed successfully merged: grouped reads (resulting in one I/O) sectors: Sectors read successfully ms: milliseconds spent reading Writes total: Total writes completed successfully merged: grouped writes (resulting in one I/O) sectors: Sectors written successfully ms: milliseconds spent writing IO cur: I/O in progress s: seconds spent for I/O
vmstat -p パーティション読み書き回数
ubuntu@www4250uj:~$ sudo fdisk -l Disk /dev/vda: 200 GiB, 214748364800 bytes, 419430400 sectors Units: sectors of 1 * 512 = 512 bytes Sector size (logical/physical): 512 bytes / 512 bytes I/O size (minimum/optimal): 512 bytes / 512 bytes Disklabel type: gpt Disk identifier: B1D9F0C9-5071-4302-9F9F-029CFDE73E1D Device Start End Sectors Size Type /dev/vda1 2048 4095 2048 1M BIOS boot /dev/vda2 4096 419427967 419423872 200G Linux filesystem ubuntu@www4250uj:~$ vmstat -p /dev/vda2 vda2 reads read sectors writes requested writes 63398 3254002 33964 1372808