Linux下清除缓存 drop

1. 用命令 free -m 查看一下内存的使用情况:

然后清除缓存后再来查看一下内存的使用情况:

前后对比可发现,缓存由之前的110M缩小到了25M,效果比较明显。

2. 下面说一下 drop_caches:清空 pagecache:syncecho 1 > /proc/sys/vm/drop_caches或者:syncsysctl -w vm.drop_caches=1清空 dentries 和 inodes:syncecho 2 > /proc/sys/vm/drop_caches或者:syncsysctl -w vm.drop_caches=2清空所有缓存(pagecache、dentries 和 inodes):syncecho 3 > /proc/sys/vm/drop_caches或者:syncsysctl -w vm.drop_caches=33. 如果尝试向 drop_caches 中写入 0,会报下面错误:-bash: echo: write error: Invalid argument我的内核是3.4.39,64 位。至于什么原因,我没找到。但是从下面关于 drop_caches 的说明来看,drop_caches 的值并没有说可以设置成 0 的,但是 drop_caches 的默认值是 0。但是 2.6.x 的内核将 drop_caches 的值设置为 0 是没有问题的。关于 drop_caches:Kernels 2.6.16 and newer provide a mechanism to have the kernel drop the page cache and/or inode and dentry caches on command, which can help free up a lot of memory. Now you can throw away that script that allocated a ton of memory just to get rid of the cache…To use /proc/sys/vm/drop_caches, just echo a number to it.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

This is a non-destructive operation and will only free things that are completely unused. Dirty objects will continue to be in use until written out to disk and are not freeable. If you run "sync" first to flush them out to disk, these drop operations will tend to free more memory.

参考:

http://linux-mm.org/Drop_Caches

https://bbs.archlinux.org/viewtopic.php?id=127049

而你自己根本不想从中跑出来。学习啦分享旅行唯美心情说说语录,仅供参考!

Linux下清除缓存 drop

相关文章:

你感兴趣的文章:

标签云: