LoginSignup
9
8

More than 5 years have passed since last update.

vm.vfs_cache_pressureを変更してもページキャッシュの解放には効きません

Posted at

Linux でページキャッシュにメモリが費やされてメモリ不足になる問題を抱えて、vm.vfs_cache_pressureを変更してみたけれど、効果がなかったというひとはたくさんおられるでしょう。

Linux の vm.vfs_cache_pressure は、slabメモリのdentryとiノードのキャッシュの割り当てを調整するだけで、ページキャッシュ(ファイルI/Oのバッファキャッシュ)の解放には関係がありません。

vfs_cache_pressure についての説明を見てみましょう。

Documentation for /proc/sys/vm/* kernel version 2.6.29 より引用

vfs_cache_pressure

This percentage value controls the tendency of the kernel to reclaim
the memory which is used for caching of directory and inode objects.

At the default value of vfs_cache_pressure=100 the kernel will attempt to
reclaim dentries and inodes at a "fair" rate with respect to pagecache and
swapcache reclaim. Decreasing vfs_cache_pressure causes the kernel to prefer
to retain dentry and inode caches. When vfs_cache_pressure=0, the kernel will
never reclaim dentries and inodes due to memory pressure and this can easily
lead to out-of-memory conditions. Increasing vfs_cache_pressure beyond 100
causes the kernel to prefer to reclaim dentries and inodes.

Increasing vfs_cache_pressure significantly beyond 100 may have negative
performance impact. Reclaim code needs to take various locks to find freeable
directory and inode objects. With vfs_cache_pressure=1000, it will look for
ten times more freeable objects than there are.

超約

このパーセント値はカーネルがディレクトリとiノードオブジェクトのキャッシュに使用されるメモリを再利用するときの傾向を制御します。

vfs_cache_pressureのデフォルト値は100で、このときカーネルはdentryとiノードキャッシュの再利用は、ページキャッシュとスワップキャッシュの再利用と同等の割合になります。

vfs_cache_pressureを小さくすると、dentryとiノードキャッシュの割り当てメモリを保持する傾向が高くなり、vfs_cache_pressure=0とした場合、カーネルはdentryとiノードキャッシュのメモリをまったく再利用しなくなります。この設定はたやすくメモリ不足の状況につながるでしょう。
vfs_cache_pressureを100より大きくすると、カーネルはdentryとiノードキャッシュのメモリをより積極的に再利用するようになります。

vfs_cache_pressureを100から大幅に大きくすると、パフォーマンスが悪くなるかもしれません。
キャッシュメモリの再利用では、解放可能なメモリ見つけるために様々なロックをかけます。vfs_cache_pressure = 1000 では、より多くの解放可能なオブジェクトを見つけようとするため、デフォルト値の10倍の処理を要します。


vfs_cache_pressure の説明では、dentryとiノードのキャッシュに割り当てられたメモリを、どの程度再利用するかの傾向を制御するとは書かれていますが、ページキャッシュやスワップキャッシュを解放するとは書かれていません。

そして、カーネルのソースを vfs_cache_pressure で grep した限りでも、ファイルシステムのメタ情報や dcache など、ファイルシステム関係のソースは引っかかりますが、mm の下にあるものはページングに関係したものは引っかかりません。簡単にマッチしたソースを見ましたが、いずれの部分もページキャッシュに関する処理やカーネル変数を操作するようなコードはないようでした。

このようなことから、ページキャッシュのメモリ回収はこのパラメータは見ていないと思われます。

9
8
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
9
8