Linux系统运行一个脚本之后内存占用很高,内存不会被正常释放,而一直作为caching,需要手动释放下。
[root@yumserver-222 ~]# free -m
             total       used       free     shared    buffers     cached
Mem:          3833        451       3381          0         33        185
-/+ buffers/cache:        232       3600
Swap:         4095          0       4095
运行某个脚本之后就很高了。
[root@yumserver-222 ~]# free -m
             total       used       free     shared    buffers     cached
Mem:          3833       1415       2417          0        103       1080
-/+ buffers/cache:        231       3601
Swap:         4095          0       4095
[root@yumserver-222 ~]#
====================================================================================
1.调整/proc/sys/vm/drop_caches来释放内存
默认/proc/sys/vm/drop_caches的值是0,可以通过更改其值来释放内存。
-----------
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.
------------
[root@yumserver-222 ~]# cat /proc/sys/vm/drop_caches
0
[root@yumserver-222 ~]# echo 3 > /proc/sys/vm/drop_caches
====================================================================================
2.sync
sync是强制系统把正在处理的pagecache,entry和inode写回硬盘的命令。sync 命令将所有未写的系统缓冲区写到磁盘中,包含已修改的 i-node、已延迟的块 I/O 和读写映射文件
sync - flush file system buffers, Force changed blocks to disk, update the super block.
[root@yumserver-222 ~]# sync
[root@yumserver-222 ~]# free -m
             total       used       free     shared    buffers     cached
Mem:          3833        139       3693          0          0          7
-/+ buffers/cache:        131       3701
Swap:         4095          0       4095
[root@yumserver-222 ~]#
内存就降下来了。