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--205--同构字符串

    问题描述: 给定两个字符串 s 和 t,判断它们是否是同构的. 如果 s 中的字符可以被替换得到 t ,那么这两个字符串是同构的. 所有出现的字符都必须用另一个字符替换,同时保留字符的顺序.两个字符不 ...

  2. Skills CodeForces - 614D (贪心)

    链接 大意: $n$门课, 第$i$门分数$a_i$, 可以增加共$m$分, 求$cnt_{mx}*cf+mi*cm$的最大值 $cnt_{mx}$为满分的科目数, $mi$为最低分, $cf$, $ ...

  3. Sergey's problem CodeForces - 1019C (图论,构造,神题)

    链接 大意: 给定有向图, 求选择一个点集$S$, 使得$S$任意两点不相连, 且对于不属于$S$的任意点$x$, 均存在$S$中的点$y$, 使得$d(x,y)<=2$, $d(x,y)$为从 ...

  4. linux 不解压日志压缩包直接搜索里面的内容

  5. 『科学计算』可视化二元正态分布&3D科学可视化实战

    二元正态分布可视化本体 由于近来一直再看kaggle的入门书(sklearn入门手册的感觉233),感觉对机器学习的理解加深了不少(实际上就只是调包能力加强了),联想到假期在python科学计算上也算 ...

  6. 『cs231n』计算机视觉基础

    线性分类器损失函数明细: 『cs231n』线性分类器损失函数 最优化Optimiz部分代码: 1.随机搜索 bestloss = float('inf') # 无穷大 for num in range ...

  7. juqery的一些简单用法

    层级选择器(重点).基本过滤选择器 :eq(index) 选择匹配到的元素中索引号为index的一个元素,index从0开始 :odd 选择匹配到的元素中索引号为奇数的所有元素,index从0开始 : ...

  8. Linux磁盘管理,vi编辑器以及包管理器

    一.Linux磁盘管理 Linux磁盘管理常用的三个命令为df,du,fdisk df:列出文件系统的整体磁盘使用量,利用这个命令来获取磁盘被占用了多少空间,,目前还剩下多少空间用法:df [-ahi ...

  9. seo-摘自网友

    网页前端制作中的SEO 在SEO盛行的今天到处都在谈优化,对于网站前端制作人员来说,有几点是跟SEO相关的,也就是SEO站内优化中的一部分,下面总结几点: 1.title,<title>页 ...

  10. kubernetes资源清单入门

    创建nginx容器: kubectl run nginx-deploy8 --image=nginx:1.14-alpine --port=80 --replicas=2 deployment &qu ...