{"id":23164,"date":"2007-05-15T09:40:00","date_gmt":"2007-05-15T09:40:00","guid":{"rendered":"https:\/\/blogs.msdn.microsoft.com\/maoni\/2007\/05\/15\/64-bit-vs-32-bit\/"},"modified":"2021-10-04T16:33:29","modified_gmt":"2021-10-04T23:33:29","slug":"64-bit-vs-32-bit","status":"publish","type":"post","link":"https:\/\/devblogs.microsoft.com\/dotnet\/64-bit-vs-32-bit\/","title":{"rendered":"64-bit vs 32-bit"},"content":{"rendered":"<p><P class=\"MsoNormal\"><FONT face=\"Verdana\">As 64-bit machines become more common, the problems we need to solve also evolve. In this post I\u2019d like to talk about what it means for the GC and the applications\u2019 memory usage when we move from 32-bit to 64-bit.<\/FONT><\/P>\n<P class=\"MsoNormal\"><FONT face=\"Verdana\">&nbsp;<\/FONT><\/P>\n<P class=\"MsoNormal\"><FONT face=\"Verdana\">One big limitation of 32-bit is the virtual memory address space &#8211; as a user mode process you get 2GB, and if you use large address aware you get 3GB. A few years these seemed like giant numbers but I&#8217;ve seen as more and more people start using .NET framework, the sizes of the managed heap go up at a quite high rate. I remember when I first started working on GC (which was late 2004 I think) we were talking about hundreds of MBs of heaps &#8211; 300MB seemed like a lot. Today I am seeing managed heaps easily of GBs in size &#8211; and yes, some of them (and more and more of them) are on 64-bit &#8211; 2 or 3GB is just not enough anymore. <\/FONT><\/P>\n<P class=\"MsoNormal\"><FONT face=\"Verdana\">&nbsp;<\/FONT><\/P>\n<P class=\"MsoNormal\"><FONT face=\"Verdana\">And along with this, we are shifting to solving a different set of problems. In CLR 2.0 we concentrated heavily on using the VM space efficiently. We tried very hard to reduce the fragmentation on the managed heap so when you get a hold of a chunk of virtual memory you can make very efficient use of it. So people don&#8217;t see problems like they have N managed heap segments, are running out of VM, yet many of these segments are quite empty (meaning having a lot of free space on them). <\/FONT><\/P>\n<P class=\"MsoNormal\"><FONT face=\"Verdana\">&nbsp;<\/FONT><\/P>\n<P class=\"MsoNormal\"><FONT face=\"Verdana\">Then you switch to 64-bit. Now suddenly you don&#8217;t need to worry about VM anymore &#8211; you get plenty there. Practically unlimited for many applications (of course it\u2019s still limited \u2013 for example if you are running out physical memory to even allocate the datastructures for virtual pages then you still can\u2019t reserve those pages). What kind of differences will you see in your managed memory usage?<\/FONT><\/P>\n<P class=\"MsoNormal\"><FONT face=\"Verdana\">&nbsp;<\/FONT><\/P>\n<P class=\"MsoNormal\"><FONT face=\"Verdana\">First of all, your process consumes more memory &#8211; I am sure all of you are already aware of this &#8211; the pointer size is bigger &#8211; it&#8217;s doubled on 64-bit so if you don&#8217;t change anything at all, now your managed heap (which undoubtly contains references) is bigger. Of course being able to manipulate memory in QWORDs instead of DWORDs can also be beneficial \u2013our measurements show that the raw allocation speed is slightly higher on 64-bit than on 32-bit that can be attributed to this.<\/FONT><\/P>\n<P class=\"MsoNormal\"><FONT face=\"Verdana\">&nbsp;<\/FONT><\/P>\n<P class=\"MsoNormal\"><FONT face=\"Verdana\">There are other factors that could make your process consume more memory &#8211; for example the module size is bigger (mscorwks.dll is about 5MB on x86, 10MB on x64 and 20MB on ia64), instructions are bigger on 64-bit and what have you. <\/FONT><\/P>\n<P class=\"MsoNormal\"><FONT face=\"Verdana\">&nbsp;<\/FONT><\/P>\n<P class=\"MsoNormal\"><FONT face=\"Verdana\">Another thing you may notice &#8211; if you have looked at the performance counters under .NET CLR Memory &#8211; is that you are now doing a lot fewer GCs on 64-bit than what you used to see on 32-bit. <\/FONT><\/P>\n<P class=\"MsoNormal\"><FONT face=\"Verdana\">&nbsp;<\/FONT><\/P>\n<P class=\"MsoNormal\"><FONT face=\"Verdana\">The curious minds might have already noticed one thing &#8211; the managed heap segments are much bigger in size on 64-bit. If you do !SOS.eeheap -gc you will now see way bigger segments. <\/FONT><\/P>\n<P class=\"MsoNormal\"><FONT face=\"Verdana\">&nbsp;<\/FONT><\/P>\n<P class=\"MsoNormal\"><FONT face=\"Verdana\">Why did we make the segment size so much bigger on 64-bit? Well, remember we talked about in <\/FONT><A href=\"http:\/\/blogs.msdn.com\/maoni\/archive\/2004\/09\/25\/234273.aspx\"><FONT face=\"Verdana\" color=\"#800080\">Using GC Efficiently Part 2<\/FONT><\/A><FONT face=\"Verdana\"> how we have a budget for gen0 and when you&#8217;ve allocated more than this budget a GC will be triggered. When you have a bigger budget it means you\u2019ll need to do fewer GCs which means your code will get more chance to run. From this perspective you should get a performance gain when you move to 64-bit &#8211; I want to emphasize the \u201cthis perspective\u201d part because in general things tend to run slower on 64-bit. The perf benefit you get because of GC may very well be obscured by other perf degrades. In reality many people are not expecting perf gain when they move to 64-bit but rather they are happy with being able to use more memory to handle more work load.<\/FONT><\/P>\n<P class=\"MsoNormal\"><FONT face=\"Verdana\">&nbsp;<\/FONT><\/P><SPAN>Of course we also don\u2019t want to wait for too long before we collect \u2013 we strive for the right balance between memory (how much memory your app consumes) and CPU (how often user threads run). <\/SPAN><\/p>\n","protected":false},"excerpt":{"rendered":"<p>As 64-bit machines become more common, the problems we need to solve also evolve. In this post I\u2019d like to talk about what it means for the GC and the applications\u2019 memory usage when we move from 32-bit to 64-bit. &nbsp; One big limitation of 32-bit is the virtual memory address space &#8211; as a [&hellip;]<\/p>\n","protected":false},"author":3542,"featured_media":58792,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"footnotes":""},"categories":[685],"tags":[3011,108],"class_list":["post-23164","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-dotnet","tag-maoniposts","tag-performance"],"acf":[],"blog_post_summary":"<p>As 64-bit machines become more common, the problems we need to solve also evolve. In this post I\u2019d like to talk about what it means for the GC and the applications\u2019 memory usage when we move from 32-bit to 64-bit. &nbsp; One big limitation of 32-bit is the virtual memory address space &#8211; as a [&hellip;]<\/p>\n","_links":{"self":[{"href":"https:\/\/devblogs.microsoft.com\/dotnet\/wp-json\/wp\/v2\/posts\/23164","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/devblogs.microsoft.com\/dotnet\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/devblogs.microsoft.com\/dotnet\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/dotnet\/wp-json\/wp\/v2\/users\/3542"}],"replies":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/dotnet\/wp-json\/wp\/v2\/comments?post=23164"}],"version-history":[{"count":0,"href":"https:\/\/devblogs.microsoft.com\/dotnet\/wp-json\/wp\/v2\/posts\/23164\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/dotnet\/wp-json\/wp\/v2\/media\/58792"}],"wp:attachment":[{"href":"https:\/\/devblogs.microsoft.com\/dotnet\/wp-json\/wp\/v2\/media?parent=23164"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/dotnet\/wp-json\/wp\/v2\/categories?post=23164"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/dotnet\/wp-json\/wp\/v2\/tags?post=23164"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}