DM368远程升级文件系统时,由于内存不够,不能malloc那么大的内存,于是考虑怎么释放内存。
先是打算kill掉某些应用程序来增加空闲内存,用到killall -9 + progressName 或者 pkill -9 + progressName,参考文章http://blog.sina.com.cn/s/blog_975a2a540100ywyx.html
但是效果不好,后用free查看发现cached占用了10M多内存,考虑怎么释放cache。
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.
执行echo 3 > /proc/sys/vm/drop_caches后,cache占用内存减小,可用内存增加,达到目的。