`
aigo
  • 浏览: 2676222 次
  • 性别: Icon_minigender_1
  • 来自: 宜昌
社区版块
存档分类
最新评论

private bytes, virtual bytes, working set三者之间的区别

 
阅读更多

原文:http://stackoverflow.com/questions/1984186/what-is-private-bytes-virtual-bytes-working-set

 

The short answer to this question is that none of these values are a reliable indicator of how much memory an executable is actually using, and none of them are really appropriate for debugging a memory leak.

Private Bytes refer to the amount of memory that the process executable has asked for - not necessarily the amount it is actually using. They are "private" because they (usually) exclude memory-mapped files (i.e. shared DLLs). But - here's the catch - they don't necessarily exclude memory allocated by those files. There is no way to tell whether a change in private bytes was due to the executable itself, or due to a linked library. Private bytes are also not exclusively physical memory; they can be paged to disk or in the standby page list (i.e. no longer in use, but not paged yet either).

Working Set refers to the total physical memory (RAM) used by the process. However, unlike private bytes, this also includes memory-mapped files and various other resources, so it's an even less accurate measurement than the private bytes. This is the same value that gets reported in Task Manager's "Mem Usage" and has been the source of endless amounts of confusion in recent years. Memory in the Working Set is "physical" in the sense that it can be addressed without a page fault; however, the standby page list is also still physically in memory but not reported in the Working Set, and this is why you might see the "Mem Usage" suddenly drop when you minimize an application.

Virtual Bytes are the total virtual address space occupied by the entire process. This is like the working set, in the sense that it includes memory-mapped files (shared DLLs), but it also includes data in the standby list and data that has already been paged out and is sitting in a pagefile on disk somewhere. The total virtual bytes used by every process on a system under heavy load will add up to significantly more memory than the machine actually has.

So the relationships are:

  • Private Bytes are what your app has actually allocated, but include pagefile usage;
  • Working Set is the non-paged Private Bytes plus memory-mapped files;
  • Virtual Bytes are the Working Set plus paged Private Bytes and standby list.

There's another problem here; just as shared libraries can allocate memory inside your application module, leading to potential false positives reported in your app's Private Bytes, your application may also end up allocating memory inside the shared modules, leading to false negatives. That means it's actually possible for your application to have a memory leak that never manifests itself in the Private Bytes at all. Unlikely, but possible.

Private Bytes are a reasonable approximation of the amount of memory your executable is using and can be used to help narrow down a list of potential candidates for a memory leak; if you see the number growing and growing constantly and endlessly, you would want to check that process for a leak. This cannot, however, prove that there is or is not a leak.

One of the most effective tools for detecting/correcting memory leaks in Windows is actually Visual Studio(link goes to page on using VS for memory leaks, not the product page). Rational Purify is another possibility. Microsoft also has a more general best practices document on this subject. There are more tools listed in this previous question.

I hope this clears a few things up! Tracking down memory leaks is one of the most difficult things to do in debugging. Good luck.

分享到:
评论

相关推荐

    NET&SQL调优

    性能监控器 内存 Available Mbytes (NON) Paged Pool bytes Free System PTE Private Bytes/Virtual Bytes/Working Set

    Windows平台服务器常用指标分析.docx

    working set 指程序所消耗的物理内存,包括私有物理内存(Private Working set)和共享Working set(Sharable Working Set)。 四、页交换 页交换是将固定大小的代码和数据块从 RAM 移动到磁盘的过程,目的是释放...

    性能测试监控哪些系统资源

    - Memory\Available bytes 的持续下降,结合 Process\Private Bytes 和 Process\Working Set 的持续上升,进一步证实了内存泄漏的存在。 2. 内存瓶颈识别: - Memory 性能对象中的 Available MBytes 计数器应保持...

    微软内部资料-SQL性能优化2

    The system working set is represented by the counter Memory: cache bytes. System working set paging activity can be viewed by monitoring the Memory: Cache Faults/sec counter. For more information, ...

    VB获得指定当前进程列表中的进程们各自占用的内存大小.zip

    在Windows操作系统中,进程是执行中的应用程序实例,而内存使用情况包括私有使用量(Private Bytes)、工作集(Working Set)和虚拟内存大小(Virtual Memory Size)等指标。私有使用量是指进程独占的内存,不与其他...

    LoadRunner实例讲解

    内存泄漏可能导致Process/Private Bytes和Process/Working Set增大;CPU过高可能表示系统过载;IIS的相关指标如File Cache Hits %、File Cache Flushes和File Cache Hits可以帮助分析服务器的性能。 在LoadRunner的...

    windows, Unix, SQL等各类计数器的分析文档

    "Working Set"是进程工作集,包含最近被访问的内存页,系统会根据内存压力调整其大小;"Handle Count"则是进程打开的句柄总数,过多可能影响性能。 【内存使用分析】 内存相关的计数器如"Available Bytes"提供了...

    系统监控平台使用

    2. Working Set:当前进程实际占用的物理内存。 3. Handle Count:进程打开的句柄数量,过多可能导致资源浪费。 4. Thread Count:进程内的线程数量,过多可能增加上下文切换的开销。 5. Private Bytes:进程独占的...

    c#技术大全之对windows系统的操作

    Console.WriteLine($"内存使用:{process.WorkingSet64}"); } } } ``` #### 实现软件升级 **知识点概述:** 软件升级通常涉及新版本的下载和安装。C#可以通过HTTP请求下载新版本,并通过文件复制、注册表更新...

    python3.6.5参考手册 chm

    PEP 461 - percent formatting support for bytes and bytearray PEP 484 - Type Hints PEP 471 - os.scandir() function – a better and faster directory iterator PEP 475: Retry system calls failing with ...

    php.ini-development

    Current working directory (except CLI) ; 5. The web server's directory (for SAPI modules), or directory of PHP ; (otherwise in Windows) ; 6. The directory from the --with-config-file-path compile ...

    opensc-0.12.0.tar.gz

    * use max_send_size 255 / max_recv_size 256 bytes by default. reduce this for some readers (e.g. scm) with t=0 cards. * increase pin buffer size to allow longer pin codes. * Windows Make.rules.mak ...

Global site tag (gtag.js) - Google Analytics