linux系统释放cache,释放linux cache

The following is the state of  memory utilization in my desktop.$ free -mtotal        used       free      shared    buffers     cachedMem:          1987       1805        181          0         230          1298-/+ buffers/cache:        276       1710Swap:         1906           0         1906We can see from the first row,  "free" is reporting only 181M to be free and around 1298M has been used for disk cache.

Now let's tune  /proc/sys/vm/drop_caches to release the memory used for cache. We can specify 3 values to drop_caches. Default value is 0 which tells to cache apps. The significance of 3 values are:

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

I will now configure drop_caches with a value of 1 to drop the cache. Let's now check the memory consumption status on the host.

$ echo "1" | sudo tee /proc/sys/vm/drop_caches

1

$ free -m

total        used       free     shared    buffers     cached

Mem:          1987        879       1108          0          0            609

-/+ buffers/cache:        269      1718

Swap:         1906          0         1906

We can now see from the first row that there is a gain of  free memory from 181M to 1108M and cached has reduced from 1298M to 609M. So ,we released some amount of RAM occupied by cache.But ofcourse as earlier said we don't want to do it in a production box.Also , this does not mean that applications will not be cached in memory any more . If we execute any application , the application will be loaded into the cache.I tried executing the dd command to see the memory consumption. The following is the memory usage after terminating the dd command.

$ dd if=/dev/zero of=test

dd: writing to `test': No space left on device

2856305+0 records in

2856304+0 records out

1462427648 bytes (1.5 GB) copied, 25.7104 s, 56.9 MB/s

[

$ free -mtotal       used       free     shared    buffers     cachedMem:          1987       1922         65          0          4       1670-/+ buffers/cache:        247       1740Swap:         1906          0       1906We can see that the cache has again started filling up. So , from the above examples looks very much clear how we can release cache space by tuning the drop_cache parameter.

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

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值