Linux内存监控工具

本文为转载 http://www.opensolution.org.cn/archives/502.html

一、free

  该工具主要是显示系统里可用和已用的内存

查看更多精彩图片

Linux 通常按一定的算法把常用的数据加载到系统的虚拟内存bufferscached 中,以便于用户程序在访问系统资源更快。而由free 查看到的buffers 是用于存放元数据,而cached 是用于存放真实的文件内容。

 

由上图free -k 的输出结果中可知:

系统总物理内存(total) 4144656K(4G);

已用(Mem 行对应的used) 的物理内存 3871932K(3.8G,: 这里包含了buffers152460K(152M)cached2253060K(2.2G).) ,他包含系统的bufferscached 的。

-/+ buffers/cache 对应的used 1466412K(1.4G), 也就是Memused(3871932K)-Membuffers(152460K)-

Mem cached(2253060K)=1466412K(1.4G). 所以实际上可用于分配的物理内存(-/+ buffers/cache 行对应的free)2678244K(2.6G).

Shared man 手册里提示应该忽略(man free:The shared memory column should be ignored; it is obsolete.)

Mem 行对应的free 对应的274220K(274M). 其实这个free 是有一定限制的: 不能低于min_free_kbytes

min_free_kbytes 用于计算系统里lowmem zone( 物理内存0-896MB 之间的zone) 的值(This is used to force the Linux VM to keep a minimum number of kilobytes free.  The VM uses this number to compute a pages_min value for each lowmem zone in the system.  Each lowmem zone gets a number of reserved free pages based proportionally on its size.).

计算方式参见mm/page_alloc.c min_free_kbytes = sqrt(lowmem_kbytes * 16)

 

上述值是一定的公式计算

系统的lowmem872656KB

[root@crm_10 /root]grep LowTotal /proc/meminfo

LowTotal:  872656

min_free_kbytes=sqrt(872656*16) 约等于 3797

二、ps,top

  这两个工具在内存监视方面有很大的相似性,所以一并说一下:

下面top 里的VIRT 相当于ps 里的VSZ : 指用于这个任务的总虚拟内存( 虚拟内存包括物理内存和swap 交换分区), 包括所有的代码、数据、共享库以及已经被outswap 分区的数据。/* The total amount of virtual memory used by the task.  It includes all code, data and shared libraries plus pages that have been swapped out.*/

 

top 里的RES 相当于ps 里的RSS : 指用于这个任务的没被outswap 分区的总物理内存/* resident set size, the non-swapped physical memory that a task has used */

top里的%MEM : 指这个任务的RES 占总物理内存的比率/* Memory usage (RES) A task's currently used share of available physical memory.*/

三、vmstat

 

显示的值跟用free 工具查看到的值相似。一般情况下: 只要swap 一列的si/so 数值不超过1024 即可。

Swap

       si: Amount of memory swapped in from disk (/s).

       so: Amount of memory swapped to disk (/s).

:VFS 里的meminfo 信息:

查看更多精彩图片

Dirty 是指数据已写入内存,但还没同步到外存( 磁盘) 的数据量.

Slab: 为了提供内核空间以页分配对有些调用( 只需小内存) 不合适的一种内存分配方式, 提出Pool 的概念。

Vmalloc: 为了解决非连续性内存的使用,提供的一种内存分配方式( 采用链表)

CommitLimit: 指当前可以分配给程序使用的虚拟内存( 只有当vm.overcommit_memory 的值设置为2 时,CommitLimit 才有意义)

 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: 指当前已分配给程序使用的总虚拟内存( 包含已分配给进程但还没使用的内存)

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.

 

 

HugePagesize: X86 架构下, 通常linux 给内存分页时,默认是每页是4KB, 而有些应用自己可以管理内存( 例如db,java ……), 所以可以把页的大小分大些( 32 位下:4K4M,PAE 模式下可以把每页设置为2M.64 位下: 4K, 8K, 64K, 256K, 1M, 4M, 16M,256M ), 这样可以增加TLB( 一个存储线性地址和物理地址对应表的高速缓冲器) 存储的条目, 这样就可减少线性地址到物理地址转换的过程. 可通过vm.hugetlb_shm_group vm.nr_hugepages 参数进行调整。具体可查看 /usr/share/doc/kernel-doc-`uname –r |cut -d- -f1`/Documentation/vm/hugetlbpage.txt( 如果你的机器上已经安装了 kernel-doc)

 

The intent of this file is to give a brief summary of hugetlbpage support in

the Linux kernel.  This support is built on top of multiple page size support

that is provided by most of modern architectures.  For example, IA-32

architecture supports 4K and 4M (2M in PAE mode) page sizes, IA-64

architecture supports multiple page sizes 4K, 8K, 64K, 256K, 1M, 4M, 16M,

256M.  A TLB is a cache of virtual-to-physical translations.  Typically this

is a very scarce resource on processor.  Operating systems try to make best

use of limited number of TLB resources.  This optimization is more critical

now as bigger and bigger physical memories (several GBs) are more readily

available.

 

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值