Linux下清除缓存 drop_caches, sysctl
来源:互联网 发布:最新网络词语 编辑:程序博客网 时间:2024/05/22 13:03
转自 http://blog.csdn.net/sky_qing/article/details/8988461
1. 用命令 free -m 查看一下内存的使用情况:
然后清除缓存后再来查看一下内存的使用情况:
前后对比可发现,缓存由之前的110M缩小到了25M,效果比较明显。
2. 下面说一下 drop_caches:
清空 pagecache:
sync
echo 1 > /proc/sys/vm/drop_caches
或者:
sync
sysctl -w vm.drop_caches=1
清空 dentries 和 inodes:
sync
echo 2 > /proc/sys/vm/drop_caches
或者:
sync
sysctl -w vm.drop_caches=2
清空所有缓存(pagecache、dentries 和 inodes):
sync
echo 3 > /proc/sys/vm/drop_caches
或者:
sync
sysctl -w vm.drop_caches=3
3. 如果尝试向 drop_caches 中写入 0,会报下面错误:
-bash: echo: write error: Invalid argument
我的内核是3.4.39,64 位。至于什么原因,我没找到。但是从下面关于 drop_caches 的说明来看,drop_caches 的值并没有说可以设置成 0 的,但是 drop_caches 的默认值是 0。但是 2.6.x 的内核将 drop_caches 的值设置为 0 是没有问题的。
关于 drop_caches:
Kernels 2.6.16 and newer provide a mechanism to have the kernel drop the page cache and/or inode and dentry caches on command, which can help free up a lot of memory. Now you can throw away that script that allocated a ton of memory just to get rid of the cache...
To use /proc/sys/vm/drop_caches, just echo a number to it.
To free pagecache:
# echo 1 > /proc/sys/vm/drop_caches
To free dentries and inodes:
# echo 2 > /proc/sys/vm/drop_caches
To free pagecache, dentries and inodes:
echo 3 > /proc/sys/vm/drop_caches
This is a non-destructive operation and will only free things that are completely unused. Dirty objects will continue to be in use until written out to disk and are not freeable. If you run "sync" first to flush them out to disk, these drop operations will tend to free more memory.
参考:
http://linux-mm.org/Drop_Caches
https://bbs.archlinux.org/viewtopic.php?id=127049
- Linux下清除缓存 drop_caches,sysctl
- Linux下清除缓存 drop_caches, sysctl
- Linux下清除缓存 drop_caches,sysctl(备忘)
- drop_caches Linux清空缓存
- drop_caches Linux清空缓存
- linux下清除tomcat缓存
- Linux下清除DNS缓存
- linux下清除tomcat缓存
- Linux下sysctl命令
- Linux drop_caches
- linux下 squid 手动清除缓存
- 如何清除linux (ubuntu)下的缓存?
- linux下sysctl()函数初探
- 手动释放linux缓存——/proc/sys/vm/drop_caches
- 清除Linux缓存
- 清除Linux缓存
- linux清除tomcat缓存
- 清除Linux缓存
- JDK与Tomcat的环境变量配置
- 九度OJ 打印日期 (模拟)
- Django构建一个Blog入门例子
- Palindrome Number
- 三星再曝廉价新机力压红米
- Linux下清除缓存 drop_caches, sysctl
- 10397 - Connect the Campus
- 征服 Mongodb 之 主从复制&集群复制
- performSelector延时调用
- 在Spring、Hibernate中使用Ehcache缓存
- Android 中不同的系统版本隐藏和显示systemui方法
- 寻找矩阵中的鞍点<二维数组>
- (2) flume 入门学习 HelloWorld 及HDFS 遇到的问题 总结
- java class生成jar包