星期二, 12月 29, 2009

[Linux]linux記憶體被吃光

相信很多人遇到用top看明明就沒有程式用記憶體很兇,但是記憶體還是被用光了
怎麼辦呢?
http://blog.chinaunix.net/u/27173/showart_467689.html
http://blog.yesican.tw/?p=912

其實就是linux為了提高disk IO的存取效率,所以有cache pagecache, dentries and inodes
怎麼free呢

#free
#sync
#echo 3 > /proc/sys/vm/drop_caches
#echo 0 > /proc/sys/vm/drop_caches

/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(8) first.

-----------------------------------------------------------------
Update
http://ssorc.tw/rewrite.php/read-599.html
這篇對於linux memory usage有更詳細的說明
節錄buffer and cache的說明~~~^^

Free中的buffer和cache︰(它們都是佔用內存)︰

  buffer : 作為buffer cache的內存,是塊設備的讀寫緩沖區

  cache: 作為page cache的內存, 文件系統的cache

  如果 cache 的值很大,說明cache住的文件數很多。如果頻繁訪問到的文件都能被cache住,那麼磁盤的讀IO bi會非常小。

Read more: http://ssorc.tw/rewrite.php/read-599.html#ixzz0gbxRjPrV

------------------------------------------------------------------------
[Update]
http://virtualthreads.blogspot.com/2006/02/understanding-memory-usage-on-linux.html
但這一篇就在說明ps很不準,別看ps的memory usage

沒有留言:

張貼留言