1. drop_caches
在Documentation/sysctl/vm.txt中有如下描述:
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 not freeable, the user should run `sync' first.
2. cache 和 buffer的區別
Cache:快取,是位於CPU與主記憶體間的一種容量較小但速度很高的儲存空間。由於CPU的速度遠高於主記憶體,CPU直接從記憶體中存取資料要等待一定時間周期,Cache中儲存著CPU剛用過或迴圈使用的一部分資料,當CPU再次使用該部分資料時可從Cache中直接調用,這樣就減少了CPU的等待時間,提高了系統的效率。Cache又分為一級Cache(L1 Cache)和二級Cache(L2 Cache),L1 Cache整合在CPU內部,L2 Cache早期一般是焊在主板上,現在也都整合在CPU內部,常見的容量有256KB或512KB
L2 Cache。
Buffer:緩衝區,一個用於儲存速度不同步的裝置或優先順序不同的裝置之間傳輸資料的地區。通過緩衝區,可以使進程之間的相互等待變少,從而使從速度慢的裝置讀入資料時,速度快的裝置的操作進程不發生間斷。
Free中的buffer和cache:(它們都是佔用記憶體):
buffer : 作為buffer cache的記憶體,是塊裝置的讀寫緩衝區
cache: 作為page cache的記憶體, 檔案系統的cache
如果 cache 的值很大,說明cache住的檔案數很多。如果頻繁訪問到的檔案都能被cache住,那麼磁碟的讀IO bi會非常小。