清理linux内存cache
2015-12-10 22:05
796 查看
在使用grep从很多文件中搜索特定数据串的时候,发现内存使用迅速提高,主要是cache的使用占用了相当多的内存。在使用下面命令的时候忽视了文件的数量和文件大小,导致cache突增。
# grep -e "dst_string" ./*
大家在使用shell编程的时候一定要注意通配符的使用,这里尤其提醒大家就是星号(*)的使用,星号固然方便,但要适度使用。
这里主要还是记录如何手动清理linux内存cache,因为上面的操作使用的大量的cache。
1、使用free查看一下当前内存使用情况:
# free
total used free shared buffers cached
Mem: 16621896 8967952 7653944 0 212352 8377276
-/+ buffers/cache: 378324 16243572
Swap: 10241428 0 10241428
2、执行sync同步数据
# sync
该命令将未写的系统缓冲区写到磁盘中。包含已修改的 i-node、已延迟的块 I/O 和读写映射文件。
3、清理cache
# echo 3 > /proc/sys/vm/drop_caches
# free
total used free shared buffers cached
Mem: 16621896 579592 16042304 0 268 308708
-/+ buffers/cache: 270616 16351280
Swap: 10241428 0 10241428
4、对比一下加粗部分就清楚了,cache被清理掉了。
参考资料:
http://www.linuxidc.com/Linux/2010-03/24939.htm
http://han19838383.blog.163.com/blog/static/54316486201101032825333/
5、drop_cache的详细文档如下,以便查阅(摘自:http://www.linuxidc.com/Linux/2010-03/24939.htm)
Writing to this will cause the kernel to drop clean caches, dentries and inodes from memory, causing that memory to become free.To free pagecache:* echo 1 > /proc/sys/vm/drop_cachesTo free dentries and inodes:* echo 2 > /proc/sys/vm/drop_cachesTo free pagecache, dentries and inodes:* echo 3 > /proc/sys/vm/drop_cachesAs this is a non-destructive operation, and dirty objects are notfreeable, the user should run "sync" first in order to make sure allcached objects are freed.This tunable was added in 2.6.16.
# grep -e "dst_string" ./*
大家在使用shell编程的时候一定要注意通配符的使用,这里尤其提醒大家就是星号(*)的使用,星号固然方便,但要适度使用。
这里主要还是记录如何手动清理linux内存cache,因为上面的操作使用的大量的cache。
1、使用free查看一下当前内存使用情况:
# free
total used free shared buffers cached
Mem: 16621896 8967952 7653944 0 212352 8377276
-/+ buffers/cache: 378324 16243572
Swap: 10241428 0 10241428
2、执行sync同步数据
# sync
该命令将未写的系统缓冲区写到磁盘中。包含已修改的 i-node、已延迟的块 I/O 和读写映射文件。
3、清理cache
# echo 3 > /proc/sys/vm/drop_caches
# free
total used free shared buffers cached
Mem: 16621896 579592 16042304 0 268 308708
-/+ buffers/cache: 270616 16351280
Swap: 10241428 0 10241428
4、对比一下加粗部分就清楚了,cache被清理掉了。
参考资料:
http://www.linuxidc.com/Linux/2010-03/24939.htm
http://han19838383.blog.163.com/blog/static/54316486201101032825333/
5、drop_cache的详细文档如下,以便查阅(摘自:http://www.linuxidc.com/Linux/2010-03/24939.htm)
Writing to this will cause the kernel to drop clean caches, dentries and inodes from memory, causing that memory to become free.To free pagecache:* echo 1 > /proc/sys/vm/drop_cachesTo free dentries and inodes:* echo 2 > /proc/sys/vm/drop_cachesTo free pagecache, dentries and inodes:* echo 3 > /proc/sys/vm/drop_cachesAs this is a non-destructive operation, and dirty objects are notfreeable, the user should run "sync" first in order to make sure allcached objects are freed.This tunable was added in 2.6.16.
相关文章推荐
- linux socket 编程顶尖教程
- linux系统inittab文件丢失故障
- Linux基本命令操作
- 为linux主机安装应用程序
- 关于linux文件管理的学习
- linux 硬盘分区
- Red Hat Linux 6.0安装图解
- linux configure使用方法
- linux打包与压缩命令
- centos type.h 编译错误问题
- Linux几个调试宏_FUNCTION_ _TIME_ _LINE_ _FILE_ _DATA_
- linux安装tesseract以及python调用tesseract-ocr
- centos 下安装 MySQL
- python使用paramiko和SCPClient进行linux远程控制和上传和下载文件
- Linux搜索文件命令
- linux系统下本地搭建git服务器
- centos/win7上安装我的世界服务器、客户端
- CentOS7系统安装笔记
- Linux系统下如何查看CPU个数
- 安装libjpeg库后提示libjpeg.so.8不存在(linux环境)