日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 运维知识 > linux >内容正文

linux

清理linux内存cache

發布時間:2025/3/21 linux 45 豆豆
生活随笔 收集整理的這篇文章主要介紹了 清理linux内存cache 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
清理linux內存cache

在使用grep從很多文件中搜索特定數據串的時候,發現內存使用迅速提高,主要是cache的使用占用了相當多的內存。在使用下面命令的時候忽視了文件的數量和文件大小,導致cache突增。
  • # grep -e "dst_string" ./*
  • 大家在使用shell編程的時候一定要注意通配符的使用,這里尤其提醒大家就是星號(*)的使用,星號固然方便,但要適度使用。 這里主要還是記錄如何手動清理linux內存cache,因為上面的操作使用的大量的cache。 1、使用free查看一下當前內存使用情況:
  • # free
  • ?????????????total used free shared buffers cached
  • Mem: 16621896 8967952 7653944 0 212352 8377276
  • -/+ buffers/cache: 378324 16243572
  • Swap: 10241428 0 10241428
  • 2、執行sync同步數據
  • # sync
  • 該命令將未寫的系統緩沖區寫到磁盤中。包含已修改的 i-node、已延遲的塊 I/O 和讀寫映射文件。 3、清理cache
  • # echo 3 > /proc/sys/vm/drop_caches
  • # free
  • ?????????????total used free shared buffers cached
  • Mem: 16621896 579592 16042304 0 268 308708
  • -/+ buffers/cache: 270616 16351280
  • Swap: 10241428 0 10241428
  • 4、對比一下加粗部分就清楚了,cache被清理掉了。 參考資料: http://www.linuxidc.com/Linux/2010-03/24939.htm http://han19838383.blog.163.com/blog/static/54316486201101032825333/ 5、drop_cache的詳細文檔如下,以便查閱(摘自:http://www.linuxidc.com/Linux/2010-03/24939.htm)
  • 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.

  • 原文地址:http://blog.chinaunix.net/uid-25505925-id-180921.html

    總結

    以上是生活随笔為你收集整理的清理linux内存cache的全部內容,希望文章能夠幫你解決所遇到的問題。

    如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。