ITPub博客

首页 > Linux操作系统 > Linux操作系统 > Redhat Linux7下如何用drop_caches手动清理缓存

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

原创 Linux操作系统 作者:chenfeng 时间:2016-06-30 18:19:57 0 删除 编辑
清理缓存(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博客 ” ,链接:https://blog.itpub.net/15498/viewspace-2121300/ ,如需转载,请注明出处,否则将追究法律责任。

请登录后发表评论 登录
全部评论
交流MySQL,PolarDB/PolarDB-X,PostgreSQL,MongoDB和Redis技术。

注册时间:2015-12-07

  • 博文量
    784
  • 访问量
    2690816