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

在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. 爬虫1 socket方式下载一张图片

    import socket import re client = socket.socket() # 图片url img_url = 'https://img03.sogoucdn.com/app/a ...

  2. The Monocycle(bfs)

    题目描述: 转载自:https://blog.csdn.net/h1021456873/article/details/54572767 题意: 给你一个转轮,有5种颜色,为了5中颜色的位置是确定的, ...

  3. soul

    mark,数据使用gzip加密,因为公司网络卡,明天后天看.

  4. java接口签名(Signature)实现方案续

    一.前言 由于之前写过的一片文章 (java接口签名(Signature)实现方案 )收获了很多好评,此次来说一下另一种简单粗暴的签名方案.相对于之前的签名方案,对body.paramenter.pa ...

  5. C#选择文件、选择文件夹、打开文件

    1.选择文件用OpenDialog OpenFileDialog dialog = new OpenFileDialog(); dialog.Multiselect = true;//该值确定是否可以 ...

  6. id生成器,分布式ID自增算法(Snowflake 算法)

    接口: /** * id生成器 */ public interface IdGenerator { String next(); } 实现类: /** * 分布式ID自增算法<br/> * ...

  7. bzoj3033: 太鼓达人 欧拉路径

    题目链接 bzoj3033: 太鼓达人 题解 对于k-1位点,k位二进制位边,将点的转移连起来 每个点的入度和出度相等并且全部是偶点 只需要在这个图中找字典序最小的欧拉回路 可以贪心地找字典序较小的边 ...

  8. Java实现FTP与SFTP文件上传下载

    添加依赖Jsch-0.1.54.jar <!-- https://mvnrepository.com/artifact/com.jcraft/jsch --> <dependency ...

  9. 2017-9-13-Linux移植:u-boot的移植

    1.u-boot下载地址:http://ftp.denx.de/pub/u-boot/ 2.Linux环境下使用tar命令解压压缩包:tar -xzvf file.tar.gz tar -xvf fi ...

  10. Shell脚本笔记(六)呈现数据

    呈现数据 一.文件描述符 Linux系统将每个对象当做文件处理,这包括输入和输出进程.Linux用文件描述符来标识每个文件对象.每个进程最多可以有9个 文件描述符,bash shell保留了前三个文件 ...