<?xml version="1.0" encoding="UTF-8" ?>
<?xml-stylesheet type="text/xsl" href="http://sqlblog.com/utility/FeedStylesheets/rss.xsl" media="screen"?><rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/" xmlns:wfw="http://wellformedweb.org/CommentAPI/"><channel><title>Search results matching tags 'Database Administration' and 'Memory Allocation'</title><link>http://sqlblog.com/search/SearchResults.aspx?o=DateDescending&amp;tag=Database+Administration,Memory+Allocation&amp;orTags=0</link><description>Search results matching tags 'Database Administration' and 'Memory Allocation'</description><dc:language>en-US</dc:language><generator>CommunityServer 2.1 SP2 (Build: 61129.1)</generator><item><title>TSQL Tuesday #11 Misconceptions – Enable AWE on 64bit SQL Servers</title><link>http://sqlblog.com/blogs/jonathan_kehayias/archive/2010/10/12/tsql-tuesday-11-misconceptions-enable-awe-on-64bit-sql-servers.aspx</link><pubDate>Tue, 12 Oct 2010 16:58:25 GMT</pubDate><guid isPermaLink="false">21093a07-8b3d-42db-8cbf-3350fcbf5496:29338</guid><dc:creator>jmkehayias</dc:creator><description>&lt;p&gt;&lt;a href="http://sankarreddy.com/2010/10/invitation-to-participate-in-t-sql-tuesday-11-misconceptions-in-sql-server/?utm_source=twitterfeed&amp;amp;utm_medium=twitter&amp;amp;utm_campaign=Feed%3A+SankarReddySqlServer+%28Sankar+Reddy+%29"&gt;&lt;/a&gt;&lt;a href="http://sankarreddy.com/2010/10/invitation-to-participate-in-t-sql-tuesday-11-misconceptions-in-sql-server/"&gt;&lt;img style="margin:5px 5px 5px 15px;" title="T-SQL Tuesday" alt="T-SQL Tuesday" align="right" src="http://SankarReddy.com/wp-content/uploads/2010/10/TSQL2sDay150x150.jpg" width="150" height="150" /&gt;&lt;/a&gt;&lt;/p&gt;  &lt;p&gt;&lt;em&gt;This post is part of the monthly community event called T-SQL Tuesday started by Adam Machanic (&lt;/em&gt;&lt;a href="http://sqlblog.com/blogs/adam_machanic/"&gt;&lt;strong&gt;&lt;em&gt;blog&lt;/em&gt;&lt;/strong&gt;&lt;/a&gt;&lt;em&gt;|&lt;/em&gt;&lt;a href="http://twitter.com/adammachanic"&gt;&lt;strong&gt;&lt;em&gt;twitter&lt;/em&gt;&lt;/strong&gt;&lt;/a&gt;&lt;em&gt;) and hosted by someone else each month. This month the host is Sankar Reddy (&lt;/em&gt;&lt;a href="http://sankarreddy.com/"&gt;&lt;strong&gt;&lt;em&gt;blog&lt;/em&gt;&lt;/strong&gt;&lt;/a&gt;&lt;em&gt;|&lt;/em&gt;&lt;a href="http://twitter.com/SankarReddy13/"&gt;&lt;strong&gt;&lt;em&gt;twitter&lt;/em&gt;&lt;/strong&gt;&lt;/a&gt;&lt;em&gt;) and the topic is &lt;/em&gt;&lt;a href="http://sankarreddy.com/2010/10/invitation-to-participate-in-t-sql-tuesday-11-misconceptions-in-sql-server/"&gt;&lt;strong&gt;&lt;em&gt;Misconceptions in SQL Server&lt;/em&gt;&lt;/strong&gt;&lt;/a&gt;&lt;em&gt;. You can follow posts for this theme on Twitter by looking at &lt;/em&gt;&lt;a href="http://twitter.com/#search?q=%23TSQL2sDay"&gt;&lt;strong&gt;&lt;em&gt;#TSQL2sDay&lt;/em&gt;&lt;/strong&gt;&lt;/a&gt;&lt;em&gt; hashtag.&lt;/em&gt;&lt;/p&gt;  &lt;p&gt;Next to SQL Server having a Memory Leak, the misconception that you have to enable AWE on 64 bit SQL Servers has to be one of the most prevalent pieces of incorrect advice that I see on the MSDN Forums.&amp;#160; This has been blogged about multiple times, yet it continues to be a problem.&lt;/p&gt;  &lt;p&gt;&lt;a href="http://www.sqlskills.com/BLOGS/PAUL/post/A-SQL-Server-DBA-myth-a-day-(530)-AWE-must-be-enabled-on-64-bit-servers.aspx"&gt;Paul Randal: A SQL Server DBA myth a day: (5/30) AWE must be enabled on 64-bit servers&lt;/a&gt;     &lt;br /&gt;&lt;a href="http://blogs.msdn.com/b/psssql/archive/2009/09/11/fun-with-locked-pages-awe-task-manager-and-the-working-set.aspx" target="_blank"&gt;Bob Ward: Fun with Locked Pages, AWE, Task Manager, and the Working Set…&lt;/a&gt;     &lt;br /&gt;&lt;a href="http://msdn.microsoft.com/en-us/library/ms190731(SQL.90).aspx" target="_blank"&gt;Books Online: awe enable Option&lt;/a&gt;&lt;/p&gt;  &lt;p&gt;This post was originally started in early March of this year, and I haven't ever gotten back around to finishing it based on a thread on the &lt;a href="http://social.msdn.microsoft.com/Forums/en-US/sqldatabaseengine/thread/2e0919ea-6fda-47c0-b132-f8b87fd8a6f2" target="_blank"&gt;MSDN Forums&lt;/a&gt; that I got involved with where misinterpretations of posts by Bob Ward and Slava Oks were the center of the confusion. (Note here that I said it was someone's misinterpretation, and not incorrect information by Bob or Slava whose posts point out that ‘awe enabled’ is a NoOp in 64bit systems)&amp;#160; It seems that the confusion here centers around information that are contained in a couple of blog posts by Slava and Bob where they provide some internals information about memory in SQL Server and use terminology that can be confusing to people just learning about memory internals.&lt;/p&gt;  &lt;p&gt;The most common reference that people provide for using ‘awe enabled’ on 64bit servers is Slava Oks blog post &lt;a href="http://blogs.msdn.com/b/slavao/archive/2005/04/29/413425.aspx" target="_blank"&gt;Be Aware: Using AWE, locked pages in memory, on 64 bit&lt;/a&gt;, where he says:&lt;/p&gt;    &lt;table cellspacing="0" cellpadding="2" bgcolor="#eeeeee"&gt;       &lt;tr&gt;         &lt;td&gt;           &lt;p align="left"&gt;&lt;em&gt;To some people it comes as a surprise that AWE mechanism is still present and actually could be useful on 64 bit platforms. As you remember the mechanism consists of two parts allocating physical memory and mapping it to the given process's VAS. The advantage of allocation mechanism is that once physical memory is allocated operating system can't reclaim it until either the process is terminated or the process frees memory back to the OS.&lt;/em&gt;&lt;/p&gt;         &lt;/td&gt;       &lt;/tr&gt;     &lt;/table&gt;   &lt;p&gt;Notice that this says AWE mechanism, not enabling AWE.&amp;#160; What exactly is the AWE mechanism?&amp;#160; It is just a different memory API, AllocateUserPhysicalPages(), used to allocate the memory.&amp;#160; On a 64 bit server you enable Lock Pages in Memory to make use of this API instead of using VirtualAlloc() to allocate all of the memory for the buffer pool.&amp;#160; &lt;/p&gt;  &lt;p&gt;The other common example cited by people is the following comment by Bob Ward on his &lt;a href="http://blogs.msdn.com/b/psssql/archive/2009/09/11/fun-with-locked-pages-awe-task-manager-and-the-working-set.aspx" target="_blank"&gt;blog post&lt;/a&gt; listed above:&amp;#160; &lt;/p&gt;    &lt;table cellspacing="0" cellpadding="2" bgcolor="#eeeeee"&gt;       &lt;tr&gt;         &lt;td&gt;           &lt;p align="left"&gt;&lt;em&gt;Well….the developers of the product discovered that if they still use the AWE APIs to allocate memory even though it is not really needed, two things would happen:&lt;/em&gt; &lt;/p&gt;            &lt;ul&gt;             &lt;li&gt;               &lt;div align="left"&gt;&lt;em&gt;A small performance gain occurs within the kernel. For more details, read this blog post from Slava Oks: &lt;/em&gt;&lt;a href="http://blogs.msdn.com/slavao/archive/2005/04/29/413425.aspx"&gt;&lt;em&gt;http://blogs.msdn.com/slavao/archive/2005/04/29/413425.aspx&lt;/em&gt;&lt;/a&gt; &lt;/div&gt;             &lt;/li&gt;              &lt;li&gt;               &lt;div align="left"&gt;&lt;em&gt;Just as with 32bit systems, any memory allocated using&amp;#160; the AWE API is not part of the working set and therefore cannot be paged to disk. Therefore it is considered “locked”.&lt;/em&gt; &lt;/div&gt;             &lt;/li&gt;           &lt;/ul&gt;            &lt;p align="left"&gt;&lt;em&gt;Thus was born the concept most refer to as “locked pages” for 64bit SQL Server editions.&lt;/em&gt;&lt;/p&gt;         &lt;/td&gt;       &lt;/tr&gt;     &lt;/table&gt;   &lt;div align="left"&gt;&amp;#160;&lt;/div&gt;  &lt;div align="left"&gt;On more than a few occasions people have pointed to this statement as being proof that you have to use ‘awe enabled’ for a performance boost in 64 bit servers.&amp;#160; What always amazes me is that in the same blog post, Bob specifically addresses this:&lt;/div&gt;  &lt;div align="left"&gt;&amp;#160;&lt;/div&gt;    &lt;table cellspacing="0" cellpadding="2" bgcolor="#eeeeee"&gt;       &lt;tr&gt;         &lt;td&gt;           &lt;p align="left"&gt;&lt;em&gt;&lt;strong&gt;2. Do I need to use the “awe enabled” sp_configure option on 64bit systems for SQL Server to “lock pages”?&lt;/strong&gt; &lt;/em&gt;&lt;/p&gt;            &lt;p align="left"&gt;No. In fact, the code for SQL Server for 64bit systems ignores this sp_configure option. It is a “no-op” for 64bit SQL Server systems. You may ask why is this the case if I just told you that AWE APIs are used in 64bit SQL Server systems to “lock pages”?&lt;/p&gt;            &lt;p align="left"&gt;The answer is based on the purpose for that sp_configure option. The purpose of this sp_configure option on 32bit systems is for the user to “enable” the “AWE” feature, which is I explained above is to extend the ability to reference memory &amp;gt; 4Gb. Now as I mentioned already in order to use the AWE APIs you must have the “Locked Pages in Memory” Privilege. So, when you try to use sp_configure to set ‘awe enabled’ on a 32bit we actually will fail this command if “Locked Pages in Memory” is not set.&lt;/p&gt;         &lt;/td&gt;       &lt;/tr&gt;     &lt;/table&gt;   &lt;p&gt;You don't have to do a thing with &amp;quot;awe enabled&amp;quot; on 64bit servers to scale memory, and you don't even need to use Lock Pages in Memory.&amp;#160; A 64 bit server can utilize the memory available on the server entirely through calls to VirtualAlloc() because it has 8TB (7TB on IA64) of user mode Virtual Address Space within which to allocate the available memory.&amp;#160; A 32 bit server doesn't have this ability since it only has 4GB of total Virtual Address Space spit 50/50 into user and kernel modes.&amp;#160; The maximum amount of memory that a 32 bit SQL Server can allocate without using AWE is around 1.6GB through VirtualAlloc(), or 2.6GB if the /3GB boot.ini switch has been used (which consequently limits the maximum amount of memory that could be mapped with AWE enabled since it reduces kernel mode address space and the available Page Table Entries for mapping AWE allocated memory).&amp;#160; &lt;/p&gt;  &lt;p&gt;The performance benefit that Bob and Slava talk about has to do with the fact that when Lock Pages in Memory is set, the memory allocated can't be paged out by the Operating System, a problem that exists when the memory is allocated using VirtualAlloc() only, allowing SQL Server to manage its memory entirely on its own.&amp;#160; This is specifically important on NUMA systems as detailed in Slavas &lt;a href="http://blogs.msdn.com/b/slavao/archive/2005/04/29/413425.aspx" target="_blank"&gt;blog post&lt;/a&gt;.&amp;#160; On a 32 bit server having the buffer pool paged is bad, but its impact is low since the buffer pool is 1.6GB.&amp;#160; However, on a 64 bit server with 32GB or memory that has 28GB allocated to the buffer pool, the impact of having the memory paged out is very significant.&amp;#160; When the SQL Server Service account has the Lock Pages In Memory set in the User Rights Assignment the database engine in Enterprise Edition, or Standard Edition with the correct Service Pack, Cumulative Update, and trace flag 834 set, will use the &amp;quot;AWE Mechanism&amp;quot; to lock the memory allocated for the Buffer Pool.&amp;#160; &lt;/p&gt;  &lt;p&gt;So there you have it, once again, there is no need to enable AWE on 64bit servers.&lt;/p&gt;</description></item><item><title>Troubleshooting the SQL Server Memory Leak (or Understanding SQL Server Memory Usage)</title><link>http://sqlblog.com/blogs/jonathan_kehayias/archive/2009/08/24/troubleshooting-the-sql-server-memory-leak-or-understanding-sql-server-memory-usage.aspx</link><pubDate>Tue, 25 Aug 2009 01:32:00 GMT</pubDate><guid isPermaLink="false">21093a07-8b3d-42db-8cbf-3350fcbf5496:16272</guid><dc:creator>jmkehayias</dc:creator><description>&lt;p&gt;I guess this could be considered a continuation of my last post about SQL Server Memory, &lt;a href="http://sqlblog.com/blogs/jonathan_kehayias/archive/2009/07/07/understanding-the-vas-reservation-aka-memtoleave-in-sql-server.aspx"&gt;Understanding the VAS Reservation (aka MemToLeave) in SQL Server&lt;/a&gt;, but for a long time I have noticed that when people don’t understand how SQL Server uses memory on their server, they immediately begin to think that SQL Server has a memory leak.&amp;nbsp; So in this post I’ll dive into how SQL Server allocates and uses the physical memory available on a server.&lt;/p&gt;  &lt;p&gt;Proper management of server resources is crucial to maintaining good performance, and as we all know a server only has a finite amount of resources.&amp;nbsp; Often when performance problems occur, the first counters looked at by system administrators are the CPU utilization and Memory Utilization counters, most often I would suspect through the Windows Task Manager and then PerfMon.&amp;nbsp; When a Windows Administrator/User that doesn’t understand SQL Server sees that SQL Server is consuming 2.7GB of memory on a 4GB server, for whatever reason, the first conclusion that they come to is that SQL Server has a memory leak.&amp;nbsp; Nothing could be farther from the truth.&amp;nbsp; This has become even more common lately as 64 bit servers become more common and the expanded VAS (I covered this in my last post) allows SQL Server to commit all of the available memory on the server without advanced configuration of options like AWE.&lt;/p&gt;  &lt;p&gt;So what exactly is going on here?&amp;nbsp; Well first recall that SQL Server has two types of memory usage, VAS (aka MemToLeave on 32bit servers) and the Buffer Pool or BPool.&amp;nbsp; When SQL Server starts up the maximum size of the BPool is calculated based on the servers configuration.&amp;nbsp; For 32bit servers without AWE enabled, the VAS reservation is calculated and reserved first, then the remaining user mode VAS is compared to the amount of physical memory available on the server.&amp;nbsp; The smaller of the two values is then compared to the max server memory configuration option and the smallest number becomes the maximum size for the BPool.&amp;nbsp; For example, a 32bit server with 4GB RAM, the /3GB boot.ini switch, and a max server memory configuration of 2048MB the maximum size of the BPool would be 2048MB:&lt;/p&gt;  &lt;blockquote&gt;   &lt;p&gt;3072MB (3GB) user VAS - 384MB = 2688MB available VAS      &lt;br&gt;4096MB (4GB) Physical Memory &amp;gt; 2688MB available VAS       &lt;br&gt;2688MB available VAS &amp;gt; 2048MB max server memory configuration&lt;/p&gt; &lt;/blockquote&gt;  &lt;p&gt;However, when AWE is enabled the BPool maximum size isn’t restricted by the available user mode VAS.&amp;nbsp; Instead the maximum size of the BPool is based on the physical memory on the server or the max server memory configuration setting, whichever is smaller.&amp;nbsp; For example, a 32bit server with 8GB RAM, the /PAE boot.ini switch, AWE enabled, and a max server memory configuration of 6144MB the maximum size of the BPool would be 6144MB:&lt;/p&gt;  &lt;blockquote&gt;8192MB (8GB) Physical Memory &amp;gt; 6144MB max server memory configuration&lt;/blockquote&gt;  &lt;p&gt;For 64 bit servers, there is no need to use AWE to allocate memory above 3GB for SQL Server since the user mode VAS is 8TB there is always ample VAS to utilize all of the physical memory available on the server.&amp;nbsp; However, the AWE mechanism for allocating memory is still useful and available on 64 bit servers.&amp;nbsp; It is used whenever the&amp;nbsp; the Lock Pages in Memory security right has been granted to the SQL Server Service Account and can improve the stability and performance of a 64 bit system. (see Slava Ok’s blog post &lt;a href="http://blogs.msdn.com/slavao/archive/2005/04/29/413425.aspx" target="_blank"&gt;Be Aware: Using AWE, locked pages in memory, on 64 bit&lt;/a&gt; ) For 64 bit servers, the maximum size of the BPool is the size of physical memory or the max server memory configuration, whichever is smaller.&amp;nbsp; For example, a 64 bit server with 16GB RAM, and a default max server memory configuration, the maximum size of the Bpool would be 16GB.&amp;nbsp; &lt;/p&gt;  &lt;p&gt;Once the calculations have been made, the address space for the BPool is reserved, but not committed.&amp;nbsp; SQL Server will only commit the physical memory as it needs it.&amp;nbsp; However, and this is what most people don’t seem to understand, once committed the memory will not be release back to the operating system unless the server gets into memory pressure.&amp;nbsp; (see Slava Ok’s blog post &lt;a href="http://blogs.msdn.com/slavao/archive/2006/11/13/q-a-does-sql-server-always-respond-to-memory-pressure.aspx" target="_blank"&gt;Q &amp;amp; A: Does SQL Server always respond to memory pressure?)&lt;/a&gt;&amp;nbsp; When data is needed for a query, SQL Server first checks the BPool to determine if the data is already available.&amp;nbsp; If it is, the data in the BPool is used to run the query, which is why performance improves after the first time a query executes.&amp;nbsp; If the data isn’t in the BPool, it is read from disk into the BPool where it is then used to run the query.&amp;nbsp; SQL Server attempts to keep data loaded in the BPool for as long as possible once it has been physically read from disk, and will commit additional memory up to the maximum calculated limit to accomplish this.&amp;nbsp; Once the maximum calculated limit has been reached, stale data is flushed from the cache by the memory clerks based on the counter ticks maintained internally in the caches (See Slava Ok’s blog post &lt;a href="http://blogs.msdn.com/slavao/archive/2005/03/18/398651.aspx" target="_blank"&gt;SQLOS Caching&lt;/a&gt;).&amp;nbsp; &lt;/p&gt;  &lt;p&gt;Since the operating system still requires memory to operate, you should set the max server memory configuration option to ensure that the operating system has sufficient memory once SQL Server has committed its memory for use.&amp;nbsp; This is especially important on 64 bit servers where the larger VAS allows for the SQL process to take all of the physical memory which can result in a paging situation for the SQL processes, degrading performance.&amp;nbsp; For this reason, 64 bit servers should use the Lock Pages in Memory right so that the AWE Mechanism is used to allocate memory, preventing paging of the BPool.&amp;nbsp; In the RTM of SQL Server 2005 and SQL Server 2008, this was a Enterprise Edition only feature.&amp;nbsp; This however was changed based on community feedback and is available in Standard Edition through the use of a trace flag 845 when the appropriate updates have been applied to SQL Server (see &lt;a href="http://blogs.msdn.com/psssql/archive/2009/05/19/an-update-for-standard-sku-support-for-locked-pages.aspx"&gt;An update for Standard SKU Support for Locked Pages…&lt;/a&gt;)&lt;/p&gt;  &lt;p&gt;For further information see the &lt;a href="http://technet.microsoft.com/en-us/library/cc280359.aspx"&gt;Memory Management Architecture&lt;/a&gt; Topic in the Books Online&lt;/p&gt;  &lt;p&gt;Some example posts on this topic from the MSDN Forums are:&lt;/p&gt;  &lt;blockquote&gt;   &lt;p&gt;&lt;a href="http://social.msdn.microsoft.com/Forums/en-US/sqlgetstarted/thread/558023bf-9c44-4112-bddc-f269bebabdff" title="http://social.msdn.microsoft.com/Forums/en-US/sqlgetstarted/thread/558023bf-9c44-4112-bddc-f269bebabdff" target="_blank"&gt;SQL server memory leak&lt;/a&gt;       &lt;br&gt;&lt;a href="http://social.msdn.microsoft.com/Forums/en-US/sqlgetstarted/thread/bbd2cce3-59f2-4d51-a5bb-49c5f41ea9b2"&gt;how to release memory from sql&lt;/a&gt;       &lt;br&gt;&lt;a href="http://social.msdn.microsoft.com/Forums/en-US/sqldatabaseengine/thread/ca454222-c4c4-4f1b-b41a-e05d9264bd7c"&gt;Max Workspace Memory (KB) is high&lt;/a&gt;       &lt;br&gt;&lt;a href="http://social.msdn.microsoft.com/Forums/en-US/sqldatabaseengine/thread/b873d49b-e2cb-4c97-8a2a-0d05380610f9"&gt;sql takes too much ram&lt;/a&gt;       &lt;br&gt;&lt;a href="http://social.msdn.microsoft.com/forums/en-US/sqldatabaseengine/thread/4e3c0646-671a-44e4-a466-aba6b5f0fb50/"&gt;&lt;b&gt;Memory&lt;/b&gt; consumption for SQL Server&lt;/a&gt;       &lt;br&gt;&lt;a href="http://social.msdn.microsoft.com/Forums/en-US/sqldatabaseengine/thread/eeeff44d-e139-4ce0-9ebd-b410e8ee80ee"&gt;Memory Consumption?&lt;/a&gt;       &lt;br&gt;&lt;a href="http://social.msdn.microsoft.com/Forums/en-US/sqldatabaseengine/thread/a6fd7f30-cabd-4cda-a117-ad9a862ea5a6"&gt;sqlservr.exe is continually eating more memory&lt;/a&gt;       &lt;br&gt;&lt;a href="http://social.msdn.microsoft.com/Forums/en-US/sqldatabaseengine/thread/4f4d0730-5eb0-498f-8e66-48093669e96e"&gt;Memory getting full&lt;/a&gt; &lt;/p&gt; &lt;/blockquote&gt;  &lt;p&gt;Hopefully this clears up the misunderstanding regarding how SQL Server allocates and consumes memory.&lt;/p&gt;  &lt;h5&gt;UPDATE:&lt;/h5&gt;  &lt;p&gt;Based on Aaron’s comment (thank you Aaron for pointing it out), I should clarify that the Task manager doesn’t show the correct numbers for memory allocated to SQL on 64 bit servers and servers using AWE.&amp;nbsp; To get the amount of memory used, you should read the following memory counters:&lt;/p&gt;  &lt;p&gt;Performance object: &lt;b&gt;Process&lt;/b&gt;    &lt;br&gt;Counter: &lt;b&gt;Private Bytes&lt;/b&gt;    &lt;br&gt;Instance: &lt;b&gt;sqlservr&lt;/b&gt;&lt;/p&gt;  &lt;p&gt;Performance object: &lt;b&gt;Process&lt;/b&gt;    &lt;br&gt;Counter: &lt;b&gt;Working Set &lt;/b&gt;    &lt;br&gt;Instance: &lt;b&gt;sqlservr&lt;/b&gt;&lt;/p&gt;  &lt;p&gt;&lt;b&gt;&lt;/b&gt;&lt;/p&gt;  &lt;p&gt;The &lt;b&gt;Private Bytes&lt;/b&gt; counter measures the amount of memory that is currently committed. The &lt;b&gt;Working Set&lt;/b&gt; counter measures the amount of physical memory that the process currently occupies. SQL Server also uses the following performance counter to expose the amount of memory that the buffer pool allocates: &lt;/p&gt;  &lt;p&gt;Performance object: &lt;b&gt;SQL Server:Memory Manager &lt;/b&gt;    &lt;br&gt;Counter: &lt;b&gt;Total Server Memory(KB)&lt;/b&gt;. &lt;/p&gt;  &lt;p&gt;&lt;b&gt;Note&lt;/b&gt; If the instance of SQL Server 2005 64-bit is a named instance, the name of the performance object is &lt;b&gt;MSSQL$InstanceName: Memory Manager&lt;/b&gt;.&lt;/p&gt;</description></item><item><title>Understanding the VAS Reservation (aka MemToLeave) in SQL Server</title><link>http://sqlblog.com/blogs/jonathan_kehayias/archive/2009/07/07/understanding-the-vas-reservation-aka-memtoleave-in-sql-server.aspx</link><pubDate>Tue, 07 Jul 2009 05:41:00 GMT</pubDate><guid isPermaLink="false">21093a07-8b3d-42db-8cbf-3350fcbf5496:15123</guid><dc:creator>jmkehayias</dc:creator><description>&lt;p&gt;For a long time now I've had a Word Document I was working on to cover the subject of the VAS Reservation (aka MemToLeave) in SQL Server.&amp;nbsp; I've been quite busy this year, so I never got around to completing it, and I wasn't sure of where I wanted to publish it, on my blog or as an article submission somewhere else.&amp;nbsp; Today an article on SQL Server Central titled SQL Server Memory Configuration, Determining MemToLeave Settings was published that has incorrect information and fails to adequately cover the subject.&amp;nbsp; I've left a comment on the article, but the subject of VAS Reservation in SQL Server is to vast to cover in the comments on a article that are unlikely to be read by someone who has a problem with VAS in their SQL Server instance.&lt;/p&gt;  &lt;p&gt;To start off with, MemToLeave is a moniker, or even better put a misnomer.&amp;nbsp; It was named MemToLeave based on the way that SQL Server allocates memory when it starts up, but it lead to confusion over the idea that it was memory that SQL Server wouldn't allocate.&amp;nbsp; The appropriate terminology for what is commonly known as the MemToLeave is the VAS Reservation.&amp;nbsp; This area of memory in SQL Server is frequently the source of many questions online that relate to Out of Memory Exceptions inside of SQL Server, and it is one of the most misunderstood portions of SQL Server memory.&amp;nbsp; Before getting into the internals of SQL Server memory, lets first take a look at Virtual Address Space in general, and the differences between 32 bit and 64 bit servers.&lt;/p&gt;  &lt;p&gt;&lt;b&gt;Differences in VAS Sizing 32bit vs 64bit&lt;/b&gt;&lt;/p&gt;  &lt;p&gt;Servers that are x86 or 32 bit have a VAS region that is 2^32 in size or roughly speaking 4 GB.&amp;nbsp; This is by default split 50/50 into kernel mode and user mode VAS regions.&amp;nbsp; Applications like SQL Server, run inside the user mode VAS region (this article will forgo discussions on AWE and PAE which can be used in conjunction with one another to allow the SQL Server Buffer Cache to utilize memory beyond 4GB), which is why non-AWE instances of SQL Server max out their buffer pool size around 1.6GB for a server with 4GB of memory installed.&amp;nbsp; To work around this limitation, the /3GB and /USERVA boot.ini switches can be used to change the user/kernel mode proportions from 50/50 to 75/25 (/3GB) or a user defined proportion (/USERVA) to allow SQL Server to address more memory for its buffer pool.&lt;/p&gt;  &lt;p&gt;Servers that are x64/IA64 or 64 bit have a VAS region that is 2^64 in size or roughly speaking 16 trillion GB (I am sure there is a proper name for this size, but I don't know it off hand, lets just call it a ridiculously large number for today's memory needs).&amp;nbsp; Since this is well beyond the physical capabilities for memory, the user mode and kernel mode VAS are capped at 8TB each for x64 based 64 bit servers (IA64 has a 7TB user mode cap).&amp;nbsp; This expanded VAS changes the dynamic of how applications such as SQL Server allocate memory.&lt;/p&gt;  &lt;p&gt;&lt;b&gt;Startup Allocation of Memory&lt;/b&gt;&lt;/p&gt;  &lt;p&gt;When SQL Server starts up, the first memory item that is reserved by the SQLOS is the VAS Reservation memory area.&amp;nbsp; This is a special contiguous memory area that is separate completely from the Bpool, and is for use by external consumers such as Extended Procedures, COM objects (OLE Automation calls), Linked Servers, OLEDB providers, SQL CLR, and is also used for allocations larger than 8KB (&amp;gt;8KB), also known as multi-page allocations, by the database engine (extemely large and complex query plans).&amp;nbsp; It has a calculated fixed size that is determined at startup based on the following formula:&lt;/p&gt;  &lt;blockquote&gt;   &lt;p&gt;(MaxWorkerThreads * StackSize) + DefautReservationSize&lt;/p&gt; &lt;/blockquote&gt;  &lt;p&gt;The MaxWorkerThreads default on SQL Server 7.0 is 128 and on SQL Server 2000 it is 255.&amp;nbsp; However, on SQL Server 2005 and 2008 it is dynamic and depends on the number of schedulers (processors) you have configured in the SQL Server.&amp;nbsp; The formula for the number of worker threads is:&lt;/p&gt;  &lt;blockquote&gt;   &lt;p&gt;((NumberOfSchedulers - 4) * 8) + BaseThreadCount&lt;/p&gt; &lt;/blockquote&gt;  &lt;p&gt;For 32 bit SQL Servers the BaseThreadCount is 256. For 64 bit SQL Servers the BaseThreadCount is doubled to 512.&lt;/p&gt;  &lt;p&gt;Note: On SQL Server 2005 and 2008, if the number of schedulers is less than four, then the BaseThreadCount is the default value for the MaxWorkerThreads; 256 for 32 bit and 512 for 64 bit servers respectively.&amp;nbsp; You can also query this information from the system:&lt;/p&gt;  &lt;blockquote&gt;   &lt;p&gt;select max_workers_count      &lt;br&gt;from sys.dm_os_sys_info&lt;/p&gt; &lt;/blockquote&gt;  &lt;p&gt;For a 32 bit SQL Server the default StackSize is 512KB so to determine the memory allocation to the VAS Reservation for a 2 processor 32 bit SQL Server the calculation would be (256*512KB) + 256MB or 384MB of space.&amp;nbsp; &lt;/p&gt;  &lt;p&gt;For a 64 bit SQL Server the default StackSize is 2048KB or 2MB, so for the same server only 64 bit, it would be (512*2048KB) + 256MB or 1280MB.&amp;nbsp; Keep in mind that only 256MB of this space is available for use by external objects both of these scenarios since the worker thread memory reservation is used to manage the worker threads in SQL Server.&lt;/p&gt;  &lt;p&gt;Once this calculation and allocation has been completed, the next memory space setup by the SQL Server is the BPool or buffer pool.&amp;nbsp; The buffer pool size is determined by a number of factors, beginning with whether the server has AWE enabled on not.&amp;nbsp; If AWE is not enabled on the SQL Server, then the buffer pool is sized based on the remaining memory in the user address space minus the VAS Reservation allocation that has been previously calculated.&amp;nbsp; On 32 bit SQL Servers, the VAS is 4GB in size, and by default is split 50/50 into user address space and kernel address space, with 2GB assigned to each.&amp;nbsp; By using the /3GB or /USERVA startup switches in the Windows boot.ini file, this default configuration can be overridden to provide 3GB of VAS to the user address space, leaving 1GB for the kernel address space.&lt;/p&gt;  &lt;p&gt;Once the user address space size has been determined by the SQL Server, the previously calculate VAS Reservation reservation is subtracted from it.&amp;nbsp; Then the resulting value is compared to the amount of available physical memory on the SQL Server, and the lower of the two numbers is the maximum available space for the buffer pool size.&amp;nbsp; This is then compared to the max server memory setting and the lower of the two values is then the maximum size of the buffer pool.&amp;nbsp; For a SQL Server with 1GB of Physical RAM and the default configuration of the Operating System and SQL Server options, this would equate to a maximum buffer pool size of 1GB based on the following calculations:&lt;/p&gt;  &lt;blockquote&gt;   &lt;p&gt;2048MB (2GB) user VAS - 384MB = 1664MB available VAS&lt;/p&gt;    &lt;p&gt;1024MB (1GB) Physical Memory&lt;/p&gt; &lt;/blockquote&gt;  &lt;p&gt;Since the smaller of the two is the physical memory size, then this is the buffer pool size.&amp;nbsp; However, on a 2GB of Physical Memory server, the maximum size of the buffer pool would be 1664MB since the available user VAS is the smaller amount.&amp;nbsp; This is why adding the /3GB switch is often done in the boot.ini, which would change the calculation to be:&lt;/p&gt;  &lt;blockquote&gt;   &lt;p&gt;3072MB (3GB) user VAS - 384MB = 2688MB available VAS &lt;/p&gt;    &lt;p&gt;4096MB (4GB) Physical Memory&lt;/p&gt; &lt;/blockquote&gt;  &lt;p&gt;Here the maximum size of the buffer pool is going to be 2688MB.&amp;nbsp; If however AWE is enabled on the SQL Server, then the maximum size of the buffer pool is the upper limit of the Physical RAM on the SQL Server or the max server memory setting, whichever is smaller.&amp;nbsp; &lt;/p&gt;  &lt;p&gt;On 64 bit SQL Servers, the VAS Reservation at startup does not occur due to the size of VAS available on 64 bit systems.&amp;nbsp; ( Thank you Linchi Shea and Bob Ward for correcting me on this.)&amp;nbsp; &lt;br&gt;&lt;/p&gt;&lt;p&gt;After reserving and allocating the BPool memory area, SQL Server will then release the VAS Reservation area it reserved in the first step in order to have this region of address space available for objects which utilize VAS Reservation memory.&lt;/p&gt;  &lt;p&gt;&lt;b&gt;Understanding allocations from the VAS Reservation&lt;/b&gt;&lt;/p&gt;  &lt;p&gt;The VAS Reservation itself isn't necessarily the limit of VAS available to SQL Server after the BPool size is calculated.&amp;nbsp; Any remaining user mode VAS can be used by SQL Server for VAS/multi-page allocators inside of SQL Server.&amp;nbsp; For this reason, the available VAS region inside SQL Server can be larger than the VAS Reservation computed and reserved at startup.&amp;nbsp; Consider for example the 32 bit server with 1GB of physical memory in the previous example.&amp;nbsp; The VAS reservation + the Buffer Pool size of 1GB is still short of the 2GB user mode VAS on the server.&amp;nbsp; When this occurs, the balance of user mode VAS is still useable for multi-page allocations by SQL Server, though it can lead to over commitment of memory which can itself be problematic.&amp;nbsp; For 64 bit servers, the available VAS is always multiple terabytes in size, so the limit to memory allocation is the limit of uncommited physical memory on the server.&lt;/p&gt;  &lt;p&gt;One of the biggest problems associated with the VAS Reservation on 32 bit servers is fragmentation, which occurs when blocks of memory are allocated from the VAS Reservation and then released later, leaving smaller contiguous blocks of memory available.&amp;nbsp; When SQL Server allocates memory from the VAS Reservation it requires contiguous blocks of memory to make the allocation.&amp;nbsp; This means that you can have 100MB of memory available but if the largest contiguous block is only 4MB and a 8MB allocation is required the request will fail.&amp;nbsp; VAS fragmentation is one of the most difficult scenarios to troubleshoot because there is no means to defragment the VAS space, and it often requires looking at the VAS consumers in your workload to determine why the fragmentation is occurring.&lt;/p&gt;  &lt;p&gt;&lt;b&gt;Troubleshooting VAS and Out of Memory Exceptions&lt;/b&gt;&lt;/p&gt;  &lt;p&gt;How you actually go about troubleshooting Out of Memory (OOM) problems related to VAS in SQL Server depends on a number of factors including what version of SQL Server you are running, what architecture it is running on, and what potential VAS consumers you have in your system.&amp;nbsp; By far the worst problems troubleshooting VAS problems occur on SQL Server 2000, where the ability to look at VAS information is very limited.&amp;nbsp; SQL Server 2005 and 2008 offer much more in the way of troubleshooting problems with the Dynamic Management Views.&amp;nbsp; For SQL Server 2000, the only way to get information on VAS inside SQL Server is to use the vmstat executable.&amp;nbsp; This tool is available as a part of the PSS Labs download from Microsoft in Lab #3:&lt;/p&gt;  &lt;p&gt;&lt;a href="http://www.microsoft.com/downloads/details.aspx?FamilyId=AEC18337-887F-4EC6-A858-81F84DE8082F&amp;amp;displaylang=en"&gt;http://www.microsoft.com/downloads/details.aspx?FamilyId=AEC18337-887F-4EC6-A858-81F84DE8082F&amp;amp;displaylang=en&lt;/a&gt;&lt;/p&gt;  &lt;p&gt;The output from the tool is a table that shows information similar to:&lt;/p&gt;  &lt;blockquote&gt;   &lt;p&gt;&lt;font face="Courier"&gt;TYPE&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; MINIMUM&amp;nbsp;&amp;nbsp;&amp;nbsp; MAXIMUM&amp;nbsp;&amp;nbsp;&amp;nbsp; AVERAGE&amp;nbsp; BLK COUNT        &lt;br&gt;~~~~&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; ~~~~~~~&amp;nbsp;&amp;nbsp;&amp;nbsp; ~~~~~~~&amp;nbsp;&amp;nbsp;&amp;nbsp; ~~~~~~~&amp;nbsp; ~~~~~~~~~         &lt;br&gt;Commit&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 4096&amp;nbsp; 769654784&amp;nbsp;&amp;nbsp;&amp;nbsp; 2141981&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 833         &lt;br&gt;Reserve&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 8192&amp;nbsp;&amp;nbsp;&amp;nbsp; 4128768&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 387799&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 121         &lt;br&gt;Free&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 4096&amp;nbsp; 166080512&amp;nbsp;&amp;nbsp;&amp;nbsp; 1964121&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 161         &lt;br&gt;Private&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 4096&amp;nbsp; 769654784&amp;nbsp;&amp;nbsp;&amp;nbsp; 4089322&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 438         &lt;br&gt;Mapped&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 4096&amp;nbsp;&amp;nbsp;&amp;nbsp; 1019904&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 131891&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 40         &lt;br&gt;Image&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 4096&amp;nbsp;&amp;nbsp;&amp;nbsp; 7598080&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 73099&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 476&lt;/font&gt;&lt;/p&gt; &lt;/blockquote&gt;  &lt;p&gt;The free Type and Maximum column show the largest available contiguous block of VAS available to SQL Server.&amp;nbsp; This information is in bytes.&amp;nbsp; In SQL Server 2005 and 2008, this same information is available in the DMV's.&amp;nbsp; Christian Bolton offers a great VAS Summary query on his blog post &lt;a href="http://sqlblogcasts.com/blogs/christian/archive/2008/01/07/sql-server-memtoleave-vas-and-64-bit.aspx"&gt;SQL Server memtoleave, VAS and 64-bit - Christian Bolton's SQL Server Blog&lt;/a&gt;:&lt;/p&gt;  &lt;blockquote&gt;   &lt;p&gt;&lt;code style="font-size:12px;"&gt;&lt;span style="color:blue;"&gt;WITH &lt;/span&gt;&lt;span style="color:black;"&gt;VASummary&lt;/span&gt;&lt;span style="color:gray;"&gt;(&lt;/span&gt;&lt;span style="color:black;"&gt;Size&lt;/span&gt;&lt;span style="color:gray;"&gt;,&lt;/span&gt;&lt;span style="color:black;"&gt;Reserved&lt;/span&gt;&lt;span style="color:gray;"&gt;,&lt;/span&gt;&lt;span style="color:black;"&gt;Free&lt;/span&gt;&lt;span style="color:gray;"&gt;) &lt;/span&gt;&lt;span style="color:blue;"&gt;AS          &lt;br&gt;&lt;/span&gt;&lt;span style="color:gray;"&gt;(&lt;/span&gt;&lt;span style="color:blue;"&gt;SELECT          &lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;span style="color:black;"&gt;Size &lt;/span&gt;&lt;span style="color:blue;"&gt;= &lt;/span&gt;&lt;span style="color:black;"&gt;VaDump.Size&lt;/span&gt;&lt;span style="color:gray;"&gt;,          &lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;span style="color:black;"&gt;Reserved &lt;/span&gt;&lt;span style="color:blue;"&gt;=&amp;nbsp; &lt;/span&gt;&lt;span style="color:magenta;"&gt;SUM&lt;/span&gt;&lt;span style="color:gray;"&gt;(&lt;/span&gt;&lt;span style="color:magenta;"&gt;CASE&lt;/span&gt;&lt;span style="color:gray;"&gt;(&lt;/span&gt;&lt;span style="color:magenta;"&gt;CONVERT&lt;/span&gt;&lt;span style="color:gray;"&gt;(&lt;/span&gt;&lt;span style="color:blue;"&gt;INT&lt;/span&gt;&lt;span style="color:gray;"&gt;, &lt;/span&gt;&lt;span style="color:black;"&gt;VaDump.Base&lt;/span&gt;&lt;span style="color:gray;"&gt;)^&lt;/span&gt;&lt;span style="color:black;"&gt;0&lt;/span&gt;&lt;span style="color:gray;"&gt;)          &lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;span style="color:blue;"&gt;WHEN &lt;/span&gt;&lt;span style="color:black;"&gt;0 &lt;/span&gt;&lt;span style="color:blue;"&gt;THEN &lt;/span&gt;&lt;span style="color:black;"&gt;0 &lt;/span&gt;&lt;span style="color:blue;"&gt;ELSE &lt;/span&gt;&lt;span style="color:black;"&gt;1 &lt;/span&gt;&lt;span style="color:blue;"&gt;END&lt;/span&gt;&lt;span style="color:gray;"&gt;),          &lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;span style="color:black;"&gt;Free &lt;/span&gt;&lt;span style="color:blue;"&gt;= &lt;/span&gt;&lt;span style="color:magenta;"&gt;SUM&lt;/span&gt;&lt;span style="color:gray;"&gt;(&lt;/span&gt;&lt;span style="color:magenta;"&gt;CASE&lt;/span&gt;&lt;span style="color:gray;"&gt;(&lt;/span&gt;&lt;span style="color:magenta;"&gt;CONVERT&lt;/span&gt;&lt;span style="color:gray;"&gt;(&lt;/span&gt;&lt;span style="color:blue;"&gt;INT&lt;/span&gt;&lt;span style="color:gray;"&gt;, &lt;/span&gt;&lt;span style="color:black;"&gt;VaDump.Base&lt;/span&gt;&lt;span style="color:gray;"&gt;)^&lt;/span&gt;&lt;span style="color:black;"&gt;0&lt;/span&gt;&lt;span style="color:gray;"&gt;)          &lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;span style="color:blue;"&gt;WHEN &lt;/span&gt;&lt;span style="color:black;"&gt;0 &lt;/span&gt;&lt;span style="color:blue;"&gt;THEN &lt;/span&gt;&lt;span style="color:black;"&gt;1 &lt;/span&gt;&lt;span style="color:blue;"&gt;ELSE &lt;/span&gt;&lt;span style="color:black;"&gt;0 &lt;/span&gt;&lt;span style="color:blue;"&gt;END&lt;/span&gt;&lt;span style="color:gray;"&gt;)          &lt;br&gt;&lt;/span&gt;&lt;span style="color:blue;"&gt;FROM          &lt;br&gt;&lt;/span&gt;&lt;span style="color:gray;"&gt;(          &lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;span style="color:blue;"&gt;SELECT&amp;nbsp; &lt;/span&gt;&lt;span style="color:magenta;"&gt;CONVERT&lt;/span&gt;&lt;span style="color:gray;"&gt;(&lt;/span&gt;&lt;span style="color:black;"&gt;VARBINARY&lt;/span&gt;&lt;span style="color:gray;"&gt;, &lt;/span&gt;&lt;span style="color:magenta;"&gt;SUM&lt;/span&gt;&lt;span style="color:gray;"&gt;(&lt;/span&gt;&lt;span style="color:black;"&gt;region_size_in_bytes&lt;/span&gt;&lt;span style="color:gray;"&gt;))          &lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;span style="color:blue;"&gt;AS &lt;/span&gt;&lt;span style="color:black;"&gt;Size&lt;/span&gt;&lt;span style="color:gray;"&gt;, &lt;/span&gt;&lt;span style="color:black;"&gt;region_allocation_base_address &lt;/span&gt;&lt;span style="color:blue;"&gt;AS &lt;/span&gt;&lt;span style="color:black;"&gt;Base          &lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;span style="color:blue;"&gt;FROM &lt;/span&gt;&lt;span style="color:black;"&gt;sys.dm_os_virtual_address_dump&amp;nbsp; &lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;span style="color:blue;"&gt;WHERE &lt;/span&gt;&lt;span style="color:black;"&gt;region_allocation_base_address &lt;/span&gt;&lt;span style="color:gray;"&gt;&amp;lt;&amp;gt; &lt;/span&gt;&lt;span style="color:black;"&gt;0x0          &lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;span style="color:blue;"&gt;GROUP BY &lt;/span&gt;&lt;span style="color:black;"&gt;region_allocation_base_address&amp;nbsp; &lt;br&gt;&amp;nbsp;&lt;/span&gt;&lt;span style="color:blue;"&gt;UNION&amp;nbsp;&amp;nbsp; &lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; SELECT &lt;/span&gt;&lt;span style="color:magenta;"&gt;CONVERT&lt;/span&gt;&lt;span style="color:gray;"&gt;(&lt;/span&gt;&lt;span style="color:black;"&gt;VARBINARY&lt;/span&gt;&lt;span style="color:gray;"&gt;, &lt;/span&gt;&lt;span style="color:black;"&gt;region_size_in_bytes&lt;/span&gt;&lt;span style="color:gray;"&gt;), &lt;/span&gt;&lt;span style="color:black;"&gt;region_allocation_base_address          &lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;span style="color:blue;"&gt;FROM &lt;/span&gt;&lt;span style="color:black;"&gt;sys.dm_os_virtual_address_dump          &lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;span style="color:blue;"&gt;WHERE &lt;/span&gt;&lt;span style="color:black;"&gt;region_allocation_base_address&amp;nbsp; &lt;/span&gt;&lt;span style="color:blue;"&gt;= &lt;/span&gt;&lt;span style="color:black;"&gt;0x0          &lt;br&gt;&lt;/span&gt;&lt;span style="color:gray;"&gt;)          &lt;br&gt;&lt;/span&gt;&lt;span style="color:blue;"&gt;AS &lt;/span&gt;&lt;span style="color:black;"&gt;VaDump          &lt;br&gt;&lt;/span&gt;&lt;span style="color:blue;"&gt;GROUP BY &lt;/span&gt;&lt;span style="color:black;"&gt;Size&lt;/span&gt;&lt;span style="color:gray;"&gt;)          &lt;br&gt;          &lt;br&gt;          &lt;br&gt;&lt;/span&gt;&lt;span style="color:blue;"&gt;SELECT &lt;/span&gt;&lt;span style="color:magenta;"&gt;SUM&lt;/span&gt;&lt;span style="color:gray;"&gt;(&lt;/span&gt;&lt;span style="color:magenta;"&gt;CONVERT&lt;/span&gt;&lt;span style="color:gray;"&gt;(&lt;/span&gt;&lt;span style="color:black;"&gt;BIGINT&lt;/span&gt;&lt;span style="color:gray;"&gt;,&lt;/span&gt;&lt;span style="color:black;"&gt;Size&lt;/span&gt;&lt;span style="color:gray;"&gt;)*&lt;/span&gt;&lt;span style="color:black;"&gt;Free&lt;/span&gt;&lt;span style="color:gray;"&gt;)/&lt;/span&gt;&lt;span style="color:black;"&gt;1024 &lt;/span&gt;&lt;span style="color:blue;"&gt;AS &lt;/span&gt;&lt;span style="color:black;"&gt;[Total avail mem, KB] &lt;/span&gt;&lt;span style="color:gray;"&gt;,&lt;/span&gt;&lt;span style="color:magenta;"&gt;CAST&lt;/span&gt;&lt;span style="color:gray;"&gt;(&lt;/span&gt;&lt;span style="color:blue;"&gt;MAX&lt;/span&gt;&lt;span style="color:gray;"&gt;(&lt;/span&gt;&lt;span style="color:black;"&gt;Size&lt;/span&gt;&lt;span style="color:gray;"&gt;) &lt;/span&gt;&lt;span style="color:blue;"&gt;AS &lt;/span&gt;&lt;span style="color:black;"&gt;BIGINT&lt;/span&gt;&lt;span style="color:gray;"&gt;)/&lt;/span&gt;&lt;span style="color:black;"&gt;1024 &lt;/span&gt;&lt;span style="color:blue;"&gt;AS &lt;/span&gt;&lt;span style="color:black;"&gt;[Max free size, KB]&amp;nbsp; &lt;br&gt;&lt;/span&gt;&lt;span style="color:blue;"&gt;FROM &lt;/span&gt;&lt;span style="color:black;"&gt;VASummary&amp;nbsp; &lt;br&gt;&lt;/span&gt;&lt;span style="color:blue;"&gt;WHERE &lt;/span&gt;&lt;span style="color:black;"&gt;Free &lt;/span&gt;&lt;span style="color:gray;"&gt;&amp;lt;&amp;gt; &lt;/span&gt;&lt;span style="color:black;"&gt;0&lt;/span&gt;&lt;/code&gt; &lt;/p&gt; &lt;/blockquote&gt;  &lt;p&gt;Further when troubleshooting what is consuming memory in SQL Server 2000, the best you can get is the output from DBCC MEMORYSTATUS, which is very limited in SQL Server 2000 when compared to the same output from SQL Server 2005 and 2008.&amp;nbsp; However, in SQL Server 2005 and 2008, the sys.dm_os_memory_clerks DMV can be used to look at where VAS allocations are being used in much more detail.&lt;/p&gt;  &lt;blockquote&gt;   &lt;p&gt;&lt;code style="font-size:12px;"&gt;&lt;span style="color:blue;"&gt;SELECT &lt;/span&gt;&lt;span style="color:black;"&gt;type&lt;/span&gt;&lt;span style="color:gray;"&gt;, &lt;/span&gt;&lt;span style="color:black;"&gt;virtual_memory_committed_kb&lt;/span&gt;&lt;span style="color:gray;"&gt;, &lt;/span&gt;&lt;span style="color:black;"&gt;multi_pages_kb          &lt;br&gt;&lt;/span&gt;&lt;span style="color:blue;"&gt;FROM &lt;/span&gt;&lt;span style="color:black;"&gt;sys.dm_os_memory_clerks          &lt;br&gt;&lt;/span&gt;&lt;span style="color:blue;"&gt;WHERE &lt;/span&gt;&lt;span style="color:black;"&gt;virtual_memory_committed_kb &lt;/span&gt;&lt;span style="color:gray;"&gt;&amp;gt; &lt;/span&gt;&lt;span style="color:black;"&gt;0 &lt;/span&gt;&lt;span style="color:gray;"&gt;OR &lt;/span&gt;&lt;span style="color:black;"&gt;multi_pages_kb &lt;/span&gt;&lt;span style="color:gray;"&gt;&amp;gt; &lt;/span&gt;&lt;span style="color:black;"&gt;0&lt;/span&gt;&lt;/code&gt; &lt;/p&gt; &lt;/blockquote&gt;  &lt;p&gt;From this, you can begin to look at the clerks that are the highest consumers and begin troubleshooting form there.&amp;nbsp; Understanding the consumers of VAS in your environment is one of the keys to troubleshooting VAS allocation issues.&amp;nbsp; As previously covered, common consumers of VAS in SQL are Extended Procedures, COM objects (OLE Automation calls), Linked Servers, OLEDB providers, SQL CLR, and is also used for allocations larger than 8KB (&amp;gt;8KB), also known as multi-page allocations, by the database engine.&amp;nbsp; Other consumers can include third party backup tools (LiteSpeed for example), and connections that have a network packet size &amp;gt; 8000 bytes (this puts them into multi-page allocation).&amp;nbsp; &lt;/p&gt;  &lt;p&gt;When any one of combination of many of these exists in your environment you need to look beyond the VAS size being the issue and determine if a problem in design, code or utilization is actually the problem.&amp;nbsp; For example, backups that use a large maxtransfersize or buffer size, or a network packet size &amp;gt; 8000 bytes can become heavy VAS consumers.&amp;nbsp; You may need to balance any performance increase realized by these tools in their default configuration with the need to resize your VAS allocation.&amp;nbsp; If you utilize OLE Automation to call COM objects, you need to make sure that for every call to sp_OACreate, you have a corresponding call to sp_OADestroy, or you will leak VAS from the open pointers.&lt;/p&gt;  &lt;p&gt;If you are on a 32 bit SQL Server, one thing that can be tried is to bump the size of the Base VAS Reservation so that more memory is reserved up front.&amp;nbsp; To increase the available size of space in the MemToLeave area, the -g startup parameter can be used to specify a value larger than 256MB.&amp;nbsp; Values less than or equal to 256MB specified with the -g startup parameter are ignored by SQL Server and the default 256MB allocation is used.&amp;nbsp; This can not be used on 64 bit servers since the VAS Reservation calculations do not occur on 64 bit servers.&amp;nbsp; &lt;/p&gt;  &lt;p&gt;The problem with using this startup parameter on a 32 bit server is that it reduces the size of the buffer pool, especially on servers that don't utilize AWE, so there is a trade off that happens.&amp;nbsp; For this reason, any use of this startup parameter should be carefully considered, and then slowly increased if necessary.&amp;nbsp; If the VAS problem is with fragmentation or worse a true memory leak from a custom Extended Stored procedure, increasing the base allocation may not resolve the problem, it will only make the time to encounter the error longer, so it isn't a catch all fix to the problem.&amp;nbsp; If your VAS problems are related to overuse of VAS then adding this parameter may solve the problem, you have to test to find out, but one note is that changing this value requires a server restart to take effect.&lt;/p&gt;  &lt;p&gt;If you are on a 64 bit SQL Server, the only real solution to the problem that I have found to date is to back down the size of the max server memory setting, which leaves additional physical memory available to be used for multi-page allocations and VAS requirements.&amp;nbsp; This essentially is doing the same thing that bumping the VAS reservation with the -g startup parameter does, by removing memory from the BPool allocation and leaving it available for VAS allocations.&lt;/p&gt;  &lt;p&gt;I hope this helps those who have had questions on how memory is determined during the startup of SQL Server. &lt;/p&gt;  &lt;p&gt;&lt;b&gt;References:&lt;/b&gt;&lt;/p&gt;  &lt;p&gt;&lt;a href="http://searchsqlserver.techtarget.com/searchSQLServer/downloads/Guru_Guide_to_SQL_Server_Architecture_Chap%2011_AWL.pdf"&gt;Guru Guide to SQL Server Architecture - Chapter 11&lt;/a&gt;&lt;/p&gt;  &lt;p&gt;&lt;a href="http://blogs.msdn.com/khen1234/archive/2006/01/31/520724.aspx"&gt;Memory-mapped files and SQL Server - Ken Henderson's WebLog&lt;/a&gt;&lt;/p&gt;  &lt;p&gt;&lt;a href="http://blogs.msdn.com/khen1234/archive/2005/05/08/415501.aspx"&gt;Be careful with xproc memory allocation - Ken Henderson's WebLog&lt;/a&gt;&lt;/p&gt;  &lt;p&gt;&lt;a href="http://msdn.microsoft.com/en-us/library/aa175282%28SQL.80%29.aspx"&gt;Inside SQL Server 2000's Memory Management Facilities&lt;/a&gt;&lt;/p&gt;  &lt;p&gt;&lt;a href="http://www.sqljunkies.ddj.com/Tutorial/0D4FF40A-695C-4327-A41B-F9F2FE2D58F6.scuk"&gt;SQL Server Memory - Microsoft SQL Server Team&lt;/a&gt;&lt;/p&gt;  &lt;p&gt;&lt;a href="http://blogs.msdn.com/slavao/archive/2005/02/11/371063.aspx"&gt;SQLOS's memory manager and SQL Server's Buffer Pool&lt;/a&gt;&lt;/p&gt;  &lt;p&gt;&lt;a href="http://sqlblogcasts.com/blogs/christian/archive/2008/01/07/sql-server-memtoleave-vas-and-64-bit.aspx"&gt;SQL Server memtoleave, VAS and 64-bit - Christian Bolton's SQL Server Blog&lt;/a&gt;&lt;/p&gt;</description></item></channel></rss>