Linux手動清理Cache

來源:互聯網
上載者:User

軟體版本:
  作業系統: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.

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在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.