暂时目前的环境处理方法比较简单:

在root用户下添加计划任务:

*/10 * * * * sync;echo 3 > /proc/sys/vm/drop_caches;

每十分钟执行一次,先将脏数据写回硬盘,之后释放缓存页和入口信息和节点信息等;

-------------------参考链接:https://www.linuxidc.com/Linux/2010-03/24939.htm

Linux下清理内存和Cache方法 /proc/sys/vm/drop_caches

Linux下清理内存和Cache方法 /proc/sys/vm/drop_caches
 

频繁的文件访问会导致系统的Cache使用量大增

$ free -m
total used free shared buffers cached
Mem: 3955 3926 28 0 55 3459
-/+ buffers/cache: 411 3544
Swap: 5726 0 5726

free内存减少到几十兆,系统运行缓慢

运行sync将dirty的内容写回硬盘
$sync

通过修改proc系统的drop_caches清理free的cache
$echo 3 > /proc/sys/vm/drop_caches

drop_caches的详细文档如下:
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.

修改/etc/sysctl.conf 添加如下选项后就不会内存持续增加
vm.dirty_ratio = 1
vm.dirty_background_ratio=1
vm.dirty_writeback_centisecs=2
vm.dirty_expire_centisecs=3
vm.drop_caches=3
vm.swappiness =100
vm.vfs_cache_pressure=163
vm.overcommit_memory=2
vm.lowmem_reserve_ratio=32 32 8
kern.maxvnodes=3

上面的设置比较粗暴,使cache的作用基本无法发挥。需要根据机器的状况进行适当的调节寻找最佳的折衷。

Linux下清理内存和Cache方法的更多相关文章

  1. Linux下清理内存和Cache方法 /proc/sys/vm/drop_caches

    Linux下清理内存和Cache方法 /proc/sys/vm/drop_caches 频繁的文件访问会导致系统的Cache使用量大增 $ free -m total used free shared ...

  2. Linux下清理内存和Cache方法见下文:

    暂时目前的环境处理方法比较简单: 在root用户下添加计划任务: */10 * * * * sync;echo 3 > /proc/sys/vm/drop_caches; 每十分钟执行一次,先将 ...

  3. Linux/Centos下清理内存和Cache方法

    Linux/Centos下释放内存和缓存方法 $ free -m 运行sync将dirty的内容写回硬盘$ sync 通过修改proc系统的drop_caches清理free的cache$ echo ...

  4. Linux下查看内存使用情况方法总结

    Linux查看CPU和内存使用情况:http://www.cnblogs.com/xd502djj/archive/2011/03/01/1968041.html 在做Linux系统优化的时候,物理内 ...

  5. Linux 下查看内存使用情况方法总结

    Linux查看CPU和内存使用情况:http://www.cnblogs.com/xd502djj/archive/2011/03/01/1968041.html 在做Linux系统优化的时候,物理内 ...

  6. [转载] Linux下查看内存使用情况方法总结

    原文: http://9iphp.com/linux/1247.html 强烈推荐 htop.

  7. 如何在Linux上清理内存缓存、缓冲与交换空间

    如何在Linux上清理内存缓存.缓冲与交换空间 与其他类型的操作系统一样,GNU/Linux已经有效的实现了内存管理,甚至更加优秀.但是如果任何进程正在吃光你的内存,并且你想清理它,Linux提供了一 ...

  8. Linux下memcached安装和启动方法

    Linux下memcached安装和启动方法 1. 首先下载memcached 和 libevent 包. Memcached用到了libevent这个库用于Socket的处理.下面是下载的两个包文件 ...

  9. Linux下Git和GitHub使用方法总结

    来源:Linux下Git和GitHub使用方法总结 1 Linux下Git和GitHub环境的搭建 第一步: 安装Git,使用命令 “sudo apt-get install git” 第二步: 到G ...

随机推荐

  1. CentOS 7 休眠系统

    CentOS 7的电源按钮只有关机和重启两项,但是可以用命令来休眠系统: 重启: $ systemctl reboot 退出系统并停止电源: $ systemctl poweroff 待机: $ sy ...

  2. Codeforces 1130D1 Toy Train (Simplified) (思维)【贪心】

    <题目链接> 题目大意: 有一个的环形火车站,其中有$[1,n] n$个站台,站台上能够放糖果,火车只能朝一个方向移动,如果火车在站台$i$,那么下一秒就会在$i+1$站(如果$i=n$, ...

  3. flex 布局的复习

  4. Oracle date-time

    Name Description ADDDATE() Add time values (intervals) to a date value ADDTIME() Add time CONVERT_TZ ...

  5. Linux学习笔记10

    创建文件 touch touch filenames 创建文件夹 mkdir mkdir dir3 dir4 dir5 建立多个文件夹 mkdir ~/games  在登录用户的本目录之下建立game ...

  6. MacOs brew 命令行安装常见工具

    brew类似ubuntu系统下的apt-get的功能 安装方法:  在Mac中打开Termal:  输入命令: ruby -e "$(curl -fsSL https://raw.githu ...

  7. python 3.6 + numpy + matplotlib + opencv + scipy 安装

    首先,下载并安装 python3.6: 然后,在网址http://www.lfd.uci.edu/~gohlke/pythonlibs/ 上 分别下载 numpy.scipy.matplotlib.o ...

  8. 【Intellij IDEA】eclipse项目导入

    intellij idea中文资料网上比较少,对于eclipse的项目如何导入intellij idea也没有完整的说明,本人在这里整理下,方便更多人加入到intellij idea的阵容里. 直接上 ...

  9. Codeforces.97D.Robot in Basement(bitset 模拟)

    题目链接 (ozr attack) 考虑怎么暴力,就是先在所有非障碍格子上全放上机器人,然后枚举每一步,枚举每个机器人移动这一步,直到所有机器人都在出口位置.复杂度是\(O(nmk)\)的. 怎么优化 ...

  10. Codeforces Round #443 (Div. 1) D. Magic Breeding 位运算

    D. Magic Breeding link http://codeforces.com/contest/878/problem/D description Nikita and Sasha play ...