问题现状:free -m 后发现fee空间很小了8G内存只剩余243M,而其它应用占用内存并不大,这是因为linux的剩余空间不是free一个值决定,而是由free+buffers+cached=totalfree 。所以是buffers和cached占用了,实际是没有被占用的,也是可以应用的,非要让free看起来大,那就需要手动清理buffers和cached的内存。具体方法如下:
[[email protected] ~]# free -mtotal used free shared buffers cachedMem: 7978 7734 243 0 164 4545-/+ buffers/cache: 3024 4954Swap: 5535 124 5411
首先要保证数据完整性,同步一下缓存中数据到磁盘:
[[email protected] ~]# sync[[email protected] ~]# sync[[email protected] ~]# sync
清理一下buffers和cached的内存:【该值要依据实际情况而定】
[[email protected] ~]# echo 1 > /proc/sys/vm/drop_caches
[[email protected] ~]# echo 2 > /proc/sys/vm/drop_caches
[[email protected] ~]# echo 3 > /proc/sys/vm/drop_caches
还原/proc/sys/vm/drop_caches 值
[[email protected] ~]# echo 0 > /proc/sys/vm/drop_caches
[[email protected] ~]# free -m
total used free shared buffers cached
Mem: 7978 3037 4940 0 26 125
-/+ buffers/cache: 2886 5091
Swap: 5535 124 5411
[[email protected] ~]# cat /proc/sys/vm/drop_caches
0
To free pagecache:
* echo 1 > /proc/sys/vm/drop_caches
To free dentries and inodes:
* echo 2 > /proc/sys/vm/drop_caches
To free pagecache, dentries and inodes:
* echo 3 > /proc/sys/vm/drop_caches