1

I'm trying to monitor memory usage. I wrote a sample c# code to be certain that I'm measuring correctly:

var list = new List<byte[]>();
int INCREMENT = 100; // 100MB
for(int i=0; i<10; i++){
  list.Add(new byte[INCREMENT * 1024 * 1024]);// 100 MB steps
  Thread.sleep(4000);
}

I used task manager and recorded the readings for "Private Working Set":

3'800k = 3.7M
3'900k = 3.8M
4'100k = 4M
4'300k = 4.2M
4'500k = 4.4M
5'200k = 5.07M
5'400k = 5.27M
5'600k = 5.47M
5'900k = 5.76M
6'100k = 5.96M

Does anyone know why the numbers make no sense?

3
  • 4
    They make complete sense. I don't understand the question. Commented Apr 18, 2014 at 21:44
  • You are populating a list every 4 seconds and your memory is growing accordingly. What seems to be wrong? Commented Apr 18, 2014 at 21:47
  • why the memory is increasing by 0.2 MB instead of 100MB? Commented Apr 18, 2014 at 22:22

3 Answers 3

1

Instead of looking at "Memory (Private Working Set)", look at "Commit Size". You may have to add it with "/View/Select Columns..." then check "Commit Size". For me it increased by about a GB, while working set went up by 3 MB.

Sign up to request clarification or add additional context in comments.

3 Comments

Just to add to this, try looking at this page for an explaination of what these things mean. Also, try looking at this SO Question in which Lars does a good job explaining what these things mean in better English.
Thanks. What's called "Commit size" in task manager is the one that makes sense. Now, I'm trying to retrieve it from wmi, but the Win32_PerfRawData_PerfProc_Process class does not have such a property. The Win32_PerfRawData_PerfOS_Memory class has such a property, but it is a global value - not process specific. Any ideas? see: msdn.microsoft.com/en-us/library/aa394323(v=vs.85).aspx
from Icemanind's link, Memory-Commit Size is the same as Virtual Memory. But when I monitor VirtualBytes with wmi, it does not change.
1

If you look at the definition for "Memory (private working set)" in Task Manager, it says "Amount of physical memory in use by the process that cannot be used by other processes". This is very different from "private bytes" which is the number of virtual memory bytes that cannot be shared by other processes.

The data you allocate in your sample may or may not be backed by physical memory at any given time. That's what is reflected by "Memory (private working set)". Since you never write any of that memory Windows has cleverly decided not to back the virtual memory with real memory pages. If you fill the array with data you'll see that the corresponding memory pages are allocated.

2 Comments

Your comment makes sense. My goal here is to use wmi to detect memory issues and I guess that unallocated (virtual) memory is a potential problem as well and would be nice to monitor. Do you agree?
I'm not sure what you mean. The point here is that when you allocate memory in your example, the memory is reserved, but not committed which is why you don't see the expected increase reported by task manager. If/when you write the memory it is committed and thus you'll see that reflected in the number reported by task manager.
0

When I run the code posted above, I actually see the "commit size" in task manager increase. If I want to retrieve that in a sript, I need to use the wmi api. When I use a wmi query such as this:

SELECT PrivateBytes FROM Win32_PerfRawData_PerfProc_Process WHERE IDProcess=1234

it does not detect the increase. You can run this query either in powershell, python,...while the test app is running. I appreciate if someone can comment on this as well.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.