Linux之清理linux内存cache
转自:https://www.cnblogs.com/madsnotes/articles/5740495.html
频繁的文件访问会导致系统的Cache使用量大增。例如:在使用grep从很多文件中搜索特定数据串的时候,发现内存使用迅速提高,主要是cache的使用占用了相当多的内存。在使用下面命令的时候忽视了文件的数量和文件大小,导致cache突增。
# grep -e "dst_string" ./*
大家在使用shell编程的时候一定要注意通配符的使用,这里尤其提醒大家就是星号(*)的使用,星号固然方便,但要适度使用。 这里主要还是记录如何手动清理linux内存cache,因为上面的操作使用的大量的cache。

# 使用free查看当前系统内存使用情况
[root@bogon ~]# free
total used free shared buffers cached
Mem: 1938784 89628 1849156 248 60 17644
-/+ buffers/cache: 71924 1866860
Swap: 2097148 0 2097148 # 执行grep操作
[root@bogon ~]# grep -e "dsf" ./* # 再次查看内存使用情况
[root@bogon ~]# free
total used free shared buffers cached
Mem: 1938784 100020 1838764 244 3608 26020
-/+ buffers/cache: 70392 1868392
Swap: 2097148 0 2097148

下面介绍如何清理cached

# 执行sync同步数据,防止数据或操作丢失(重要),将未写的系统缓冲区写到磁盘中。包含已修改的 i-node、已延迟的块 I/O 和读写映射文件
sync
# 清理cached
[root@bogon ~]# echo 3 > /proc/sys/vm/drop_caches # 查看清理cached后的内存使用情况
[root@bogon ~]# free
total used free shared buffers cached
Mem: 1938784 87116 1851668 240 188 17596
-/+ buffers/cache: 69332 1869452
Swap: 2097148 0 2097148

drop_cache的详细文档如下,以便查阅.

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_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
As 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.(只有内核在2.6.16以上的才支持)

Linux之清理linux内存cache的更多相关文章
- 【Linux】清理缓存buffer/cache
运行sync将dirty的内容写回硬盘 sync 通过修改proc系统的drop_caches清理free的cache echo 3 > /proc/sys/vm/drop_caches ech ...
- Linux下清理内存和Cache方法 /proc/sys/vm/drop_caches
Linux下清理内存和Cache方法 /proc/sys/vm/drop_caches 频繁的文件访问会导致系统的Cache使用量大增 $ free -m total used free shared ...
- Linux下清理内存和Cache方法见下文:
暂时目前的环境处理方法比较简单: 在root用户下添加计划任务: */10 * * * * sync;echo 3 > /proc/sys/vm/drop_caches; 每十分钟执行一次,先将 ...
- Linux下清理内存和Cache方法
暂时目前的环境处理方法比较简单: 在root用户下添加计划任务: */10 * * * * sync;echo 3 > /proc/sys/vm/drop_caches; 每十分钟执行一次,先将 ...
- Linux内核中内存cache的实现【转】
Linux内核中内存cache的实现 转自:http://blog.chinaunix.net/uid-127037-id-2919545.html 本文档的Copyleft归yfydz所有,使用 ...
- 在 Linux 上如何清除内存的 Cache、Buffer 和交换空间
原文链接:http://www.linuxidc.com/Linux/2015-06/118856.htm 像任何其他的操作系统一样,GNU/Linux 已经实现的内存管理不仅有效,而且更好.但是,如 ...
- 关于Linux的缓存内存 Cache Memory详解<转>
转自 http://www.ha97.com/4337.html PS:前天有童鞋问我,为啥我的Linux系统没运行多少程序,显示的可用内存这么少?其实Linux与Win的内存管理不同,会尽量缓存内存 ...
- linux memory release commands内存清理/释放命令
linux 内存清理/释放命令 You could find reference from here: http://jingyan.baidu.com/article/597a06436a687f3 ...
- 如何在Linux上清理内存缓存、缓冲与交换空间
如何在Linux上清理内存缓存.缓冲与交换空间 与其他类型的操作系统一样,GNU/Linux已经有效的实现了内存管理,甚至更加优秀.但是如果任何进程正在吃光你的内存,并且你想清理它,Linux提供了一 ...
随机推荐
- PHP Manager 安装失败的解决方法, PHP Manager 1.4 for IIS 10,经验证支持windows server 2016版本
// 另有无需进行修改注册表的安装包,经测试最高支持Windows Server 2016 版本,下载地址如下: https://github.com/EnhWeb/PHPManager/tree/m ...
- 【AtCoder】ARC071
ARC071 C - 怪文書 / Dubious Document 题目大意:给n个字符串,每个字符串可以通过扔掉一些字母将剩下的字母重排得到新的字符串,求n个字符串都能拼出的字符串且长度最大,若有多 ...
- windows 设置开机启动,启动项
第一步ctrl+R输入以下任意一个 方法一: C:\ProgramData\Microsoft\Windows\Start Menu\Programs\StartUp 方法二: shell:start ...
- BZOJ1001 [BeiJing2006]狼抓兔子 最小割 对偶图 最短路
原文链接http://www.cnblogs.com/zhouzhendong/p/8686871.html 题目传送门 - BZOJ1001 题意 长成上面那样的网格图求最小割. $n,m\leq ...
- 实体转xml 并以string输出
<?xml version="1.0" encoding="utf-8"?><Root> <Header> <Mess ...
- Noj - 在线强化训练4
状态 题号 竞赛题号 标题 × 1092 A 童年的回忆——计算24 × 1145 B 求图像的周长 × 1144 C 农场灌溉问题 × 1202 D 数独游戏 × 1243 E 循环赛日程表 × 1 ...
- mybatis中if test 可以使用== != null '' and or 和括号()
<if test="pd.flag==1 or ((pd.flag==2 or pd.flag==3) and (pd.sfyj==2 or pd.sfyj==3)) or pd.fl ...
- gradle3.0新命令
摘抄原文https://mp.weixin.qq.com/s/6UZhaI9cILJiPGYHkXd73g No1: Implementation compile 指令被标注为过时方法,而新增了两个依 ...
- POJ 1200 Crazy Search 【hash】
<题目链接> 题目大意: 给定n,nc,和一个字符串,该字符串由nc种字符组成,现在要你寻找该字符串中长度为n的子字符串有多少种. 解题分析: 因为要判重,所以讲这些字符串hash一下,将 ...
- Python常用模块--collections
collections是Python中一个非常强大的容器数据模块. 1.创建升级版的元组--namedtupe Python的元组(1,2,3)具有不可变性,但是单独的元组在无法满足现有需求时,可以使 ...