手动释放cache

释放内存cache,首先我们要查看一下使用情况

例如我的电脑:

 hadoop:root:/root:>free -m
             total       used       free     shared    buffers     cached
Mem:          1869        265       1603          0         22        101
-/+ buffers/cache:        141       1728
Swap:         2047          0       2047

可以看出来,我的cache和buffer并不是太多,嘿嘿嘿,当然我的内存也没多大。
首先我们需要怎么做呢
第一步,先将缓存区的脏数据写入到磁盘中:
使用sync命令

hadoop:root:/root:>sync

第二步对一个记录缓存释放参数的文件进行赋值,我通常选择赋值为3,之后再解释。
这个文件地址为
/proc/sys/vm/drop_caches

 hadoop:root:/root:>echo 3 >/proc/sys/vm/drop_caches 
hadoop:root:/root:>free -m
             total       used       free     shared    buffers     cached
Mem:          1869        171       1698          0          0         33
-/+ buffers/cache:        137       1732
Swap:         2047          0       2047

大家可以看到我的buffer和cache十分明显的减少了。

第三步 我们把大象放进冰箱需要三步,这个同样也需要三步,我们需要讲这个参数恢复为0.

hadoop:root:/root:>echo 0 >/proc/sys/vm/drop_caches 

最后,我对这0,1,2,3这三个参数进行解释

这是外文解释

/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 first

简单来说就是
1:释放pagecache(页高速缓冲存储器)
2:释放dentries 和 inodes
3:释放pagecache、dentries 和 inodes

若泽大数据交流群:671914634

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值