2008年6月26日 星期四

linux下查詢記憶體使用情況

free

total used free shared buffers cached
Mem: 1023916 975816 48100 0 26376 465844
-/+ buffers/cache: 483596 540320
Swap: 2096440 105564 1990876

計算方式

total used free shared buffers cached
Mem: a b c d e f
-/+ buffers/cache: g h
Swap: i j k

a = 總記憶體大小
b = 配給 buffers 與 cache 的記憶體大小(包含未用的 buffers 與 cache)
c = 剩下的記憶體大小
e = 配給 buffers 但未用的記憶體大小
f = 配給 cache 但未用的記憶體大小
g = buffers 與 cache 被使用掉的記憶體大小,也就是實際被應用程式用走的
h = 那這個就是實際剩下的記憶體大小

a = b + c
a = g + h
g = b - e - f
h = c + e + f

buffer 與 cache 的區別:
A buffer is something that has yet to be "written" to disk.
A cache is something that has been "read" from the disk and stored for later use.

Quote: http://www.ubuntu.org.tw/modules/newbb/viewtopic.php?topic_id=6132

一般情況下,Linux kernel 會盡可能多地利用 RAM 的空閑空間作為 cache/buffer 以最大幅度地提高系統性能。當系統中運行的應用程序占用的 RAM 增加時,則將 cache/buffer 所占用的空間釋放出來,讓渡給應用程序使用。

Quote: http://web.mit.edu/rhel-doc/4/RH-DOCS/rhel-isa-zh_tw-4/s1-resource-rhlspec.html

Mem: 那一行顯示了實際記憶體的使用率;
Swap: 顯示的是系統 swap 空間的使用率;
-/+ buffers/cache: 則是目前撥給系統緩衝區的實體記憶體數量。

沒有留言: