磁盘缓存增大, 占据内存清除的方法

来源:互联网 发布:电子商务数据分析师 编辑:程序博客网 时间:2024/06/08 07:06

大家有没有遇到这种情况:在给tf卡或者usb存储设备持续写入文件的时候,内存占用会不断增加,一直到剩余很少内存的时候才停止占用更多内存。而这时候  如果其他模块急需更多内存,系统运行效率就会大大降低。最近google+baidu  翻阅了一些资料做如下总结:

频繁的文件访问会导致系统的Cache使用量大增,占用内存。

运行sync命令将dirty的内容写回硬盘
$sync

通过修改proc系统的drop_caches清理free的cache
$echo 3 > /proc/sys/vm/drop_caches

drop_caches的详细文档如下:
Writing to this will cause the kernel to drop clean caches, dentries and inodes from memory, causing that memory to become free.
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
As this is a non-destructive operation, and dirty objects are notfreeable, the user should run "sync" first in order to make sure allcached objects are freed.
This tunable was added in 2.6.16

linux C 编程序可以用sync()函数替代命令。

原创粉丝点击