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

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

$ free -m
total used free shared buffers cached
Mem:
-/+ buffers/cache:
Swap:

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 > /proc/sys/vm/drop_caches
To free dentries and inodes:
* echo > /proc/sys/vm/drop_caches
To free pagecache, dentries and inodes:
* echo > /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..

修改/etc/sysctl.conf 添加如下选项后就不会内存持续增加

vm.dirty_ratio =
vm.dirty_background_ratio=
vm.dirty_writeback_centisecs=
vm.dirty_expire_centisecs=
vm.drop_caches=
vm.swappiness =
vm.vfs_cache_pressure=
vm.overcommit_memory=
vm.lowmem_reserve_ratio=
kern.maxvnodes=

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

Linux下清理内存和Cache方法 /proc/sys/vm/drop_caches的更多相关文章

  1. Linux下清理内存和Cache方法

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

  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. /proc/sys/vm/drop_caches 清理缓存

    1. 使用方法 /proc/sys/vm/drop_caches默认是0 # echo 1 > /proc/sys/vm/drop_caches; free pagecache, use# ec ...

  5. Linux中的Buffer Cache和Page Cache echo 3 > /proc/sys/vm/drop_caches Slab内存管理机制 SLUB内存管理机制

    Linux中的Buffer Cache和Page Cache echo 3 > /proc/sys/vm/drop_caches   Slab内存管理机制 SLUB内存管理机制 http://w ...

  6. linux内存——/proc/sys/vm/drop_caches

      原贴:http://www.linuxfly.org/post/320/ http://blog.csdn.net/chinalinuxzend/article/category/265273/2 ...

  7. 手工释放linux内存——/proc/sys/vm/drop_caches

    --手工释放linux内存——/proc/sys/vm/drop_caches 总有很多朋友对于Linux的内存管理有疑问,之前一篇日志似乎也没能清除大家的疑虑.而在新版核心中,似乎对这个问题提供了新 ...

  8. [转]手工释放linux内存——/proc/sys/vm/drop_caches

    另一篇:http://www.linuxfly.org/post/320/   1.清理前内存使用情况 free -m 2.开始清理  echo 1 > /proc/sys/vm/drop_ca ...

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

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

随机推荐

  1. PHP 基础知识测试题 答案分析

    一:选择题(单项选择,每题2分): 1. LAMP具体结构不包含下面哪种(A      ) A:Windows系统              如果是这个就是WMP B:Apache服务器 C:MySQ ...

  2. PHP 知识点

    __tostring()     注:能够直接输出对象 class Ren { public $name; function Run() { echo "跑"; } functio ...

  3. iOS-Xcode使用技巧

    一.快捷键的使用 经常用到的快捷键如下: 新建 shift + cmd + n     新建项目 cmd + n             新建文件 视图 option + cmd + 回车 打开助理编 ...

  4. JavaScript必须了解的知识点总结。

    整理的知识点不全面但是很实用. 主要分三块: (1)JS代码预解析原理(包括三个段落): (2)函数相关(包括 函数传参,带参数函数的调用方式,闭包): (3)面向对象(包括 对象创建.原型链,数据类 ...

  5. memset

    函数原型: void *memset(void *s, int ch, size_t n); 函数解释:将s中当前位置后面的n个字节 (typedef unsigned int size_t )用 c ...

  6. rabbitMQ第五篇:Spring集成RabbitMQ

    前面几篇讲解了如何使用rabbitMq,这一篇主要讲解spring集成rabbitmq. 首先引入配置文件org.springframework.amqp,如下 <dependency> ...

  7. 今天不谈技术,说说一些常用的软件~By 逆天

    前端工具:http://www.cnblogs.com/dunitian/p/5640147.html    在线办公: http://word.baidu.com/welcome.html http ...

  8. WPF datagrid 加入图片

    <DataGridTemplateColumn Header="图像" Width="SizeToCells"> <DataGridTempl ...

  9. Neutron Vlan Network 原理- 每天5分钟玩转 OpenStack(92)

    前面我们陆续学习了 Neutron local network,flat network 和 DHCP 服务,从本节将开始讨论 vlan network. vlan network 是带 tag 的网 ...

  10. 连接第二个 insance 到 first_local_net - 每天5分钟玩转 OpenStack(83)

    上一节在 first_local_net 中已经部署了 cirros-vm1,今天将再部署一个instance,并验证两个 instance 的连通性. 以同样的方式 launch instance ...