原因分析:
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.