Linux性能统计 - cat /proc/meminfo

来源:互联网 发布:网红阿沁的淘宝店 编辑:程序博客网 时间:2024/06/05 18:26

32位系统


$cat /proc/meminfo

MemTotal: 2052440 kB//Total amount of physical RAM, in kilobytes.
MemFree: 50004 kB//The amount of physical RAM, in kilobytes, left unused by the system.
Buffers: 19976 kB//The amount of physical RAM, in kilobytes, used for file buffers.
Cached: 436412 kB//The amount of physical RAM, in kilobytes, used as cache memory.
SwapCached: 19864 kB//The amount of swap, in kilobytes, used as cache memory.
Active: 1144512 kB//The total amount of buffer or page cache memory, in kilobytes, that is in active use. This is memory that has been recently used and is usually not reclaimed for other purposes.
Inactive: 732788 kB//The total amount of buffer or page cache memory, in kilobytes, that are free and available. This is memory that has not been recently used and can be reclaimed for other purposes.
Active(anon): 987640 kB
Inactive(anon): 572512 kB
Active(file): 156872 kB//Active(file), Inactive(file) has file back-end which means its original file is in disk but to use it faster it was loaded on RAM.
Inactive(file): 160276 kB
Unevictable: 8 kB
Mlocked: 8 kB
HighTotal: 1177160 kB//The total and free amount of memory, in kilobytes, that is not directly mapped into kernel space. The HighTotal value can vary based on the type of kernel used.
HighFree: 7396 kB
LowTotal: 875280 kB//The total and free amount of memory, in kilobytes, that is directly mapped into kernel space. The LowTotal value can vary based on the type of kernel used.
LowFree: 42608 kB
SwapTotal: 489940 kB//The total amount of swap available, in kilobytes.
SwapFree: 450328 kB//The total amount of swap free, in kilobytes.
Dirty: 104 kB//The total amount of memory, in kilobytes, waiting to be written back to the disk.
Writeback: 0 kB//The total amount of memory, in kilobytes, actively being written back to the disk.
AnonPages: 1408256 kB
Mapped: 131964 kB//The total amount of memory, in kilobytes, which have been used to map devices, files, or libraries using the mmap command.
Slab: 37368 kB//The total amount of memory, in kilobytes, used by the kernel to cache data structures for its own use.
SReclaimable: 14164 kB
SUnreclaim: 23204 kB
PageTables: 13308 kB
NFS_Unstable: 0 kB
Bounce: 0 kB
WritebackTmp: 0 kB
CommitLimit: 1516160 kB
Committed_AS: 2511900 kB//The total amount of memory, in kilobytes, estimated to complete the workload. This value represents the worst case scenario value, and also includes swap memory.
VmallocTotal: 122880 kB//The total amount of memory, in kilobytes, of total allocated virtual address space.
VmallocUsed: 28688 kB//The total amount of memory, in kilobytes, of used virtual address space.
VmallocChunk: 92204 kB//The largest contiguous block of memory, in kilobytes, of available virtual address space.
HugePages_Total: 0//The total number of hugepages for the system. The number is derived by dividing Hugepagesize by the megabytes set aside for hugepages specified in /proc/sys/vm/hugetlb_poolThis statistic only appears on the x86, Itanium, and AMD64 architectures.
HugePages_Free: 0//The total number of hugepages available for the system. This statistic only appears on the x86, Itanium, and AMD64 architectures.
HugePages_Rsvd: 0
HugePages_Surp: 0
Hugepagesize: 2048 kB//The size for each hugepages unit in kilobytes. By default, the value is 4096 KB on uniprocessor kernels for 32 bit architectures. For SMP, hugemem kernels, and AMD64, the default is 2048 KB. For Itanium architectures, the default is 262144 KB. This statistic only appears on the x86, Itanium, and AMD64 architectures.
DirectMap4k: 10232 kB
DirectMap2M: 899072 kB
========================================================================================
输出结果解释:
MemTotal: 所有可用RAM大小 (即物理内存减去一些预留位和内核的二进制代码大小),MemTotal=HighTotal+LowTotal
MemFree: 未使用的RAM大小MemFree=HighFree+LowFree
Buffers: 块设备的读写缓冲区大小
Cached: 文件系统的缓存,详细请参考:http://blog.csdn.net/genius_lg/article/details/14454935
SwapCached:被高速缓冲存储器(cache memory)用的交换空间的大小,已经被交换出来的内存,但仍然被存放在swapfile中。用来在需要的时候很快的被替换而不需要再次打开I/O端口。
Active: 在活跃使用中的缓冲或高速缓冲存储器页面文件的大小,除非非常必要否则不会被移作他用。Active=Active(anon)+Active(file)
Inactive: 在不经常使用中的缓冲或高速缓冲存储器页面文件的大小,可能被用于其他途径。Inactive=Inactive(anon)+Inactive(file)
HighTotal: 所有可用的高端内存,ZONE_HIGHMEM(896MB~结束),该区域不是直接映射到内核空间,内核必须使用不同的手法使用该段内存。在X86结构中,物理内存的三种类型区域为ZONE_DMA(内存开始的16MB),ZONE_NORMAL(16MB~896MB),ZONE_HIGHMEM(896MB~结束)。详细请参考:http://ilinuxkernel.com/?p=1013
HighFree: 未使用的高端内存

