Linux如何清除系統cache

來源:互聯網
上載者:User
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會非常小。

 

 

 

 

 

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.