キャッシュを消去するには、/proc/sys/vm/drop_caches を設定します。

キャッシュを消去するには、/proc/sys/vm/drop_caches を設定します。

コールドキャッシュタイミングタスクの一環としてOSキャッシュを取得しようとしています。これカーネル文書(2019年1月に検索)説明する:

drop_caches

Writing to this will cause the kernel to drop clean caches, as well as
reclaimable slab objects like dentries and inodes.  Once dropped, their
memory becomes free.

To free pagecache:
    echo 1 > /proc/sys/vm/drop_caches
To free reclaimable slab objects (includes dentries and inodes):
    echo 2 > /proc/sys/vm/drop_caches
To free slab objects and pagecache:
    echo 3 > /proc/sys/vm/drop_caches

This is a non-destructive operation and will not free any dirty objects.
To increase the number of objects freed by this operation, the user may run
`sync' prior to writing to /proc/sys/vm/drop_caches.  This will minimize the
number of dirty objects on the system and create more candidates to be
dropped.

This file is not a means to control the growth of the various kernel caches
(inodes, dentries, pagecache, etc...)  These objects are automatically
reclaimed by the kernel when memory is needed elsewhere on the system.

Use of this file can cause performance problems.  Since it discards cached
objects, it may cost a significant amount of I/O and CPU to recreate the
dropped objects, especially if they were under heavy use.  Because of this,
use outside of a testing or debugging environment is not recommended.

You may see informational messages in your kernel log when this file is
used:

    cat (1234): drop_caches: 3

These are informational only.  They do not mean that anything is wrong
with your system.  To disable them, echo 4 (bit 3) into drop_caches.

私は詳細について少し概略的です。走る

echo 3 > /proc/sys/vm/drop_caches

ページキャッシュ、ディレクトリエントリ、およびinodeを解放します。いいね

もしそうなら、システムがキャッシュを再び正常に起動させるには、まずキャッシュをゼロにリセットする必要がありますか?私のシステムは現在の値を0に設定しますが、これがデフォルト値だと思います。それとも自然にリセットされますか?これには少なくとも2つの可能性がありますが、どちらが正しいかわかりません。

  1. echo 3 > /proc/sys/vm/drop_cachesページキャッシュ、ディレクトリエントリ、およびinodeを解放します。その後、システムはすぐにキャッシュを再開します。/proc/sys/vm/drop_cachesこの場合、期待値がどうなるかはよくわかりません。ほぼすぐにゼロに戻りますか?

  2. 3に設定すると、/proc/sys/vm/drop_cachesシステムは0にリセットされるまでメモリキャッシュを実行しません。

どんな場合が本当ですか?

ベストアンサー1

固定的ではありません。ファイルに書き込むだけでキャッシュが削除され、すぐにキャッシュが再起動されます。

デフォルトでは、そのファイルに書き込むときに実際に設定を変更するのではなく、カーネルにコマンドを発行することです。カーネルはキャッシュを削除してコマンドに従い、以前と同様に実行を続けます。

おすすめ記事