读写文件时,Linux内核为了提高读写效率与速度,会将文件在内存中进行缓存,这就是Cache Memory(缓存内存)。
即使程序运行结束后,Cache Memory也不会自动释放。这就会导致程序频繁读写文件后,可用物理内存会很少。
其实这缓存内存(Cache Memory)在你需要使用内存的时候会自动释放,所以不必担心没有内存可用。
如果你希望手动去释放Cache Memory(缓存内存)的话也是有办法的。

清理缓存(drop_caches)的官方文档:http://www.kernel.org/doc/Documentation/sysctl/vm.txt

==============================================================
drop_caches

Writing to this will cause the kernel to drop clean caches, as well as
reclaimable slab objects like dentries and inodes.  Once dropped, their
memory becomes free.

To free pagecache:
echo 1 > /proc/sys/vm/drop_caches
To free reclaimable slab objects (includes dentries and inodes):
echo 2 > /proc/sys/vm/drop_caches
To free slab objects and pagecache:
echo 3 > /proc/sys/vm/drop_caches

This is a non-destructive operation and will not free any dirty objects.
To increase the number of objects freed by this operation, the user may run
`sync' prior to writing to /proc/sys/vm/drop_caches.  This will minimize the
number of dirty objects on the system and create more candidates to be
dropped.

This file is not a means to control the growth of the various kernel caches
(inodes, dentries, pagecache, etc...)  These objects are automatically
reclaimed by the kernel when memory is needed elsewhere on the system.

Use of this file can cause performance problems.  Since it discards cached
objects, it may cost a significant amount of I/O and CPU to recreate the
dropped objects, especially if they were under heavy use.  Because of this,
use outside of a testing or debugging environment is not recommended.

You may see informational messages in your kernel log when this file is
used:
cat (1234): drop_caches: 3

These are informational only.  They do not mean that anything is wrong
with your system.  To disable them, echo 4 (bit 3) into drop_caches.
==============================================================
cat /proc/sys/vm/drop_caches
0 //默认是0;1-清空页缓存;2-清空inode和目录树缓存;3-清空所有缓存
[root@bak ~]# sync //注意:在清空缓存之前使用sync命令同步数据到磁盘
[root@bak ~]# free -m
             total       used       free     shared    buffers     cached
Mem:         15898       3029      12869          0        191       1064
-/+ buffers/cache:       1772      14125
Swap:        31999          0      31999
[root@bak ~]# echo 3 > /proc/sys/vm/drop_caches
[root@bak ~]# free -m //发现缓存明显减少了
             total       used       free     shared    buffers     cached
Mem:         15898       1770      14128          0          1         30
-/+ buffers/cache:       1738      14160
Swap:        31999          0      31999

centos 清理内存缓存的更多相关文章

  1. 如何在Linux上清理内存缓存、缓冲与交换空间

    如何在Linux上清理内存缓存.缓冲与交换空间 与其他类型的操作系统一样,GNU/Linux已经有效的实现了内存管理,甚至更加优秀.但是如果任何进程正在吃光你的内存,并且你想清理它,Linux提供了一 ...

  2. Centos清理内存 内存回收释放及内存使用查看的相关命令

    在清理前内存使用情况 free -m 用以下命令清理内存 echo 1 > /proc/sys/vm/drop_caches 清理后内存使用情况再用以下命令看看. free –m 多出很多内存了 ...

  3. linux清理内存缓存cache

    Linux服务器有自己先进的内存管理机制,有时候会发现我们系统的buff/cache内存占用会越来越高,操作系统也有卡顿的情况,遇到这种情况,不妨试试下面的方法. 1步骤一:我们先查看物理内存占用情况 ...

  4. linux 过滤内存使用率并于计划任务结合来自动清理内存缓存

    过滤出内存使用率并进行判断 #!/bin/bash echo "###cleand free_cache script########" #memory usage mem_pus ...

  5. [sh]清理memcached缓存

    #!/bin/bash ###author xxx ###date xxx ###清理内存缓存 used=`free -m | awk 'NR==2' | awk '{print $3}'` free ...

  6. CentOS7清理yum缓存和释放内存方法

    清理yum缓存 清理yum缓存使用yum clean 命令,yum clean 的参数有headers, packages, metadata, dbcache, plugins, expire-ca ...

  7. Android Glide数据更新及内存缓存、硬盘缓存清理

    [转] 原文                                         Android Glide数据更新及内存缓存.硬盘缓存清理 Android的Glide在加载图片时候内部默 ...

  8. Centos下查看cpu、磁盘、内存使用情况以及如何清理内存

    核查服务器基本情况 查看内存使用情况 free -m 查看cpu使用情况 top #查看进程运行情况 查看磁盘以及分区情况 df -h 查看网络情况 ifconfig 查看端口使用情况 #1.方法一 ...

  9. Memcache内存缓存框架

    转载请注明原文地址:https://www.cnblogs.com/ygj0930/p/10923221.html 一:Memcache是什么,为什么要用它 MemCache是一个高性能.“分布式”的 ...

随机推荐

  1. [技巧.Dotnet]轻松实现“强制.net程序以管理员身份运行”。

    使用场景: 程序中不少操作都需要特殊权限,有时为了方便,直接让程序以管理员方式运行. (在商业软件中,其实应该尽量避免以管理员身份运行.在安装或配置时,提前授予将相应权限.) 做法: 以C#项目为例: ...

  2. ASP.NET控件<ASP:Button /> html控件<input type="button">区别联系

    ASP.NET控件<ASP:Button />-------html控件<input type="button">杨中科是这么说的:asp和input是一样 ...

  3. aspnet超级链接 传递 当前页面 textbox值

    一共有两个窗体. 第一个窗体A传参到窗体B  A的参数是A窗体的textbox 窗体A代码 <html xmlns="http://www.w3.org/1999/xhtml" ...

  4. flask-admin章节四:flask session的使用

    1. 关于session flask session可能很多人根本都没有使用过,倒是cookie大家可能使用得比较多.flask cookie使用起来比较简单,就两个函数,读取和设置. 具体使用方式如 ...

  5. MSMQ(Microsoft Message Queue)

    http://www.cnblogs.com/sk-net/archive/2011/11/25/2232341.html 利用 MSMQ(Microsoft Message Queue),应用程序开 ...

  6. ATL 获取flash信息

    // This goes past the ATL includes #import "C:/WINDOWS/system32/Macromed/Flash/Flash9e.ocx" ...

  7. 深入研究C语言 第三篇

    本篇研究TC2.0下其他几个工具.同时看看TC由源代码到exe程序的过程. 1. 用TCC将下面的程序编为.obj文件 我们知道,TCC在默认的编译连接一个C语言的源程序a.c的时候分为以下两步: ( ...

  8. 不同包中继承关系访问protected内部类问题

    有两个包pack1和pack2,pack1中是父类,pack2中子类继承自pack1中的父类.这里主要探索一下子类访问父类中protected内部类的问题: 第一个类: package pack1; ...

  9. exp

    想将远程机器上的数据库备份,搞了一上午,终于解决了: exp 用户名/密码@ip/service名 file=地址+文件名

  10. Xamarin +vs2015 Android 开发GPS loaction 返回 null 小结

    最近公司要开发android 所以研究了一下Xamarin  to android 中个GPS 废话不多说,说重点. 想获取手机上的gps信息必不可少的就是要使用 LocationManager Lo ...