woaidongmao

文章均收录自他人博客,但不喜标题前加-[转贴],因其丑陋,见谅!~
随笔 - 1469, 文章 - 0, 评论 - 661, 引用 - 0
数据加载中……

Windows系统内存计数器理解解析

序言
内存的使用情况是系统性能中重要的因素之一,频繁的页交换及内存泄露都会影响到系统的性能。本文主要是描述内存的一些概念、计数器含义,以及可能存在的性能瓶颈。

一些概念

页交换是使用称为页面的单位,将固定大小的代码和数据块从 RAM 移动到磁盘的过程,其目的是为了释放内存空间。
每个Windows进程都拥有4G的虚拟地址空间,在多任务环境下,所有进程使用的内存总和可以超过物理内存。
进程的一部分可能会从物理内存中删除而被暂存在硬盘的文件里(pagefile)。当进程试图访问这些被交换到pagefile里的内存的时候,系统会产生一个缺页中断(page fault),这时候Windows内存管理器会负责把对应的内存页重新从硬盘调入物理内存。
用于描述物理内存中虚拟页面子集的术语称为一个工作集(Working Set),也叫驻留集。一共有三种工作集:进程工作集、系统工作集、会话工作集。(具体概念看后面的计数器)
非换页池:它是由一些可保证总是驻留在物理内存中的虚拟地址范围构成的,由于这些地址范围总是驻留在内存中,因此任何时候都可以访问它们,而不会招致页面错误。
换页池:系统空间中的一段虚拟内存区域,它可以被换入和换出系统。这两种内存池都位于系统地址空间部分,并且被映射到每个进程的虚拟地址空间中。
 共享内存:对于多个进程可见的内存,或者出现在多个进程虚拟地址空间中的内存。例如:如果两个进程使用了同样的DLL,那么只需将引用该DLL的代码页面加载到物理内存一次,然后所有映射了该DLL的进程之间共享这些页面。
MDL(Memory Descrīptor List)是一个结构体,用于描述一片内存区域中的所有物理内存页。

可能存在的性能问题

1
Memory\\Page Reads/sec过高,持续大于5
 
过多的页交换要使用大量的硬盘空间,很容易将导致将页交换内存不足与导致页交换的磁盘瓶径混淆。这就需要我们在研究内存不足不太明显的页交换的原因时,必须跟踪如下的磁盘使用情况计数器和内存计数器Physical Disk\\ % Disk TimePhysical Disk\\ Avg.Disk Queue LengthMemory\\Page Reads/sec
 
如果Memory\\Page Reads/sec比较低,但Physical Disk\\% Disk Time and Physical Disk\\Avg. Disk Queue Length计数器很高,表明磁盘有瓶颈。
 
如果随着Physical Disk\\Avg. Disk Queue Length的增加,而Memory\Page Reads/sec并没有减少,表明有内存的瓶颈。

2
、内存泄露
  如果怀疑内存泄露,监视 Memory\\ Available Bytes Memory\\ Committed Bytes,以观察内存行为,并监视可能存在泄露内存的进程的 Process\\Private BytesProcess\\Working SetProcess\\Handle CountHandle泄漏)。
 
如果怀疑是内核模式进程导致了泄露,则还应该监视 Memory\\Pool Paged BytesProcess\\ Pool Paged Bytes。(Memory\\Pool Paged BytesProcess\\ Pool Nonpaged Bytes,有什么不同,期待告知)。
 
可以通过PoolMon工具详细查看非换页池和换页池的详细使用情况。
 
备注:这里只是随便提一下。

各计数器理解及描述

1
Process\\Working Set
含义:

进程工作集,是虚拟地址空间在物理内存中的那部分。包含了一个进程内的各个线程引用过的页面,即:Task Manager中的Mem Usage
分析:
由于每个进程工作集中包含了共享页面,所以Process\\Working Set_Total)值会大于实际的总进程内存使用量。

2
Process\\Private Bytes
含义:
分配的私有虚拟内存总数,即私有的、已提交的虚拟内存使用量。即:Task Manager中的VM Size
分析:
内存泄露时表现的现象是私有虚拟内存的递增,而不是工作集大小的递增。在某个点上,内存管理器会阻止一个进程继续增加物理内存大小,但它可以继续增大它的虚拟内存大小。

