軟體版本:
作業系統:ubuntu10.04
核心版本:Linux version 2.6.32-36-generic
本文內容:
假如某程式頻繁的存取大量檔案將會導致 cache 的使用量劇增,並且不會在該程式退出後自動釋放。如果大量記憶體一直被 cache 佔用,系統會變得非常慢,甚至連敲命令都卡。我們可以通過對 /proc/sys/vm/drop_caches 這個檔案寫入不同的數值以達到清理 cache 的目的。
首先要運行 sync 將為寫入的緩衝回寫到磁碟中。
$ sync
將後往 /proc/sys/vm/drop_caches 寫入數值 3 。
$ echo 3 > /proc/sys/vm/drop_caches
關於 drop_caches 的詳細說明:
Writing to this will cause the kernel to drop clean caches, dentries and inodes from memory, causing that memory to become free.
To free pagecache:
* echo 1 > /proc/sys/vm/drop_caches
To free dentries and inodes:
* echo 2 > /proc/sys/vm/drop_caches
To free pagecache, dentries and inodes:
* echo 3 > /proc/sys/vm/drop_caches
As this is a non-destructive operation, and dirty objects are
notfreeable, the user should run "sync" first in order to make sure
allcached objects are freed.
This tunable was added in 2.6.16.