Linux释放cache内存



作者: yibin  出自: http://www.linuxdiyf.com
/proc是个虚拟文档体系,我们可以颠末对他的读写操作做为和kernel实体间中止通讯的一种才智.也等于说可以颠末批改/proc中的文档,来对以后kernel的举动做出调整.那么我们可以颠末调整/proc/sys/vm/drop_caches来释放内存.操作如下:

[root@server test]# cat /proc/sys/vm/drop_caches
0

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

[root@server test]# sync

手动实行sync敕令(形貌:sync 敕令运转 sync 子例程。倘使必需中止体系,则运转 sync 敕令以确保文档体系的齐备性。sync 敕令将任何未写的体系缓冲区写到磁盘中,包罗已批改的 i-node、已耽误的块 I/O 和读写映射文档)

[root@server test]# echo 3 > /proc/sys/vm/drop_caches
[root@server test]# cat /proc/sys/vm/drop_caches
3

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

[root@server test]# free -m
total used free shared buffers cached
Mem: 249 66 182 0 0 11
-/ buffers/cache: 55 194
Swap: 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(8) first.




版权声明: 原创作品,允许转载,转载时请务必以超链接情势标明文章 原始来因 、作者信息和本声明。否则将清查法律责任。

原文地址:https://www.cnblogs.com/zgqjymx/p/1973563.html