linux 清除cached說明


關於 drop_caches:
Kernels 2.6.16 and newer provide a mechanism to have the kernel drop the page cache and/or inode and dentry caches on command, which can help free up a lot of memory. Now you can throw away that script that allocated a ton of memory just to get rid of the cache...


To use /proc/sys/vm/drop_caches, just echo a number to it.

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


This is a non-destructive operation and will only free things that are completely unused. Dirty objects will continue to be in use until written out to disk and are not freeable. If you run "sync" first to flush them out to disk, these drop operations will tend to free more memory.


修改/etc/sysctl.conf 添加如下選項後就不會內存持續增加
vm.dirty_ratio = 1
vm.dirty_background_ratio=1
vm.dirty_writeback_centisecs=2
vm.dirty_expire_centisecs=3
vm.drop_caches=3
vm.swappiness =100
vm.vfs_cache_pressure=163
vm.overcommit_memory=2
vm.lowmem_reserve_ratio=32 32 8
kern.maxvnodes=3

上面的設置比較粗暴,使cache的作用基本無法發揮。需要根據機器的狀況進行適當的調節尋找最佳的折衷。


發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章