主要參考核心文檔和紅帽文檔對 > cat /proc/meminfo 讀出的核心資訊進行解釋, 下篇文章會簡單對讀出該資訊的代碼進行簡單的分析。
MemTotal: 507480 kB MemFree: 10800 kB Buffers: 34728 kB Cached: 98852 kB SwapCached: 128 kB Active: 304248 kB Inactive: 46192 kB HighTotal: 0 kB HighFree: 0 kB LowTotal: 507480 kB LowFree: 10800 kB SwapTotal: 979956 kB SwapFree: 941296 kB Dirty: 32 kB Writeback: 0 kB AnonPages: 216756 kB Mapped: 77560 kB Slab: 22952 kB SReclaimable: 15512 kB SUnreclaim: 7440 kB PageTables: 2640 kB NFS_Unstable: 0 kB Bounce: 0 kB CommitLimit: 1233696 kB Committed_AS: 828508 kB VmallocTotal: 516088 kB VmallocUsed: 5032 kB VmallocChunk: 510580 kB |
相應選項中文意思想各位高手已經知道,如何翻譯有什麼錯誤,請務必指出: MemTotal: 所有可用RAM大小 (即實體記憶體減去一些預留位和核心的二進位代碼大小) MemFree: LowFree與HighFree的總和,被系統留著未使用的記憶體 Buffers: 用來給檔案做緩衝大小 Cached: 被高速緩衝儲存空間(cache memory)用的記憶體的大小(等於 diskcache minus SwapCache ). SwapCached:被高速緩衝儲存空間(cache memory)用的交換空間的大小 已經被交換出來的記憶體,但仍然被存放在swapfile中。用來在需要的時候很快的被替換而不需要再次開啟I/O連接埠。 Active: 在活躍使用中的緩衝或高速緩衝儲存空間分頁檔的大小,除非非常必要否則不會被移作他用. Inactive: 在不經常使用中的緩衝或高速緩衝儲存空間分頁檔的大小,可能被用於其他途徑. HighTotal: HighFree: 該地區不是直接映射到核心空間。核心必須使用不同的手法使用該段記憶體。 LowTotal: LowFree: 低位可以達到高位記憶體一樣的作用,而且它還能夠被核心用來記錄一些自己的資料結構。Among many other things, it is where everything from the Slab is allocated. Bad things happen when you're out of lowmem. SwapTotal: 交換空間的總大小 SwapFree: 未被使用交換空間的大小 Dirty: 等待被寫回到磁碟的記憶體大小。 Writeback: 正在被寫回到磁碟的記憶體大小。 AnonPages:未映射頁的記憶體大小 Mapped: 裝置和檔案等映射的大小。 Slab: 核心資料結構緩衝的大小,可以減少申請和釋放記憶體帶來的消耗 SReclaimable:可收回Slab的大小 SUnreclaim:不可收回Slab的大小(SUnreclaim+SReclaimable=Slab) PageTables:管理記憶體分頁頁面的索引表的大小。 NFS_Unstable:不穩定頁表的大小 Bounce: CommitLimit: Based on the overcommit ratio ('vm.overcommit_ratio'), this is the total amount of memory currently available to be allocated on the system. This limit is only adhered to if strict overcommit accounting is enabled (mode 2 in 'vm.overcommit_memory'). The CommitLimit is calculated with the following formula: CommitLimit = ('vm.overcommit_ratio' * Physical RAM) + Swap For example, on a system with 1G of physical RAM and 7G of swap with a `vm.overcommit_ratio` of 30 it would yield a CommitLimit of 7.3G. For more details, see the memory overcommit documentation in vm/overcommit-accounting. Committed_AS: The amount of memory presently allocated on the system. The committed memory is a sum of all of the memory which has been allocated by processes, even if it has not been "used" by them as of yet. A process which malloc()'s 1G of memory, but only touches 300M of it will only show up as using 300M of memory even if it has the address space allocated for the entire 1G. This 1G is memory which has been "committed" to by the VM and can be used at any time by the allocating application. With strict overcommit enabled on the system (mode 2 in 'vm.overcommit_memory'), allocations which would exceed the CommitLimit (detailed above) will not be permitted. This is useful if one needs to guarantee that processes will not fail due to lack of memory once that memory has been successfully allocated. VmallocTotal: 可以vmalloc虛擬記憶體大小 VmallocUsed: 已經被使用的虛擬記憶體大小 VmallocChunk: largest contigious block of vmalloc area which is free
下面簡單來個例子,看看已用記憶體和實體記憶體大小..
#include <stdio.h> #include <stdlib.h> #include <string.h> int MemInfo(char* Info, int len); int main() { char buf[128];
memset(buf, 0, 128); MemInfo(buf, 100); printf("%s", buf); return 0; } int MemInfo(char* Info, int len) { char sStatBuf[256]; FILE* fp; int flag; int TotalMem; int UsedMem; char* line; if(system("free -m | awk '{print $2,$3}' > mem")); memset(sStatBuf, 0, 256); fp = fopen("mem", "rb"); if(fp < 0) { return -1; } fread(sStatBuf,1, sizeof(sStatBuf) , fp); line = strstr(sStatBuf, "\n"); TotalMem = atoi(line); line = strstr(line, " "); UsedMem = atoi(line); memset(sStatBuf, 0, 256); sprintf(sStatBuf, "Used %dM/Total %dM\n", UsedMem, TotalMem); if(strlen(sStatBuf) > len) { return -1; } memcpy(Info, sStatBuf, strlen(sStatBuf)); return 0; }
結果:Used 488M/Total 495M
|
參考:http://www.redhat.com/docs/manuals/enterprise/RHEL-4-Manual/en-US/Reference_Guide/s2-proc-meminfo.html http://lxr.linux.no/linux+v2.6.23/Documentation/filesystems/proc.txt |