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提供了一 ...
随机推荐
- Python_冒泡排序
从小到大的排序:(最前面的数和一步步和后面的数比较,如果大于则交换,如果不大于则继续循环) 方法1: data = [65, 1, 45, 77, 3, 9, 43, 23, 7, 53, 213, ...
- linux重启服务的脚本命令
最近做网站测试,每次测试完成都要重启服务,为此写了一个简单的shell脚本 linux服务重启shell脚本示例 2014年12月18日 linux服务重启脚本,如何实现linux服务的定时重启,可以 ...
- playbook role应用
参考: ansible中文权威指南 1. 动态Include 结合when等判断,在满足某个条件的时候加载. - include: test.yml when: ...... handler 中也可以 ...
- PAT (Basic Level) Practise - 写出这个数
题目链接:https://www.patest.cn/contests/pat-b-practise/1002 读入一个自然数n,计算其各位数字之和,用汉语拼音写出和的每一位数字. 输入格式:每个测试 ...
- Linux系统数据共享-NFS服务
转载:http://www.cnblogs.com/mchina/archive/2013/01/03/2840040.html 一.NFS服务简介 NFS 是Network File System的 ...
- 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 ...
- 电信项目java补充类
一.DecimalFormat 1.概述 public class DecimalFormat extends NumberFormat DecimalFormat是格式为十进制数的NumberFor ...
- 20165220 Java第四周学习总结
教材学习内容总结 super:使用关键字super来访问和调用被子类隐藏的成员变量和方法. 接口:用关键字interface来定义一个接口.接口由类来实现以便使用接口中的方法,用关键字implemen ...
- TF之RNN:基于顺序的RNN分类案例对手写数字图片mnist数据集实现高精度预测—Jason niu
import tensorflow as tf from tensorflow.examples.tutorials.mnist import input_data mnist = input_dat ...
- Service工作原理
--摘自<android插件化开发指南> 一.在新进程启动Service 第一步:APP向AMS发送一个启动Service的消息 通过AMN/AMP把要启动的Service信息发送给AMS ...