Redhat Linux7下如何用drop_caches手動清理快取

chenfeng發表於2016-06-30
清理快取(drop_caches)的官方文件如下:
http://www.kernel.org/doc/Documentation/sysctl/vm.txt
==============================================================
drop_caches

Writing to this will cause the kernel to drop clean caches, as well as
reclaimable slab objects like dentries and inodes.  Once dropped, their
memory becomes free.


To free pagecache:
echo 1 > /proc/sys/vm/drop_caches
To free reclaimable slab objects (includes dentries and inodes):
echo 2 > /proc/sys/vm/drop_caches
To free slab objects and pagecache:
echo 3 > /proc/sys/vm/drop_caches

==============================================================

# cat /proc/sys/vm/drop_caches
0 //預設是0;1-清空頁快取;2-清空inode和目錄樹快取;3-清空所有快取

示例如下:
[root@chenfeng ~]# sync    //在清空快取之前使用sync命令同步資料到磁碟

[root@chenfeng ~]# free -m
              total        used        free      shared  buff/cache   available
Mem:           1824        1165          93          10         566         421
Swap:             0           0           0

[root@chenfeng ~]# echo 3 > /proc/sys/vm/drop_caches  //清空所有快取

[root@chenfeng ~]# free -m  //可以看到快取buff/cache的值明顯減少了
              total        used        free      shared  buff/cache   available
Mem:           1824        1123         492          10         209         514
Swap:             0           0           0

來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/15498/viewspace-2121300/,如需轉載,請註明出處,否則將追究法律責任。

相關文章