打开APP
userphoto
未登录

开通VIP,畅享免费电子书等14项超值服

开通VIP
CentOS,清理缓存(drop

读写文件时,Linux内核为了提高读写效率与速度,会将文件在内存中进行缓存,这就是Cache Memory(缓存内存)。
即使程序运行结束后,Cache Memory也不会自动释放。这就会导致程序频繁读写文件后,可用物理内存会很少。
其实这缓存内存(Cache Memory)在你需要使用内存的时候会自动释放,所以不必担心没有内存可用。
如果你希望手动去释放Cache Memory(缓存内存)的话也是有办法的。

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

This is a non-destructive operation and will not free any dirty objects.
To increase the number of objects freed by this operation, the user may run
`sync' prior to writing to /proc/sys/vm/drop_caches.  This will minimize the
number of dirty objects on the system and create more candidates to be
dropped.

This file is not a means to control the growth of the various kernel caches
(inodes, dentries, pagecache, etc...)  These objects are automatically
reclaimed by the kernel when memory is needed elsewhere on the system.

Use of this file can cause performance problems.  Since it discards cached
objects, it may cost a significant amount of I/O and CPU to recreate the
dropped objects, especially if they were under heavy use.  Because of this,
use outside of a testing or debugging environment is not recommended.

You may see informational messages in your kernel log when this file is
used:
cat (1234): drop_caches: 3

These are informational only.  They do not mean that anything is wrong
with your system.  To disable them, echo 4 (bit 3) into drop_caches.
==============================================================
# cat /proc/sys/vm/drop_caches
0 //默认是0;1-清空页缓存;2-清空inode和目录树缓存;3-清空所有缓存
[root@bak ~]# sync //注意:在清空缓存之前使用sync命令同步数据到磁盘
[root@bak ~]# free -m
             total       used       free     shared    buffers     cached
Mem:         15898       3029      12869          0        191       1064
-/+ buffers/cache:       1772      14125
Swap:        31999          0      31999
[root@bak ~]# echo 3 > /proc/sys/vm/drop_caches
[root@bak ~]# free -m //发现缓存明显减少了
             total       used       free     shared    buffers     cached
Mem:         15898       1770      14128          0          1         30
-/+ buffers/cache:       1738      14160
Swap:        31999          0      31999

本站仅提供存储服务,所有内容均由用户发布,如发现有害或侵权内容,请点击举报
打开APP,阅读全文并永久保存 查看更多类似文章
猜你喜欢
类似文章
【热】打开小程序,算一算2024你的财运
linux free命令中buffer与cache的区别
Linux 释放cache化缓存
Linux 释放内存
linux 清理缓存
简单介绍Linux内存手动释放方法
linux怎么清除缓存(转)
更多类似文章 >>
生活服务
热点新闻
分享 收藏 导长图 关注 下载文章
绑定账号成功
后续可登录账号畅享VIP特权!
如果VIP功能使用有故障,
可点击这里联系客服!

联系客服