读写文件时,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. SQL 计算两个地理坐标相差的距离的函数

    Create function getGreatCircleDistance(@lat1 decimal(18,11),@lng1 decimal(18,11),@lat2 decimal(18,11 ...

  2. .Net判断一个对象是否为数值类型

    这乍一听是个很简单的事,但突然搞起来还真有点无从下手的感觉. 首先当然是通过GetType()方法反射获取其类型信息,然后对其进行分析,但是类型信息Type中并没有简单地给出这么一个属性进行判断. 老 ...

  3. [Notes] Timer Comparision when turn influence computing on/off

    Overall algorithm – bunny 关闭influence计算                                                             ...

  4. 选择什么样的DOCTYPE

  5. KindleEditor上传文件报404

    初步怀疑是iis配置的允许上传大小太小了,然后就修改了配置文件但是不起作用. 后来百度了下iis版本是7.5,然后就按照iis8 的配置: IIS8请求筛选模块被配置为拒绝超过请求内容长度,在&quo ...

  6. interactivePopGestureRecognizer

    苹果一直都在人机交互中尽力做到极致,在iOS7中,新增加了一个小小的功能,也就是这个api:self.navigationController.interactivePopGestureRecogni ...

  7. exec、source以及bash的区别(zz)

    在bash shell中,source.exec以及sh都可以用来执行shell script,但是它们的差别在哪里呢? sh:父进程会fork一个子进程,shell script在子进程中执行 so ...

  8. hdoj 1869 六度分离

    Problem Description 1967年,美国著名的社会学家斯坦利·米尔格兰姆提出了一个名为“小世界现象(small world phenomenon)”的著名假说,大意是说,任何2个素不相 ...

  9. iis下设置php最大执行时间

    php在执行中常见错误: The FastCGI process exceeded configured request timeout: FastCGI process exceeded confi ...

  10. Java LinkedList 源码剖析

    LinkedList同时实现了List接口和Deque接口,也就是说它既可以看作一个顺序容器,又可以看作一个队列(Queue),同时又可以看作一个栈(Stack).这样看来,LinkedList简直就 ...