linux如何手动释放内存吗,手动释放Linux内存

一台机子监控报警,内存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来限制用户的内存分配 参考: 外链网址已屏蔽

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值