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. poj1651 Multiplication Puzzle

    比较特别的区间dp.小的区间转移大的区间时,也要枚举断点.不过和普通的区间dp比,断点有特殊意义.表示断点是区间最后取走的点.而且一个区间表示两端都不取走时中间取走的最小花费. #include &l ...

  2. TCP文件发送

    发送端(客户端) #include <iostream> #include <winsock2.h> #include <Ws2tcpip.h> #include ...

  3. IOS-底层数据结构

      Objective-C底层数据结构 类的数据结构 Class(指针) typedef struct objc_class *Class; /* 这是由编译器为每个类产生的数据结构,这个结构定义了一 ...

  4. OC 文件基本操作

    // // main.m // oc_13 // // Created by ma c on 15/12/17. // Copyright (c) 2015年 博文科技. All rights res ...

  5. SQL优化(SQL TUNING)可大幅提升性能的实战技巧之一——让计划沿着索引跑

    我们进行SQL优化时,经常会碰到对大量数据集进行排序,然后从排序后的集合取前部分结果的需求,这种情况下,当我们按照常规思路去写SQL时,系统会先读取过滤获得所有集合,然后进行排序,再从排序结果取出极少 ...

  6. spring cloud 学习(二)关于 Eureka 的学习笔记

    关于 Eureka 的学习笔记 个人博客地址 : https://zggdczfr.cn/ ,欢迎光临~ 前言 Eureka是Netflix开发的服务发现组件,本身是一个基于REST的服务.Sprin ...

  7. Jpa实体类生成图解

    Jpa实体类生成图解   创建连接     创建项目  

  8. jsp jsp运行原理

    JSP的运行原理  每个jsp页面在第一次被访问时,WEB容器都会把请求交给jsp引擎(一个java程序).Jsp 引擎先将jsp翻译成一个_jspServlet实质上也是一个servlet,然后按照 ...

  9. 快速切题 poj1129 Channel Allocation

    Channel Allocation Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 12334   Accepted: 63 ...

  10. Flask初级(七)flash模板循环,判断

    Project name :Flask_Plan templates:templates static:static 继续前面的代码 修改Flask_Plan.py @app.route('/') d ...