一台机子监控报警,内存free的空间过小了,基本都被cached掉了,应用以外的数据操作将变慢,甚至可能会用到swap,就搜了一下,用手工的办法释放了部分内存。
环境: OS: CentOS 6.3
场景:
--释放前,free的值比较小了
[root@develop ~]# free -m
total used free shared buffers cached
Mem: 64378 59984 994 0 1908 51181
-/+ buffers/cache: 10294 54083
Swap: 32255 9 32246 同步过程
--将缓存数据先刷到磁盘
[root@develop ~]# more /proc/sys/vm/drop_caches
0
[root@develop ~]# sync
[root@develop ~]# echo 1 > /proc/sys/vm/drop_caches
[root@develop ~]# free -m
total used free shared buffers cached
Mem: 64378 18034 46344 0 4 8986
-/+ buffers/cache: 9042 55335
Swap: 32255 9 32246
--重新改回去
[root@develop ~]# echo 0 > /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. 这个办法并不是一个治标的办法,不过可以结合ulimit来限制用户的内存分配 参考: 外链网址已屏蔽