Redhat Linux7下如何用drop_caches手动清理缓存

清理缓存(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

请使用浏览器的分享功能分享到微信等