CentOS下記憶體使用量率查看

來源:互聯網
上載者:User

標籤:http   使用   os   io   檔案   for   ar   art   

free
total        used        free      shared     buffers      cached
Mem:        1815340     1628680      186660           0      130316     1327736
-/+ buffers/cache:      170628     1644712
Swap:       1020116           0     1020116
Mem:表示實體記憶體統計
-/+ buffers/cached:表示實體記憶體的緩衝統計
Swap:表示硬碟上交換分區的使用方式,這裡我們不去關心。
系統的總實體記憶體:1815340Kb(2GB),但系統當前真正可用的記憶體並不是第一行free 標記的 186660Kb,它僅代表未被分配的記憶體。

第1行 Mem:
total:表示實體記憶體總量。1815340
used:表示總計分配給緩衝(包含buffers 與cache )使用的數量,但其中可能部分緩衝並未實際使用。 1628680
free:未被分配的記憶體。186660
shared:共用記憶體,一般系統不會用到,這裡也不討論。0
buffers:系統分配但未被使用的buffers 數量。130316
cached:系統分配但未被使用的cache 數量。1327736      buffer 與cache 的區別見後面。

total = used + free

第2行 -/+ buffers/cached:
used:也就是第一行中的used – buffers-cached 也是實際使用的記憶體總量。
free:未被使用的buffers 與cache 和未被分配的記憶體之和,這就是系統當前實際可用記憶體。 free 2= buffers1 + cached1 + free1 //free2為第二行、buffers1等為第一行

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 第3行: 第三行所指的是從應用程式角度來看,對於應用程式來說,buffers/cached 是等於可用的,因為buffer/cached是為了提高檔案讀取的效能,當應用程式需在用到記憶體的時候,buffer/cached會很快地被回收。
所以從應用程式的角度來說,可用記憶體=系統free memory+buffers+cached.

接下來解釋什麼時候記憶體會被交換,以及按什麼方交換。
當可用記憶體少於額定值的時候,就會開會進行交換.
如何看額定值:
#cat /proc/meminfo
交換將通過三個途徑來減少系統中使用的物理頁面的個數:
1.減少緩衝與頁面cache的大小,
2.將系統V類型的記憶體頁面交換出去,
3.換出或者丟棄頁面。(Application 佔用的記憶體頁,也就是實體記憶體不足)。
事實上,少量地使用swap是不是影響到系統效能的。

下面是buffers與cached的區別。
buffers是指用來給塊裝置做的緩衝大小,他只記錄檔案系統的metadata以及 tracking in-flight pages.
cached是用來給檔案做緩衝。
那就是說:buffers是用來儲存,目錄裡面有什麼內容,許可權等等。
而cached直接用來記憶我們開啟的檔案 ,如果你想知道他是不是真的生效,你可以試一下,先後執行兩次命令#man X ,你就可以明顯的感覺到第二次的開打的速度快很多。
實驗:在一台沒有什麼應用的機器上做會看得比較明顯。記得實驗只能做一次,如果想多做請換一個檔案名稱。

需要看哪些進程使用了記憶體的時候用以下命令:

ps aux

顯示:

USER    PID    %CPU    %MEM    VSZ    RSS    TTY    STAT    START    TIME    COMMAND
mysql    1888    0.8    0.2    1026444    60812    ?    Sl    25-Dec    78:56:00    /usr/local/mysql/libexec/mysqld
webuser    5108    0    0    360072    17048    ?    S    10:41    0:00    /usr/local/bin/httpd
webuser    4953    0    0    358728    15656    ?    S    10:41    0:00    /usr/local/bin/httpd
webuser    4916    0.1    0    358880    15616    ?    S    10:41    0:00    /usr/local/bin/httpd
webuser    5750    0    0    358452    15420    ?    S    10:41    0:00    /usr/local/bin/httpd
webuser    5106    0    0    356384    15364    ?    S    10:41    0:00    /usr/local/bin/httpd
webuser    4970    0    0    356420    15344    ?    S    10:41    0:00    /usr/local/bin/httpd
webuser    4950    0    0    358856    15288    ?    S    10:41    0:00    /usr/local/bin/httpd
webuser    4911    0    0    359056    15276    ?    S    10:41    0:00    /usr/local/bin/httpd
webuser    5034    0    0    358864    15180    ?    S    10:41    0:00    /usr/local/bin/httpd
webuser    5095    0    0    358868    15136    ?    S    10:41    0:00    /usr/local/bin/httpd
webuser    4929    0    0    358856    15124    ?    S    10:41    0:00    /usr/local/bin/httpd
webuser    4900    0    0    358464    14912    ?    S    10:41    0:00    /usr/local/bin/httpd
webuser    4944    0    0    356376    14792    ?    S    10:41    0:00    /usr/local/bin/httpd
webuser    4896    0    0    356376    14768    ?    S    10:41    0:00    /usr/local/bin/httpd
webuser    4995    0    0    356452    14640    ?    S    10:41    0:00    /usr/local/bin/httpd
webuser    5035    0    0    356472    14608    ?    S    10:41    0:00    /usr/local/bin/httpd
webuser    5097    0    0    356392    14588    ?    S    10:41    0:00    /usr/local/bin/httpd
webuser    4918    0    0    356400    14560    ?    S    10:41    0:00    /usr/local/bin/httpd
webuser    4927    0    0    356444    14520    ?    S    10:41    0:00    /usr/local/bin/httpd
webuser    4938    0    0    356388    14512    ?    S    10:41    0:00    /usr/local/bin/httpd
webuser    4913    0    0    356376    14476    ?    S    10:41    0:00    /usr/local/bin/httpd
webuser    5039    0    0    356392    14452    ?    S    10:41    0:00    /usr/local/bin/httpd
webuser    4940    0    0    356376    14384    ?    S    10:41    0:00    /usr/local/bin/httpd
webuser    4934    0    0    356404    14332    ?    S    10:41    0:00    /usr/local/bin/httpd

其中RSS列,就是實體記憶體使用量

VSZ: 佔用的虛擬記憶體大小
RSS: 佔用的實體記憶體大小

 

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.