Linux內存cached釋放


Linux內存cached釋放

我們用free命令查看系統內存使用情況的時候會發現:

#free -m
1、total = used + free
2、cached比較大,甚至我遇見過內存剩余只有7M的情況,這個時候cached非常大,基本上接近等於total了,這個時候打開文件或者傳輸文件的時候可用內存很小,程序可能就會用到交換分區swap了,所以會發現機器速度變慢的情況


如何解決這個導致機器變慢的問題呢?
罪魁禍首就是內存都被cached了,free的基本沒有了
所以我們應該想想如何把cached內存釋放出來
重啟機器肯定是可以解決,但是我們肯定是不能用這樣的辦法


釋放方法有三種(系統默認值是0,釋放之后你可以再改回0值):
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


果然如此,這樣立刻解決了內存問題。
root@localhost ~]# free -m
            total      used      free    shared    buffers    cached
Mem:        15940      7187      8753          0        326      4824
-/+ buffers/cache:      2035      13905
Swap:        18127          0      18127
[root@localhost ~]#  echo "1" > /proc/sys/vm/drop_caches
^[[A^[[A[root@localhfree -m
            total      used      free    shared    buffers    cached
Mem:        15940      1903      14037          0          0        29
-/+ buffers/cache:      1874      14066
Swap:        18127          0      18127


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM