/proc/meminfo Explained"Free," "buffer," "swap," "dirty." What does it all mean? If you said, "something to do with the Summer of '68", you may need a primer on 'meminfo'. The entries in the /proc/meminfo can help explain what's going on with your memory usage, if you know how to read it. Example of "cat /proc/meminfo": The information comes in the form of both high-level and low-level statistics. At the top you see a quick summary of the most common values people would like to look at. Below you find the individual values we will discuss. First we will discuss the high-level statistics. High-Level Statistics
Detailed Level Statistics VM Statistics VM splits the cache pages into "active" and "inactive" memory. The idea is that if you need memory and some cache needs to be sacrificed for that, you take it from inactive since that's expected to be not used. The vm checks what is used on a regular basis and moves stuff around. When you use memory, the CPU sets a bit in the pagetable and the VM checks that bit occasionally, and based on that, it can move pages back to active. And within active there's an order of "longest ago not used" (roughly, it's a little more complex in reality). The longest-ago used ones can get moved to inactive. Inactive is split into two in the above kernel (2.4.18-24.8.0). Some have it three.
Memory Statistics
在Linux下檢視記憶體我們一般用free指令: [[email protected] tmp]# free total used free shared buffers cached Mem: 3266180 3250004 16176 0 110652 2668236 -/+ buffers/cache: 471116 2795064 Swap: 2048276 80160 1968116 下面是對這些數值的解釋: total:總計實體記憶體的大小。 used:已使用多大。 free:可用有多少。 Shared:多個程序共享的記憶體總額。 Buffers/cached:磁盤緩存的大小。 第三行(-/+ buffers/cached): used:已使用多大。 free:可用有多少。 第四行就不多解釋了。 區 别:第二行(mem)的used/free與第三行(-/+ buffers/cache) used/free的差別。這兩個的差別在于使用的角度來看,第一行是從OS的角度來看,因為對于OS,buffers/cached 都是屬于被使用,是以他的可用記憶體是16176KB,已用記憶體是3250004KB,其中包括,核心(OS)使用+Application(X, oracle,etc)使用的+buffers+cached. 第三行所指的是從應用程式角度來看,對于應用程式來說,buffers/cached 是等于可用的,因為buffer/cached是為了提高檔案讀取的性能,當應用程式需在用到記憶體的時候,buffer/cached會很快地被回收。 是以從應用程式的角度來說,可用記憶體=系統free memory+buffers+cached。 如上例: 2795064=16176+110652+2668236 接下來解釋什麼時候記憶體會被交換,以及按什麼方交換。 當可用記憶體少于額定值的時候,就會開會進行交換。 如何看額定值: cat /proc/meminfo [[email protected] tmp]# cat /proc/meminfo MemTotal: 3266180 kB MemFree: 17456 kB Buffers: 111328 kB Cached: 2664024 kB SwapCached: 0 kB Active: 467236 kB Inactive: 2644928 kB HighTotal: 0 kB HighFree: 0 kB LowTotal: 3266180 kB LowFree: 17456 kB SwapTotal: 2048276 kB SwapFree: 1968116 kB Dirty: 8 kB Writeback: 0 kB Mapped: 345360 kB Slab: 112344 kB Committed_AS: 535292 kB PageTables: 2340 kB VmallocTotal: 536870911 kB VmallocUsed: 272696 kB VmallocChunk: 536598175 kB HugePages_Total: 0 HugePages_Free: 0 Hugepagesize: 2048 kB 用free -m檢視的結果: [[email protected] tmp]# free -m total used free shared buffers cached Mem: 3189 3173 16 0 107 2605 -/+ buffers/cache: 460 2729 Swap: 2000 78 1921 檢視/proc/kcore檔案的大小(記憶體鏡像): [[email protected] tmp]# ll -h /proc/kcore -r-------- 1 root root 4.1G Jun 12 12:04 /proc/kcore 備注: 占用記憶體的測量 測量一個程序占用了多少記憶體,linux為我們提供了一個很友善的方法,/proc目錄為我們提供了所有的資訊,實際上top等工具也通過這裡來擷取相應的資訊。 /proc/meminfo 機器的記憶體使用資訊 /proc/pid/maps pid為程序号,顯示目前程序所占用的虛拟位址。 /proc/pid/statm 程序所占用的記憶體 [[email protected] ~]# cat /proc/self/statm 654 57 44 0 0 334 0 輸出解釋 CPU 以及CPU0。。。的每行的每個參數意思(以第一行為例)為: 參數 解釋 /proc//status Size (pages) 任務虛拟位址空間的大小 VmSize/4 Resident(pages) 應用程式正在使用的實體記憶體的大小 VmRSS/4 Shared(pages) 共享頁數 0 Trs(pages) 程式所擁有的可執行虛拟記憶體的大小 VmExe/4 Lrs(pages) 被映像到任務的虛拟記憶體空間的庫的大小 VmLib/4 Drs(pages) 程式資料段和使用者态的棧的大小 (VmData+ VmStk )4 dt(pages) 04 檢視機器可用記憶體 /proc/28248/>free total used free shared buffers cached Mem: 1023788 926400 97388 0 134668 503688 -/+ buffers/cache: 288044 735744 Swap: 1959920 89608 1870312 我們通過free指令檢視機器空閑記憶體時,會發現free的值很小。這主要是因為,在linux中有這麼一種思想,記憶體不用白不用,是以它盡可能的cache和buffer一些資料,以友善下次使用。但實際上這些記憶體也是可以立刻拿來使用的。 是以 空閑記憶體=free+buffers+cached=total-used 轉自:http://blog.chinaunix.net/u2/78225/showart_1727609.html |