1. 使用方法

/proc/sys/vm/drop_caches默认是0

# echo 1 > /proc/sys/vm/drop_caches; free pagecache, use
# echo 2 > /proc/sys/vm/drop_caches; free dentries and inodes
# echo 3 > /proc/sys/vm/drop_caches; free pagecache, dentries and inodes

注意:使用之前需要先sync,将缓存刷到磁盘中。

2. 实验

单位:MB

# free -m
total used free shared buff/cache available
Mem: 79
Swap:
# cp /etc/* /mytest/
# free -m
total used free shared buff/cache available
Mem: 1825 382 1341 8 1412
Swap: 0 0 0 过一段时间: # free -m
total used free shared buff/cache available
Mem: 1825 382 1341 8 1412
Swap: 0 # cat /proc/sys/vm/drop_caches
0 # sync # echo 3 > /proc/sys/vm/drop_caches
# free -m
total used free shared buff/cache available
Mem: 1825 382 1405 8 1413
Swap:

3. 写个脚本做这个事情

# cat cleanup_cache.sh
#!/bin/sh
# drop_caches for every mins drop_caches() {
echo "Drop caches."
sync
echo > /proc/sys/vm/drop_caches &
return
} while true; do
sleep
drop_caches
done exit

4. 结论

Linux内核默认保持drop_cache的值是0,不建议经常修改它。

/proc/sys/vm/drop_caches 清理缓存的更多相关文章

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

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

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

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

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

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

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

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

  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_cache

    linux的内存查看: [root@localhost 0.1.0]# free -m                   total       used       free     shared ...

  7. 手工释放linux内存------/proc/sys/vm/drop_cache

    当在Linux下频繁存取文件后,物理内存会很快被用光,当程序结束后,内存不会被正常释放,而是一直作为caching.这个问题,貌似有不少人在问,不过都没有看到有什么很好解决的办法.那么我来谈谈这个问题 ...

  8. /proc/sys/shm/drop_caches

    author:skate time:2012/02/22 手工释放linux内存--/proc/sys/vm/drop_cache 转载一篇文章 linux的内存查看: [root@localhost ...

  9. /proc/sys/vm man手册

    Manual page proc(5) line 1967 (press h for help or q to quit) /proc/sys/vm This directory contains f ...

随机推荐

  1. LeetCode--202--快乐数

    问题描述: 编写一个算法来判断一个数是不是“快乐数”. 一个“快乐数”定义为:对于一个正整数,每一次将该数替换为它每个位置上的数字的平方和,然后重复这个过程直到这个数变为 1,也可能是无限循环但始终变 ...

  2. 3-8《Ruby元编程》第二章对象模型

    <Ruby元编程> 第二章 对象模型 类定义揭秘inside class definitions: class关键字更像一个作用域操作符,核心作用是可以在里面随时定义方法. [].meth ...

  3. Jersey 2.x 运行项目

    现在我们已经有可以可以运行的项目了,让我们队这个项目进行一些测试吧. 你需要运行下面的一些命令行: mvn clean test 这个命令将会对项目进行编译后运行单元测试. 你应该会看到和下面类似的输 ...

  4. UVA557 汉堡 Burger

    题面 https://www.luogu.org/problemnew/show/UVA557 这里顺便整理一下二维格点随机游走问题. 遇到这种问题时,需注意分母的计算问题. 设x为起点到终点的距离. ...

  5. M爷的线段树

    M爷的线段树 - BUCTOJ 3305 一个长度为n的数列A.修改m次,每次给区间[L,R]中的每一个数加X.查询k次,每次查询第i个元素的值并输出.1<=n<=1e5 ,1<=m ...

  6. EBS开发附件上传和下载功能(转)

    原文地址: EBS开发附件上传和下载功能 上传 Oracle ERP二次开发中使用的方式有两种,一是通过标准功能,在系统管理员中定义即可,不用写代码,就可以使几乎任何Form具有附件功能,具体参考系统 ...

  7. java连接MySql数据库 zeroDateTimeBehavior

    JAVA连接MySQL数据库,在操作值为0的timestamp类型时不能正确的处理,而是默认抛出一个异常, 就是所见的:java.sql.SQLException: Cannot convert va ...

  8. Asterisk——part 1

    Asterisk Russell Bryant Asterisk1 is an open source telephony applications platform distributed unde ...

  9. Win10 dell驱动触摸板安装

    Win10 dell驱动触摸板安装 在此之前安装驱动后要重启

  10. PHP:第一章——PHP中十进制、二进制、八进制、十六进制转换

    //十进制.二进制.八进制.十六进制转换 //十进制转换为二进制decbin()函数: //echo decbin(5);//输出:101 //十进制转换为八进制decoct()函数 //echo d ...