GNU/Linux >> Belajar Linux >  >> Linux

Linux – Mengatur /proc/sys/vm/drop_caches Untuk Menghapus Cache?

Sebagai bagian dari melakukan beberapa pengaturan waktu cache dingin, saya mencoba untuk membebaskan cache OS. Dokumentasi kernel (diambil Januari 2019) mengatakan:

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.

Saya agak samar tentang detailnya. Berlari

echo 3 > /proc/sys/vm/drop_caches

membebaskan pagecache, dentries dan inode. Oke.

Jadi, jika saya ingin sistem memulai caching secara normal lagi, apakah saya perlu mengatur ulang ke 0 terlebih dahulu? Sistem saya memiliki nilai yang saat ini disetel ke 0, yang saya asumsikan sebagai default. Atau akan reset sendiri? Saya melihat setidaknya dua kemungkinan di sini, dan saya tidak yakin mana yang benar:

  1. echo 3 > /proc/sys/vm/drop_caches membebaskan pagecache, dentries dan inode. Sistem kemudian segera memulai caching lagi. Saya tidak yakin apa yang saya harapkan dari nilai di /proc/sys/vm/drop_caches yang harus dilakukan jika ini masalahnya. Segera kembali ke 0?

  2. Jika /proc/sys/vm/drop_caches disetel ke 3, sistem tidak melakukan cache memori sampai disetel ulang ke 0.

Kasus mana yang benar?

Jawaban yang Diterima:

Ini tidak lengket – Anda cukup menulis ke file untuk menghapus cache dan kemudian segera memulai cache lagi.

Terkait:Mengapa menggunakan install daripada cp dan mkdir?

Pada dasarnya ketika Anda menulis ke file itu, Anda tidak benar-benar mengubah pengaturan, Anda mengeluarkan perintah ke kernel. Kernel bertindak atas perintah itu (dengan menghapus cache) kemudian melanjutkan seperti sebelumnya.


Linux
  1. Bagaimana cara mendapatkan jalur proses di Unix / Linux

  2. Perintah pembersihan cache NFS?

  3. linux /proc/loadavg

  1. mount dev, proc, sys di lingkungan chroot?

  2. Direktori - /sys di linux

  3. /sys/ dokumentasi?

  1. Linux – Menautkan /proc/mnt Ke /proc/mounts?

  2. Linux – Kehilangan File Jika Saya Membersihkan Cache (echo 3> /proc/sys/vm/drop_caches)?

  3. echo 3 > /proc/sys/vm/drop_caches - Izin ditolak sebagai root