3
Memory\\Available MBytes Available BytesAvailable KBytes
含义:
Available MBytes 是指以 MB 表示的可用物理内存量,此内存能立刻分配给一个进程或系统使用。它是空闲列表、零列表和备用列表的大小总和。
分析:
至少要有10% 的物理内存值,最低限度是4 MB
页面状态:
备用:页面原先属于某个工作集,但现在被去除了。该页面自从最后一次被写到磁盘后一直未被修改过,PTEPage Table Entry)仍然指向该物理页面,不过已标记为无效的和正在转移中。
空闲:页面是空闲的,但它包含了未特别指明的脏数据。(需要用零初始化,否则不能交给用户进程)
零化:页面是空闲的,并且已经被零页面线程初始化为零了。

4
Memory\\Page Faults/sec
含义:
Page Faults/sec 是每秒钟出错页面的平均数量。由于每个错误操作中只有一个页面出错,计算单位为每秒出错页面数量,因此这也等于页面错误操作的数量。这个计数器包括硬错误(那些需要磁盘访问的)和软错误(在物理内存的地方找到的错误页)。许多处理器可以在有大量软错误的情况下继续操作。但是,硬错误可以导致明显的拖延,因为需要访问磁盘。

5
Memory\\Page Reads/sec
含义:
Page Reads/sec 是读取磁盘以解析硬页面错误的次数。它显示读取操作的数量,它并不考虑每个操作的页面数量。当一个进程引用一个虚拟内存的页面,而此虚拟内存位于工作集以外或物理内存的其他位置,并且此页面必须从磁盘检索时,就会发生硬页面错误。此计数器是引起系统范围内延迟的主要指示器。它包含读取操作以满足文件系统缓存(通常由应用程序请求)和非缓存映射内存文件的错误。比较内存的值\\PagesReads/sec 与内存的值\\PagesInput/sec 来决定每个操作取读的平均页面数量。
通俗含义:
页的硬故障,Page/sec的子集,是为了解决硬错误,从硬盘读取的次数。
分析:
阈值为>5,越低越好。大数值表示磁盘读而不是缓存读。持续大于5的值,表明内存的读请求发生了较多的缺页中断(page fault)
说明进程的Working Set已经不够,使用硬盘来虚拟内存。此处为读得次数,不关心读取得页数,比较大的值表明内存出现了瓶颈。

6
Memory\\Page Writes/sec
含义:
Page Writes/sec 是指为了释放物理内存空间而将页面写入磁盘的速度。只有页面还在物理内存中时所做的更改才会写入磁盘,因此这些页面可能只保留数据而不保留代码。这个计数器显示写入操作,不计数每个操作中写入的页数。

7
Memory\\Pages Input/sec
含义:
Pages Input/sec 是以解析硬页面错误从磁盘读取的页数。当一个进程引用一个虚拟内存的页面,而此虚拟内存位于工作集以外或物理内存的其他位置,并且此页面必须从磁盘检索时,就会发生硬页面错误。当夜面发生错误时,系统尝试将多个连续页面读入内存以充分利用取读操作的优点。请比较 Memory\\Pages Input/sec 的值和 Memory\\Page Reads/sec 的值以便决定每个取读操作读入内存的平均页面数量。

8
Memory\\Pages Output/sec
含义:
Pages Output/sec 是指为了释放物理内存空间而将页面写入磁盘的页数。只有在物理内存中更改时页面才会写回到磁盘上,因此页面可能只保留数据而不是代码。高速的页面输出可能表示内存不足。当物理内存不足时,Windows 会将页面写回到磁盘以便释放空间。

9
Memory\\Page/sec
含义:
Pages/sec 是指为解决硬页错误从磁盘读取或写入磁盘的页数。这个计数器是可以显示导致系统范围延缓类型错误的主要指示器。它是 Memory\\Pages Input/sec Memory\\Pages Output/sec 的总和。是用页数计算的,以便在不用做转换的情况下就可以同其他页计数如: Memory\\Page Faults/sec 做比较,这个值包括为满足错误而在文件系统缓存(通常由应用程序请求)的非缓存映射内存文件中检索的页。
分析:
一般如果pages/sec持续高于几百,那么您应该进一步研究页交换活动。有可能需要增加内存,以减少换页的需求(你可以把这个数字乘以4k就得到由此引起的硬盘数据流量) 。Pages/sec 的值很大不一定表明内存有问题,而可能是运行使用内存映射文件的程序所致。

10
Memory\\ % Committed Bytes In Use
含义:
%Committed Bytes In Use Memory\\Committed Bytes Memory\\Commit Limit 之间的比值。Committed memory是已在页面文件中保留空间的在用物理内存。Commit Limit 是由页面文件的大小而决定的。如果扩大了页面文件,该比例就会减小。

※※※※※※※※※※※※※※※※※※※※※※※※※※※※※※※※※※※※※※※※※※※※※※※※※※※※※※※※※※※※※※※※※※※※※