LowTotal: 所有可用的低端内存,包括ZONE_DMA(内存开始的16MB),ZONE_NORMAL(16MB~896MB)。示例中的结果为什么不是896MB?LowTotal 的大小与使用的内核有关,内核不同,大小不同。低端内存作用与高端内存一样,而且它还能够被内核用来记录一些自己的数据结构。

LowFree: 未使用的低端内存

SwapTotal: 交换空间的总大小。SwapTotal=SwapCached+SwapFree?

SwapFree: 未被使用交换空间的大小。
Dirty: 等待被写回到磁盘的内存大小。Dirty和Buffers的关系如何理解?
Writeback: 正在被写回到磁盘的内存大小。
AnonPages:未映射页的内存大小。
Mapped: 设备和文件等映射的大小。
Slab: 内核数据结构缓存的大小,可以减少申请和释放内存带来的消耗,Slab=SUnreclaim+SReclaimable
SReclaimable: 可收回Slab的大小。
SUnreclaim: 不可收回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: 已经被使用的vmalloc虚拟内存大小。

VmallocChunk: largest contigious block of vmalloc area which is free

64位系统

MemTotal:        8183084 kB
MemFree:          140820 kB
Buffers:          976308 kB
Cached:          4641732 kB
SwapCached:          948 kB
Active:          3071632 kB
Inactive:        3818940 kB
Active(anon):    1122168 kB
Inactive(anon):   179116 kB
Active(file):    1949464 kB
Inactive(file):  3639824 kB
Unevictable:       48240 kB
Mlocked:           36508 kB
SwapTotal:       2104508 kB
SwapFree:        2016232 kB
Dirty:             20012 kB
Writeback:             0 kB
AnonPages:       1315816 kB
Mapped:            98472 kB
Shmem:               104 kB
Slab:             987292 kB
SReclaimable:     801512 kB
SUnreclaim:       185780 kB
KernelStack:        8008 kB
PageTables:         9284 kB
NFS_Unstable:          0 kB
Bounce:                0 kB
WritebackTmp:          0 kB
CommitLimit:     6196048 kB
Committed_AS:    4221384 kB
VmallocTotal:   34359738367 kB
VmallocUsed:      329048 kB
VmallocChunk:   34359406704 kB
HardwareCorrupted:     0 kB
AnonHugePages:      2048 kB
HugePages_Total:       0
HugePages_Free:        0
HugePages_Rsvd:        0
HugePages_Surp:        0
Hugepagesize:       2048 kB
DirectMap4k:      114112 kB
DirectMap2M:     3022848 kB
DirectMap1G:     5242880 kB

========================================================================================

下面简单来个例子,看看已用内存和物理内存大小

#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
0 0
原创粉丝点击