linux meminfo 详解 (转)

来源:互联网 发布:基因武器 知乎 编辑:程序博客网 时间:2024/06/01 10:49
 

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


转自: http://hi.baidu.com/yy199771/blog/item/98c70e7ffa9c1d330cd7da99.html


相应选项中文意思想各位高手已经知道,如果翻译有什么错误,请务必指出:

   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

VMSTAT介绍

通过STATSPACK收集服务器信息,主要通过收集VMSTAT的信息来展现服务器状况。VMSTAT工具是最常见的UNIX监控工具,可以展现给定时间间隔的服务器的状态值。

一般VMSTAT工具的使用是通过两个数字参数来完成的,第一个参数是采样的时间间隔数,单位是秒,第二个参数是采样的次数。如:
[oracle@brucelau oracle]$ vmstat 1 2
procs                   memory swap       io   system         CPU
r   b   w swpd free buff   cache    si   so bi bo in cs   us   sy   id
1   0   0    0 271844 186052 255852 0 0     2     6   102 10 0 0 100
0   0   0    0 271844 186052 255852 0 0     0     0   104 11 0 0 100
  
(注:目前系统几乎空闲,并且不同操作系统VMSTAT输出内容有所不同)
  
目前说来,对于服务器监控有用处的度量主要有:

r(运行队列)
pi(页导入)
us(用户CPU)
sy(系统CPU)
id(空闲)
  
通过VMSTAT识别CPU瓶颈

r(运行队列)展示了正在执行和等待CPU资源的任务个数。当这个值超过了CPU数目,就会出现CPU瓶颈了。
获得CPU个数的命令(LINUX环境):
cat /proc/cpuinfo|grep processor|wc –l
当r值超过了CPU个数,就会出现CPU瓶颈,解决办法大体几种:
1. 最简单的就是增加CPU个数
2. 通过调整任务执行时间,如大任务放到系统不繁忙的情况下进行执行,进尔平衡系统任务
3.   调整已有任务的优先级  

通过VMSTAT识别CPU满负荷

首先需要声明一点的是,vmstat中CPU的度量是百分比的。当us+sy的值接近100的时候,表示CPU正在接近满负荷工作。但要注意的是,CPU 满负荷工作并不能说明什么,UNIX总是试图要CPU尽可能的繁忙,使得任务的吞吐量最大化。唯一能够确定CPU瓶颈的还是r(运行队列)的值。
  
通过VMSTAT识别RAM瓶颈

数据库服务器都只有有限的RAM,出现内存争用现象是Oracle的常见问题。
首先察看RAM的数量,命令如下(LINUX环境):
[root@brucelau root]#free
          total       used       free        shared    buffers     cached
Mem:    1027348     873312     154036     185736     187496     293964
-/+ buffers/cache:    391852    635496
Swap:    2096440       0    2096440
  
当然可以使用top等其他命令来显示RAM。

当内存的需求大于RAM的数量,服务器启动了虚拟内存机制,通过虚拟内存,可以将RAM段移到SWAP DISK的特殊磁盘段上,这样会出现虚拟内存的页导出和页导入现象,页导出并不能说明RAM瓶颈,虚拟内存系统经常会对内存段进行页导出,但页导入操作就 表明了服务器需要更多的内存了,页导入需要从SWAP DISK上将内存段复制回RAM,导致服务器速度变慢。
  
解决的办法有几种:
1.    最简单的,加大RAM
2.    改小SGA,使得对RAM需求减少
3.    减少RAM的需求(如:减少PGA)
  
我们基本的了解了VMSTAT工作,下面是STATSPACK通过vmstat统计收集服务器性能数据。
  
STATSPACK通过vmstat收集服务器信息
首先在perfstat用户下建一个存储服务器信息的表:如
建表:
create table stats$vmstat
(
start_date date,   --系统时间
duration date,   --时间间隔
server_name varchar2(20), --服务器名称
runque_waits number, --运行队列数据
page_in   number, --页导入数据
page_out number, --页导出数据
user_cpu number, --用户cpu数据
system_cpu number, --系统cpu数据
idle_cpu number, --空闲cpu数据
wait_cpu number –等待cpu数据(只是aix存在)
)
tablespace perfstat;
然后,通过UNIX/LINUX的shell变成,利用vmstat的结果来获取相应的服务器信息,并且存放到表中。


原创粉丝点击