清理缓存(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
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/,如需转载,请注明出处,否则将追究法律责任。
转载于:http://blog.itpub.net/15498/viewspace-2121300/
本文介绍如何通过修改/proc/sys/vm/drop_caches来清理Linux系统的缓存,包括页缓存、inode和目录树缓存等。通过echo不同数字到该文件可以实现对不同类型缓存的清理。
201

被折叠的 条评论
为什么被折叠?



