博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
手动释放linux内存cache
阅读量:4216 次
发布时间:2019-05-26

本文共 1528 字,大约阅读时间需要 5 分钟。

 free -m 可以查看系统内存使用情况

系统中明明没有几个进程,可是内存占用几乎100%

后来发现原来被缓存占用了(见下图中cached部分)

手工释放内存的cache 

网上找到的文章,写的非常好,效果明显

free -m 各个参数的说明

total 内存总数

used 已经使用的内存数
free 空闲的内存数
shared 多个进程共享的内存总额
buffers Buffer Cache和cached Page Cache 磁盘缓存的大小
-buffers/cache (已用)的内存数:used - buffers - cached
+buffers/cache(可用)的内存数:free + buffers + cached
可用的memory=free memory+buffers+cached

以下为释放缓存的具体操作,都是从文章中粘出来的

/proc是一个虚拟文件系统,我们可以通过对它的读写操作做为与kernel实体间进行通信的一种手段。也就是说可以通过修改/proc中的文件,来对当前kernel的行为做出调整。那么我们可以通过调整/proc/sys/vm/drop_caches来释放内存。操作如下:

# cat /proc/sys/vm/drop_caches0

首先,/proc/sys/vm/drop_caches的值,默认为0。

# sync

手动执行sync命令(描述:sync 命令运行 sync 子例程。如果必须停止系统,则运行sync 命令以确保文件系统的完整性。sync 命令将所有未写的系统缓冲区写到磁盘中,包含已修改的 i-node、已延迟的块 I/O 和读写映射文件)

# echo 3 > /proc/sys/vm/drop_caches# cat /proc/sys/vm/drop_caches3

将/proc/sys/vm/drop_caches值设为3

# free -mtotal used free shared buffers cachedMem: 249 66 182 0 0 11-/+ buffers/cache: 55 194Swap: 511 0 511

再来运行free命令,会发现现在的used为66MB,free为182MB,buffers为0MB,cached为11MB。那么有效的释放了buffer和cache。

有关/proc/sys/vm/drop_caches的用法在下面进行了说明

/proc/sys/vm/drop_caches (since Linux 2.6.16)

Writing to this file causes the kernel to drop clean caches,dentries and inodes from memory, causing that memory to become free.
To free pagecache, use echo 1 > /proc/sys/vm/drop_caches;
to free dentries and inodes, use echo 2 > /proc/sys/vm/drop_caches;
to free pagecache, dentries and inodes, use echo 3 > /proc/sys/vm/drop_caches.
Because this is a non-destructive operation and dirty objects are not freeable, the user should run sync first

 

转载地址:http://cenmi.baihongyu.com/

你可能感兴趣的文章
《浪潮之巅》5奔腾的芯 英特尔公司
查看>>
《浪潮之巅》7 互联网的金门大桥 -—思科公司
查看>>
《浪潮之巅》8英名不朽---杨致远、菲洛和雅虎公司
查看>>
《浪潮之巅》9硅谷的见证人———惠普公司
查看>>
优秀的人都将是孤独的
查看>>
android 实现摇一摇功能
查看>>
android 侧滑事件的监听
查看>>
创新中国总决赛之行
查看>>
当你厌恶一个人时,你要想一下你是否也是这样的一个人
查看>>
android 数据库sqlite的使用
查看>>
android 腾讯信鸽的使用
查看>>
Android 闹钟的实现详解
查看>>
Android 实现底部导航栏
查看>>
大二新学期开始
查看>>
java 中的集合
查看>>
Html 标签学习
查看>>
《浪潮之巅》 10没落的贵族--摩托罗拉公司
查看>>
《浪潮之巅》11 硅谷的另一面
查看>>
Android activity 之间的数据传递 bundle
查看>>
android Intent 常见用法和使用场景
查看>>