帮助了解 Windows 内存 - “工作集”
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/5405693/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Help understanding Windows memory - "Working Set"
提问by BabaBooey
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. Here is a printout of the app's memory usage over time...
我一直在跟踪我的应用程序中的一些内存泄漏。这真的很痛苦,但我终于把一切都收紧了。然而,有一点让我感到困惑的 Windows 内存管理。这是应用随时间推移的内存使用情况的打印输出...
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. This happened overnight as the application was basically doing nothing.
工作集在 30 秒内从 49 MB 跃升至 146 MB。这发生在一夜之间,因为应用程序基本上什么都不做。
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
采纳答案by Damon
Simply said, the working set is the collection of memory pages currently owned by your process and not swapped out (i.e. in RAM). That is somewhat inaccurate, however. Reality is a lot more complicated.
简单地说,工作集是当前由您的进程拥有且未换出(即在 RAM 中)的内存页面的集合。然而,这有点不准确。现实要复杂得多。
Windows maintains a minimum working set size and a maximum working set size for every process. The minimum working set is easy, it is what Windows will grant to every process (as long as it can, by physical limits).
Windows 为每个进程维护最小工作集大小和最大工作集大小。最小工作集很简单,这是 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. However, while they are no longer in your working set, these pages are not necessarily"gone".
最大工作集更加可疑。如果您的程序使用的内存超过其配额,Windows 将丢弃一些页面。然而,虽然它们不再在您的工作集中,但这些页面不一定“消失”了。
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 中可以拥有比实际工作集中更多的页面,但它并不“正式”拥有它们。
回答by Erik
The Resident Set/Working Setis the portion of Virtual Address Spacewhich is currently residing in Physical Memoryand therefore isn't Swapped Out