博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
Linux下清理内存和Cache方法
阅读量:6955 次
发布时间:2019-06-27

本文共 1244 字,大约阅读时间需要 4 分钟。

 频繁的文件访问会导致系统的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的作用基本无法发挥。需要根据机器的状况进行适当的调节寻找最佳的折衷。

转载于:https://www.cnblogs.com/dailidong/p/7571188.html

你可能感兴趣的文章
Foxify v0.10.7 发布,基于 TypeScript 的 Node 框架
查看>>
Python数据结构——双端队列
查看>>
GitHub 项目推荐:用深度学习让你的照片变得美丽 ...
查看>>
另类文件加密 图片当密码给文本加密
查看>>
MySQL数据库如何解决大数据量存储问题
查看>>
CENTOS6.5 yum配置
查看>>
《自顶向下网络设计(第3版)》——1.6 复习题
查看>>
【转】微信小程序给程序员带来的可能是一个赚钱的机遇
查看>>
《Programming Ruby中文版:第2版》终于正式出版了
查看>>
使用Observium来监控你的网络和服务器
查看>>
蚂蚁区块链团队资讯简报20170514
查看>>
线性空间(向量空间)
查看>>
多媒体之录音
查看>>
mysql 分区类型详解
查看>>
ORACLE同义词总结
查看>>
ios字体设置
查看>>
【SICP练习】51 练习2.19
查看>>
solveCrossprod求 X'X的逆, ( X' == t(X), 即X的行列变换矩阵 )
查看>>
PostgreSQL column cryptographic use pgcrypto extension and optional openssl lib
查看>>
通过支付宝服务中断事件看系统可靠性和YunOS的可靠性
查看>>