认真能把事做对,用心才能把事做好,专心、专注、心注未来。 声明:本博客内容除特别注明转载外全部是个人工作总结,转载时请注明出处!

关于释放linux虚拟内存

上一篇 / 下一篇  2011-05-07 17:21:09 / 个人分类:原创

原因分析:

Linux下频繁读取文件后,物理内存会很快耗尽.当程序结束时,内存不会被正常释放,而是一直作为caching.这是linux为了提高磁盘的读取效率而做的设计.

解决方法:

1.    linux-sudv:~ #sync

sync命令以确保文件系统的完整性。它将所有未写的系统缓冲区写到磁盘中.包括pagecache,dentries and inodes.

2.    linux-sudv:~ #echo 3 > /proc/sys/vm/drop_caches

drop_caches的值设为3.(该值默认为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.


TAG: 虚拟内存

 

评分:0

我来说两句

Open Toolbar