简体   繁体   English

帮助理解Windows内存 - “工作集”

[英]Help understanding Windows memory - “Working Set”

I've been tracking down a few memory leaks in my application. 我一直在追踪我的应用程序中的一些内存泄漏。 It's been a real pain, but I've finally tightened everything up. 这是一个真正的痛苦,但我终于收紧了一切。 However, there's one bit of Windows memory management that is confusing me. 但是,有一点Windows内存管理令我感到困惑。 Here is a printout of the app's memory usage over time... 以下是应用程序内存使用情况的打印输出...

Time        PrivateMemorySize64        WorkingSet64
20:00:36    47480,                     50144
20:01:06    47480,                     50144
20:01:36    47480,                     50144
20:02:06    47480,                     149540
20:02:36    47480,                     149540
20:03:06    47480,                     149540

The working set jumped from 49 MB to 146 over a span of 30 seconds. 工作装置在30秒的时间内从49 MB跳到146。 This happened overnight as the application was basically doing nothing. 这种情况在一夜之间发生,因为应用程序基本上什

The working set (which is what task manager shows me) seems to be able to be influenced by other applications such as debuggers (as I learned while looking for memory leaks). 工作集(这是任务管理器向我展示的)似乎能够受到其他应用程序(如调试器)的影响(正如我在查找内存泄漏时所了解的那样)。 After reading the documentation on what Working Set is, I still don't have a good understanding. 在阅读了有关工作集的文档后,我仍然没有很好的理解。

Any help is appreciated. 任何帮助表示赞赏。

Update : Thanks to some links from responders as well as some additional searching, I have a better understanding on how a separate process can cause my process' working set to grow. 更新 :感谢响应者的一些链接以及一些额外的搜索,我更好地了解了一个单独的流程如何导致我的流程的工作集增长。 Good to know that a spike in the working set is not necessarily an indication that your app is leaking... Further reason to not rely on Task Manager for memory evaluation :) 很高兴知道工作集中的峰值并不一定表明你的应用程序正在泄漏...还有理由不依赖任务管理器进行内存评估:)

Helpful links: 有用的网址:

A few words on memory usage or: working set vs. private working set 关于内存使用情况的几句话:工作集与私人工作集

CyberNotes: Windows Memory Usage Explained Cyber​​Notes:Windows内存使用说明

Simply said, the working set is the collection of memory pages currently owned by your process and not swapped out (ie in RAM). 简单地说,工作集是您的进程当前拥有的内存页面的集合,而不是换出(即在RAM中)。 That is somewhat inaccurate, however. 然而,这有点不准确。 Reality is a lot more complicated. 现实要复杂得多。

Windows maintains a minimum working set size and a maximum working set size for every process. Windows为每个进程维护最小工作集大小和最大工作集大小。 The minimum working set is easy, it is what Windows will grant to every process (as long as it can, by physical limits). 最小工作集很容易,它将授予Windows每个进程(只要它可以通过物理限制)。

The maximum working set is more dubious. 最大工作集更加可疑。 If your program uses more memory than will fit in its quota, Windows will drop some pages. 如果您的程序使用的内存超过其配额中的内存,Windows将删除一些页面。 However, while they are no longer in your working set, these pages are not necessarily "gone". 然而,虽然它们不再在您的工作集中,但这些页面不一定 “消失”。

Rather, those pages are removed from your working set and moved to the pool of available pages. 相反,这些页面将从您的工作集中删除并移动到可用页面池中。 As a consequence, if some other program needs more memory and no cleared pages are left over, your pages will be cleared, and assigned to a different process. 因此,如果某些其他程序需要更多内存并且没有剩余已清除的页面,则您的页面将被清除,并分配给不同的进程。 When you access them, they will need to be fetched from the swapfile again, possibly purging other pages, if you are still above the maximum working set size. 当您访问它们时,如果仍然高于最大工作集大小,则需要再次从交换文件中提取它们,可能还要清除其他页面。

However, if nobody asked for more memory in the mean time (or if all demands could be satisfied by pages that were unused anyway), then accessing one of those pages will simply make it "magically reappear" and kick out another page in its stead. 但是,如果没有人要求同时获得更多内存(或者无论如何都可以通过未使用的页面满足所有要求),那么访问其中一个页面只会使其“神奇地重新出现”并取而代之的是另一页。

Thus, your process can have more pages in RAM than are actually in its working set, but it does not "officially" own them. 因此,您的进程可以在RAM中拥有比实际工作集中更多的页面,但它并不“正式”拥有它们。

驻留集/工作集虚拟地址空间的一部分,当前驻留在物理内存中 ,因此不会被交换

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM