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