11
Memory\\ Committed Bytes
含义:
Committed Bytes 是指已被提交的(不是保留的)虚拟内存字节数。此数并不一定代表页面文件的使用量,因为它包含了物理内存中从未被换出过的私有提交页面。当然,如果一个进程完全是非驻留的,则它代表所使用的页面文件数量。
对应Task ManagerPF使用 (Current Commit Charge) 。页面文件的使用量参见计数器:Paging File\\%Usage
原文:
Number of bytes of virtual (not reserved) memory that has been committed. This number doesn’t necessarily represent page file usage because it includes private committed pages in physical memory that have never been paged out. Rather, it represents the amount of page file space that would be used if the process was completely made nonresident.
分析:
NT的内存分配采用了两步走的方法,首先,在虚地址空间上保留一段空间,这时操作系统并没有分配物理内存,只是保留了一段地址。然后,再提交这段空间,这时操作系统才会分配物理内存。
Windows
的地址空间有三种状态。一种是COMMITED,表明该地址空间已和一块内存相联系;一种是RESERVED,表明该地址空间虽未与一块内存相联系但今后可能会用到,需要保留;一种是FREE,表明该地址空间与内存没有联系。

12
Memory\\ Commit Limit
含义:
Commit Limit 是指无需扩展页面文件就可以提交的虚拟内存字节数。
原文:
Number of bytes of virtual memory that can be committed without having to extend the paging files; if the paging files can be extended, this limit is not hard.
To use a reserved region of address space, you must allocate physical storage and then map this storage to the reserved region. This process is called committing physical storage. Physical storage is always committed in pages.

※※※※※※※※※※※※※※※※※※※※※※※※※※※※※※※※※※※※※※※※※※※※※※※※※※※※※※※※※※※※※※※※※※※

13
Memory\\Pool Nonpaged Allocs
含义:
Pool Nonpaged Allocs 指在换换页池中分派空间的调用数。它是用衡量分配空间的调用数来计数的,而不管在每个调用中分派的空间数是多少。
原文:
Shows the number of calls to allocate space in the nonpaged pool. This counter is measured in numbers of calls to allocate space, regardless of the amount of space allocated in each call.
分析:
考察其自系统启动以来的增长了10%以上,如果是,表明有潜在的严重瓶颈。
需要观察Server\\Pool Nonpaged Failures,非页面池分配失败的次数。非零表示计算机的物理内存太小。

14
Memory\\Pool Nonpaged Bytes
含义:

Pool Nonpaged Bytes
指在非换页池中的字节数,非换页池是指系统内存(操作系统使用的物理内存)中可供对象(指那些在不处于使用时不可以写入磁盘上而且只要分派过就必须保留在物理内存中的对象)使用的一个区域。
疑问:Memory\\Pool Nonpaged Bytes 的计数方式与 Process\\Pool Nonpaged Bytes 的计数方式有什么不同。
通俗含义:
非换页池中的当前大小,即Task Manager中的Kernel Memory→NonPaged

15
Memory\\Pool Paged Allocs
含义:
Pool Paged Allocs 指在换页池中分派空间的调用次数。它是用计算分配空间的调用次数来计算的,而不管在每个调用中分派的空间数是什么。
原文:
Shows the number of calls to allocate space in the paged pool. This counter is measured in numbers of calls to allocate space, regardless of the amount of space allocated in each call.

16
Memory\\Pool Paged Bytes
含义:
Pool Paged Bytes 指在换页池中的字节数,换页池是系统内存(操作系统使用的物理内存)中可供对象(在不处于使用时可以写入磁盘的)使用的一个区域。
疑问:Memory\\Pool Paged Bytes 的计数方式与 Process\\Pool Paged Bytes 的方式有什么不同。
通俗含义:
换页池的当前虚拟大小,即Task Manager中的Kernel Memory→Paged Virtual
换页池的当前物理(驻留)大小参见计数器Memory\\Poll Paged Resident Bytes
分析:
也需要观察Server\\Pool Paged Failures,页面池分配失败的次数。非零表示计算机的物理内存或页面文件太小。

※※※※※※※※※※※※※※※※※※※※※※※※※※※※※※※※※※※※※※※※※※※※※※※※※※※※※※※※※※※※※※

17
Memory\\ Cache Bytes
含义:

系统工作集的总大小,其包括以下代码或数据驻留在内存中的那一部分:系统缓存、换页内存池、可换页的系统代码(Ntoskrnl.exe和驱动程序),以及系统映射的视图。
分析:
从字面意思上看,仅仅是指系统缓存,其实不然。
Cache Bytes Memory\\System Cache Resident Bytes
Memory\\System Driver Resident BytesMemory\\System Code Resident Bytes Memory\\Pool Paged Resident Bytes的总和。

