2
0

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 3 years have passed since last update.

バッファキャッシュとページキャッシュというのがあるらしい

Posted at

勉強前イメージ

どっちもキャッシュ?種類があるの知らんかった

調査

バッファキャッシュ とは

ブロックデバイス(データ転送をブロック単位で行うHDDなどを指す)に直接アクセスするときに使用されるキャッシュで
実装上はブロックデバイスに対するページキャッシュになっています。
freeコマンドでは buffers の箇所に当たります。
以下のfreeコマンドを見てみると、4.1MBがバッファキャッシュとして持っていることがわかります。

# free -h -w
              total        used        free      shared     buffers       cache   available
Mem:           3.7G        425M        1.6G         48M        4.1M        1.7G        3.0G
Swap:          819M          0B        819M

以下のvmstatコマンドだと、buffになります。
これはMB単位で見やすくしているので、4になっています。

# vmstat -wSm
procs -----------------------memory---------------------- ---swap-- -----io---- -system-- --------cpu--------
 r  b         swpd         free         buff        cache   si   so    bi    bo   in   cs  us  sy  id  wa  st
 1  0            0         1713            4         1809    0    0     1     4   31   46   0   0 100   0   0

ページキャッシュ とは

ディスクから読み込んだデータをキャッシュする、ファイルシステムに対するキャッシュです。
ファイル単位でアクセスする際に使用されます。
ファイルへ書き込んだときは残るので、読み込むときにキャッシュのデータを利用できます。
freeコマンドでは cache にあたります。
以下ではページキャッシュは1.7GB持ってることがわかります。

# free -h -w
              total        used        free      shared     buffers       cache   available
Mem:           3.7G        425M        1.6G         48M        4.1M        1.7G        3.0G
Swap:          819M          0B        819M

以下のvmstatコマンドだと、cacheになります。

# vmstat -wSm
procs -----------------------memory---------------------- ---swap-- -----io---- -system-- --------cpu--------
 r  b         swpd         free         buff        cache   si   so    bi    bo   in   cs  us  sy  id  wa  st
 1  0            0         1713            4         1809    0    0     1     4   31   46   0   0 100   0   0

おまけ

  • freeコマンド

free -h -w
-h : 表示をGB、MBで見やすく
-w : ワイド表示(デフォルトだと buff/cache で一緒になってしまってる)

# free -h -w
              total        used        free      shared     buffers       cache   available
Mem:           3.7G        425M        1.6G         48M        4.1M        1.7G        3.0G
Swap:          819M          0B        819M
  • vmstat

vmstat -wSm
-w : ワイド表示
-Sm : 単位をMBにする

# vmstat -wSm
procs -----------------------memory---------------------- ---swap-- -----io---- -system-- --------cpu--------
 r  b         swpd         free         buff        cache   si   so    bi    bo   in   cs  us  sy  id  wa  st
 1  0            0         1713            4         1809    0    0     1     4   31   46   0   0 100   0   0

勉強後イメージ

キャッシュにもいろいろあるのね。
freeコマンドとかvmstatとか使ったことあったけどちゃんと見れてなかった。

参考

2
0
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
2
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?