确定谁/什么在 w3wp.exe 中保留了 5.5 GB 虚拟内存
在我的计算机(XP、64)上,ASP.net 工作进程 (w3wp.exe) 始终在启动时保留 5.5GB 的虚拟内存。 无论它托管的 Web 应用程序是什么(可以是任何内容,甚至是 aspx 中的空网页),都会发生这种情况。
这个大的旧虚拟内存块是在进程启动时保留的,因此这不是某种逐渐的内存“泄漏”。
用windbg进行一些窥探表明,有问题的内存是Private、Reserved和RegionUsageIsVAD,这表明它可能是有人调用VirtualAlloc的工作。 它还显示,所讨论的内存被分配/保留为 4 个大块,每个块 1GB 和几个较小的块(每个块 1/4GB)。
所以我想我需要弄清楚谁在调用 VirtualAlloc 并保留所有这些内存。 我怎么做?
在内存分配之前将调试器附加到进程是很棘手的,因为 w3wp.exe 是由 svchost.exe(即 IIS/ASP.Net 过滤器)启动的进程,并且如果我尝试自己启动它来调试它它只是关闭而没有所有这些大量的内存保留。 另外,如果我重新使用命令行参数,它们将无效(这是有道理的,因为它是由调用进程创建的管道)。
我可以在事后将 Windbg 它附加到进程中(这就是我找到有问题的内存区域的方式),但我不确定此时是否可以确定谁分配了什么。
On my machine (XP, 64) the ASP.net worker process (w3wp.exe) always launches with 5.5GB of Virtual Memory reserved. This happens regardless of the web application it's hosting (it can be anything, even an empty web page in aspx).
This big old chunk of virtual memory is reserved at the moment the process starts, so this isn't a gradual memory "leak" of some sort.
Some snooping around with windbg shows that the memory is question is Private, Reserved and RegionUsageIsVAD, which indicates it might be the work of someone calling VirtualAlloc. It also shows that the memory in question is allocated/reserved in 4 big chunks of 1GB each and a several smaller ones (1/4GB each).
So I guess I need to figure out who's calling VirtualAlloc and reserving all this memory. How do I do that?
Attaching a debugger to the process prior to the memory allocation is tricky, because w3wp.exe is a process launched by svchost.exe (that is, IIS/ASP.Net filter) and if I try to launch it myself in order to debug it it just closes down without all this profuse memory reservation. Also, the command line parameters are invalid if I resuse them (which makes sense because it's a pipe created by the calling process).
I can attach windbg it to the process after the fact (which is how I found the memory regions in question), but I'm not sure it's possible at that point to determine who allocated what.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
王大卫 回答了类似的问题:
David Wang answers this to a similar question:
虚拟内存只是分配给进程的地址空间。 它与内存使用无关。
请参阅:
Virtual memory is just the address space allocated to the process. It has nothing to do with memory usage.
See:
保留内存与分配内存有很大不同。 保留内存只是分配地址空间。 它不提交任何物理页。
该地址空间可能是由 IIS 为其堆分配的。 它只会在需要时提交页面。
如果您确实想从 Windbg 启动 w3wp.exe,您可能需要使用有效的命令行参数来启动它。 您可以使用 Process Explorer 来确定当前的命令行w3wp.exe进程是。 例如,在我的服务器上,我的服务器是:
我不确定其中的 UID 指定了什么,但它看起来它可能是由 W3SVC 服务(启动 w3wp.exe 的服务)动态生成的,以命名那里指定的管道。 因此,在从 Windbg 启动 w3wp 之前,您一定应该查看命令行。
Reserved memory is very different from allocated memory. Reserving memory just allocates address space. It doesn't commit any physical pages.
This address space is likely allocated by IIS for its heap. It will only commit pages when needed.
If you really want to launch w3wp.exe from windbg, you probably need to launch it with valid command-line arguments. You can use Process Explorer to determine what the command line for the current w3wp.exe process is. For instance, on my server, mine was:
I'm not sure what the UID in there specifies, but it looks it's probably generated on the fly by the W3SVC service (which is what launched w3wp.exe) to name the pipe specified there. So you should definitely look at your command line before launching w3wp from windbg.