HighTechTalks DotNet Forums  

.Net 2.0 memory usage

Dotnet Framework microsoft.public.dotnet.framework


Discuss .Net 2.0 memory usage in the Dotnet Framework forum.



Reply
 
Thread Tools Search this Thread Display Modes
  #1  
Old   
Joe K
 
Posts: n/a

Default .Net 2.0 memory usage - 02-14-2007 , 05:01 PM






I ported a .Net service from 1.1 to 2.0. In .Net 1.1, the total private
bytes for this service ran around 40MB. In .Net 2.0, the same service has
total private bytes of around 140MB. I then ran our service under a memory
debugger, and we have a total of 34 MB allocated on the heap.

Anyone have any ideas as to where the extra 100MB is going in .Net 2.0?

Joe



Reply With Quote
  #2  
Old   
Joe K
 
Posts: n/a

Default Re: .Net 2.0 memory usage - 02-14-2007 , 05:27 PM






So check this out:
- .Net memory # Bytes in all Heaps = 1.8 MB
- .Net memory # Total committed bytes = 3.3 MB
- .Net memory # Total reserved bytes = 33.9 MB
- Private bytes = 139.6 MB

Huh? This make any sense to anyone?



Reply With Quote
  #3  
Old   
ForrestPhoto@gmail.com
 
Posts: n/a

Default Re: .Net 2.0 memory usage - 02-15-2007 , 05:14 AM



Quote:
Huh? This make any sense to anyone?
No. What does your service do?



Reply With Quote
  #4  
Old   
Joe K
 
Posts: n/a

Default Re: .Net 2.0 memory usage - 02-15-2007 , 03:30 PM



I have a little more information. The difference appears to be related to
System.Threading.Thread. If I build a standalone .Net service in .Net 2.0
that starts 100 threads, I will see ~110 MB of memory allocated in private
bytes to this process. The same code on .Net 1.1 results in 7 MB of memory
in private bytes.

If anyone can explain this, I am very interested in understanding this.

Thanks.

Joe



Reply With Quote
  #5  
Old   
Henning Krause [MVP - Exchange]
 
Posts: n/a

Default Re: .Net 2.0 memory usage - 02-15-2007 , 05:21 PM



Hello,

usually, every thread has a stack size of 1 MB... but AFAIK, that has not
changed from 1.1 to 2.0. So I would guess, the .NET 2.0 behavior is
correct. I'm not sure why a .NET 1.1 software would behave other.

Albeit from this: Why are you using 100 threads? Seem very much to me...
either, most of your threads wait most of the time, or you'll have many
thread context switches...

Best regards,
Henning Krause


"Joe K" <joe (AT) nospamplease (DOT) com> wrote

Quote:
I have a little more information. The difference appears to be related to
System.Threading.Thread. If I build a standalone .Net service in .Net 2.0
that starts 100 threads, I will see ~110 MB of memory allocated in private
bytes to this process. The same code on .Net 1.1 results in 7 MB of
memory
in private bytes.

If anyone can explain this, I am very interested in understanding this.

Thanks.

Joe




Reply With Quote
  #6  
Old   
Joe K
 
Posts: n/a

Default Re: .Net 2.0 memory usage - 02-15-2007 , 05:43 PM



My theory is that the .Net 2.0 behavior is correct too - I just can't
explain what I see in .Net 1.1

Is it possible that .Net 1.1 used the Win32 thread pool in some way,
resulting in the memory allocated for a threads to be counted as shared
memory, and thus not being counted in private bytes?

I used 100 as an example. Our thread pool shrinks/grows based on demand.

Joe



Reply With Quote
  #7  
Old   
Henning Krause [MVP - Exchange]
 
Posts: n/a

Default Re: .Net 2.0 memory usage - 02-15-2007 , 05:52 PM



Hello,

the .NET ThreadPool is built ontop on the Win32 threadpool in both versions.

But if you create 100 threads yourself, the ThreadPool is not used...

Best regards,
Henning Krause

"Joe K" <joe (AT) nospamplease (DOT) com> wrote

Quote:
My theory is that the .Net 2.0 behavior is correct too - I just can't
explain what I see in .Net 1.1

Is it possible that .Net 1.1 used the Win32 thread pool in some way,
resulting in the memory allocated for a threads to be counted as shared
memory, and thus not being counted in private bytes?

I used 100 as an example. Our thread pool shrinks/grows based on demand.

Joe




Reply With Quote
  #8  
Old   
Joe K
 
Posts: n/a

Default Re: .Net 2.0 memory usage - 02-16-2007 , 09:17 AM



Okay, then I can't explain it. Go ahead and try it though. The below code
in .Net 1.1 reports 7MB for private bytes, but 111MB in 2.0.

namespace TestService
{
public partial class Service1 : ServiceBase
{
public Service1()
{
InitializeComponent();
}

protected override void OnStart(string[] args)
{
for (int i = 0; i < 100; i++)
{
Thread thread = new Thread(Service1.Run);
thread.Start();
}
}

protected override void OnStop()
{
// TODO: Add code here to perform any tear-down necessary to
stop your service.
}

protected static void Run()
{
while (true)
{
Thread.Sleep(1000*10);
}
}
}
}





Reply With Quote
  #9  
Old   
Chris Mullins [MVP]
 
Posts: n/a

Default Re: .Net 2.0 memory usage - 02-16-2007 , 01:01 PM



If nothing else, you're creating 100 threads. Each thread requires 1 Meg of
stack space from your Working Set. That's 100 Megs already.

--
Chris Mullins, MCSD.NET, MCPD:Enterprise, Microsoft C# MVP
http://www.coversant.com/blogs/cmullins

"Joe K" <joe (AT) nospamplease (DOT) com> wrote

Quote:
Okay, then I can't explain it. Go ahead and try it though. The below
code
in .Net 1.1 reports 7MB for private bytes, but 111MB in 2.0.

namespace TestService
{
public partial class Service1 : ServiceBase
{
public Service1()
{
InitializeComponent();
}

protected override void OnStart(string[] args)
{
for (int i = 0; i < 100; i++)
{
Thread thread = new Thread(Service1.Run);
thread.Start();
}
}

protected override void OnStop()
{
// TODO: Add code here to perform any tear-down necessary to
stop your service.
}

protected static void Run()
{
while (true)
{
Thread.Sleep(1000*10);
}
}
}
}







Reply With Quote
  #10  
Old   
Joe K
 
Posts: n/a

Default Re: .Net 2.0 memory usage - 02-16-2007 , 04:09 PM



Create 10, 20 or 100 threads in your test, and the result will still be the
same: thread memory is not counted in private bytes in 1.1, but is in 2.0.
I'm just wondering why? Not sure I understand the fixation on the # of
threads - that has nothing to do with my question.

Joe



Reply With Quote
Reply




Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Powered by vBulletin Version 3.5.4
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.