歡迎來到Linux教程網
Linux教程網
Linux教程網
Linux教程網
Linux教程網 >> Unix知識 >> 關於Unix >> 關於釋放linux虛擬內存

關於釋放linux虛擬內存

日期:2017/3/6 14:28:15   编辑:關於Unix
原因分析: Linux下頻繁讀取文件後,物理內存會很快耗盡.當程序結束時,內存不會被正常釋放,而是一直作為caching.這是linux為了提高磁盤的讀取效率而做的設計. 解決方法: 1. linux-sudv:~ #sync sync命令以確保文件系統的完整性。它將所有未寫的系統緩沖區寫到

  原因分析:

  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.

Copyright © Linux教程網 All Rights Reserved