gpt4 book ai didi

asp.net - Environment.WorkingSet 错误地报告内存使用情况

转载 作者:行者123 更新时间:2023-12-03 17:20:28 27 4
gpt4 key购买 nike

Environment.WorkingSet 错误地报告了在 Windows 2003 Server 上运行的网站的内存使用情况。(操作系统版本:Microsoft Windows NT 5.2.3790 Service Pack 2,.NET 版本:2.0.50727.3607)

它将内存报告为 Working Set(Physical Mem.): 1952 MB (2047468061)。

同一个网站在 Windows Vista 上本地运行,工作集(物理内存):49 MB (51924992)。

我对服务器的访问有限,支持也很有限:(。
所以我通过遍历 VirtualQuery 计算了总内存。
具有状态的页面总数:MEM_FREE 为 1300 MB。
(我猜服务器有 4 GB 的 RAM 并且未启用 PAE,最大用户模式虚拟地址为 0x7fff0000。)

所以,我知道工作集不仅仅是关于虚拟内存。但是,有这么高的工作集,而在另一台机器上却很低,这正常吗?

最佳答案

我认为问题与 this article 中描述的内容有关:

MAY 04, 2005
Fun with the WorkingSet and int32
I finally found an honest to goodness bug in the .NET framework.

... the WorkingSet returns the amount of memory being used by the process as an integer (32 bit signed integer). OK, so the maximum value of an integer is 2,147,483,647 -- which is remarkably close to the total amount of memory that a process can have in its working set.

... There is actually a switch in Windows that will allow a process to use 3 gig of memory instead of 2 gig. This switch is often turned on when dealing with Analysis Services -- this thing can be a memory hog. So now what happens is that when I poll the WorkingSet I get a negative number, a really big negative number. Usually, in the realm of -2,147,482,342.

... The problem was the overflow bit.

Working set is returned to the .NET framework as a binary value. The first bit of an integer is the sign bit. 0 is positive, 1 is negative. So, when the value turned from (binary) 1111111111111111111111111111111 to (binary) 10000000000000000000000000000000 the value goes from 2147483647 to -2147483647.

OK, so I still have to fix this. Here is what I came up with (in C#):

long lWorkingSet = 0;
if (process.WorkingSet >= 0)
lWorkingSet = processWorkingSet;
else
lWorkingSet = ((long)int.MaxValue*2)+process.WorkingSet;

Hopefully that fixes the problem for now.

The real question will come in down the road. Microsoft knows about this problem. I still have find out how they are going to fix this for Win64...where this trick will no longer work.



http://msdn2.microsoft.com/library/0aayt1d0(en-us,vs.80).aspx:
There's gonna be a Process.WorkingSet64 variable, and they're deprecating WorkingSet.

On a tangent, though, I thought it was impossible for a managed process to come near the 3gb limit, because the runtime splits the memory into multiple heaps. Is this not true?

关于asp.net - Environment.WorkingSet 错误地报告内存使用情况,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3378874/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com