释放内存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