18
Memory\\Cache Bytes Peak
含义:
Cache Bytes Peak 是系统启动后文件系统缓存使用的最大字节数量。这可能比当前的缓存量要大。这个计数器只显示上一次观察到的值;它不是一个平均值。
原文:
Shows the maximum number of bytes used by the file system cache since the system was last started. This might be larger than the current size of the cache.

19
Memory\\Cache Faults/sec
含义:
Cache Faults/sec 指在文件系统缓存中找不到要寻找的页而需要从内存(软错误)的其他地方或从磁盘(硬错误)的其他上检索时出现的错误的速度。文件系统缓存活动是大部分应用程序 IP 操作的可靠指示
器。这个计数器显示错误的次数而不管每次操作中的出错的页数。
原文:
Shows the rate, in incidents per second, at which faults occured when a page that was sought in the file system cache was not found and was be retrieved either from elsewhere in memory (a soft fault) or from disk (a hard fault). This counter shows the total number of faults, without regard for the number of pages faulted in each operation.
分析:
从文件系统缓存中查找数据,未命中的次数。这个值应该尽可能的低,较大的值表明内存出现短缺,缓存命中很低。
同时需要观察Cache\MDL Read Hits%MDL Read Hits 是指 Memory Descrīptor List 向文件系统缓存发出的请求命中缓存的百分比,例如:不需要磁盘访问即可为在缓存中的页面提供内存访问。
值越大(接近100%),表明文件系统缓存效果越好。

20
Memory\\Demand Zero Faults/sec
含义:
Demand Zero Faults/sec 通过零化页面来弥补分页错误的平均速度。这个计数器显示最近两个保留取样值的差,再除以取样间隔。零化页面是指先清空以前的资料,再将页面用0来填满,这是Windows NT的安全性功能,这样可以防止以前的资料外泄。这个计数器显示的是错误数量,而不是重新获取的页面数量。
原文:
Shows the average rate, in incidents per second, at which page faults required a zeroed page to satisfy the fault. This counter displays the difference between the values observed in the last two samples, divided by the duration of the sample interval. Zeroed pages (pages emptied of previously stored data and filled with zeroes) prevent processes from seeing data stored by earlier processes that used the same memory space. This counter displays the number of faults, without regard to the number of pages retrieved to satisfy the fault.

21
Memory\\Free System Page Table Entries
含义:
Free System Page Table Entries 指系统没有使用的页表项目。这个计数值仅显示上一次的值,而不是一个平均值。
原文:
Shows the number of page table entries not in use by the system.

22
Memory\\Pool Paged Resident Bytes
含义:
换页池所使用的物理内存,即Task Manager中的Kernel Memory→Paged Physical

23
Memory\\System Cache Resident Bytes
含义:
System Cache Resident Bytes 是文件系统缓存可换页的操作系统代码的字节大小。此值只包括当前的物理页面,而不包括当前未使用的虚拟内存页面。它不等于任务管理器上显示的系统缓存值。因此,此值会比文件系统缓存使用的实际虚拟内存要小。此值是 Memory\\System Code Resident Bytes 的组件,它代表当前在物理内存里的所有可换页的操作系统代码。
原文:
Shows the size, in bytes, of pageable operating system code in the file system cache. This value includes only current physical pages and does not include any virtual memory pages that are not currently resident. It does not equal the System Cache value shown in Task Manager. As a result, this value may be smaller than the actual amount of virtual memory in use by the file system cache. This value is a component of System Code Resident Bytes that represents all pageable operating system code that is currently in physical memory.
通俗含义:
系统缓存所使用的物理内存。

24
Memory\\System Code Resident Bytes
含义:
System Code Resident Bytes 是操作系统代码当前在物理内存的字节大小,此物理内存在未使用时可写入磁盘。此值是 Memory\\System Code Total Bytes 的组件,它还包括磁盘上的操作系统代码。Memory\\System Code Resident Bytes ( Memory\\System Code Total Bytes) 不包括必须留在物理内存的代码,并且不能写入磁盘。
原文:
Shows the size, in bytes, of operating system code currently in physical memory that can be written to disk when not in use. This value is a component of System Code Total Bytes, which also includes operating system code on disk. System Code Resident Bytes (and System Code Total Bytes) does not include code that must remain in physical memory.
通俗含义:
Ntoskrnl.exe
中可换页代码所使用的物理内存。

25
Memory\\System Code Total Bytes
含义:
System Code Total Bytes 指当前在虚拟内存中的可换页的操作系统代码的字节数。这是用来衡量在不使用时可以写入到磁盘上的操作系统使用的物理内存的数量。这个值是通过将在 Ntoskrnl.exe, Hal.dll 、启动驱动器和用 Ntldr/osloader 加载的文件系统中的字节的数相加得出的。这个计数器不包括必须保留在物理内存中并不能写入到磁盘上的代码。
原文:
Shows the size, in bytes, of pageable operating system code currently in virtual memory. It is a measure of the amount of physical memory being used by the operating system that can be written to disk when not in use. This value is calculated by adding the bytes in Ntoskrnl.exe, Hal.dll, the boot drivers, and file systems loaded by Ntldr/osloader. This counter does not include code that must remain in physical memory.

26
Memory\\System Driver Resident Bytes
含义:
System Driver Resident Bytes 指设备驱动程序当前使用的可换页的物理内存的字节数。它是驱动程序的工作集(物理内存区域)。这个值为 Memory\\System Driver Total Bytes (也包括可以写入磁盘的驱动程序
内存)的组件。无论 System Driver Resident Bytes 还是 System Driver Total Bytes都包括不能写入磁盘的物理内存。
原文:
Shows the size, in bytes, of pageable physical memory being used by device drivers. The counter is the working set (physical memory area) of the drivers. This value is a component of System Driver Total Bytes, which also includes driver memory that has been written to disk. Neither System Driver Resident Bytes nor System Driver Total Bytes includes memory that cannot be written to disk.
通俗含义:
可换页的设备驱动程序代码所使用的物理内存。

27
Memory\\System Driver Total Bytes
含义:
System Driver Total Bytes 指设备驱动程序当前使用的可换页的虚拟内存的字节数。当不使用时可换页内存可以写入磁盘。它包括物理内存(Memory\\System Driver Resident Bytes)和代码以及写到磁盘中的数据。它是Memory\\System Code Total Bytes 的一个组件。
原文:
Shows the size, in bytes, of pageable virtual memory currently being used by device drivers. Pageable memory can be written to disk when it is not being used. It includes physical memory (System Driver Resident Bytes) and code and data written to disk. This counter is a component of System Code Total Bytes.

28
Memory\\Transition Faults/sec
含义:
Transition Faults/sec是在没有额外磁盘运行的情况下,通过恢复页面来解决页面错误的速度。页面错误包括页面正被另一个共享此页面的进程使用,或在被修改的页面列表上或待机列表上,或在发生页面错误时正被写入磁盘。该技术器也等于错误的页面数量,因为每一操作只有一个页面错误。
原文:
Shows the rate, in incidents per second, at which page faults were resolved by recovering pages without additional disk activity, including pages that were being used by another process sharing the page, or that were on the modified page list or the standby list, or that were being written to disk at the time of the page fault. This counter is also equal to the number of pages faulted because only one page is faulted in each operation.
分析:
如果这个指标持续的居高不下说明内存存在瓶颈,应该考虑增加内存。

29
Memory\\Write Copies/sec
含义:
Write Copies/sec 是指通过从物理内存中的其他地方复制页面来满足写入尝试而引起的页面错误速度。由于页面只在被写入时才被复制,这是一个实用的共享数据方式;另外该页面是共享的。这个计数器显示的是复制次数,不考虑每次操作时中被复制的页面数。
原文:
Shows the rate, in incidents per second, at which page faults were caused by attempts to write that were satisfied by copying the page from elsewhere in physical memory. This is an economical way of sharing data since pages are only copied when they are written to; otherwise, the page is shared. This counter shows the number of copies, without regard to the number of pages copied in each operation.
分析:
就是写时复制错误的比率。写时复制页面保护机制是一种优化,内存管理器利用它可以节约内存。
例如:两个进程正在共享三个页面,每个页面都被标记为写时复制,当其中一个进程的任一线程对一个页面执行写操作,则会产生一个内存管理错误。内存管理器不会将该错误报告为访问违例,而是在物理内存中分配一个新的读/写页面,并将原始页面中的内容拷贝到新的页面中,同时更新该进程对应的页面映射信息,使之指向新的页面位置,然后解除异常,从而继续进行刚才的写指令。写操作成功,新拷贝的页面现在对于执行写操作的进程来说是私有的,对于其他进程是不可见的。

 

posted on 2011-08-11 13:13 肥仔 阅读(825) 评论(0)  编辑 收藏 引用 所属分类: Windows开发


只有注册用户登录后才能发表评论。
网站导航: 博客园   IT新闻   BlogJava   知识库   博问   管理