Search results matching tags 'Memory Management' and 'SQL Server Magazine'http://sqlblog.com/search/SearchResults.aspx?o=DateDescending&tag=Memory+Management,SQL+Server+Magazine&orTags=0Search results matching tags 'Memory Management' and 'SQL Server Magazine'en-USCommunityServer 2.1 SP2 (Build: 61129.1)Geek City: Q &amp; A on my Plan Cache Sizing article in SQL Server Magazinehttp://sqlblog.com/blogs/kalen_delaney/archive/2007/12/15/QA-on-my-plan-cache-sizing-article-in-sql-server-magazine.aspxSun, 16 Dec 2007 03:00:00 GMT21093a07-8b3d-42db-8cbf-3350fcbf5496:4004Kalen Delaney<BLOCKQUOTE></BLOCKQUOTE>
<P><A href="http://www.sqlmag.com/articles/articleid/97373/Managing_PlanCache_Size.html" target=_blank>My December article in SQL Server Magazine</A>, called Managing Plan Cache Size, expands on the information I talked about in a <A href="http://sqlblog.com/blogs/kalen_delaney/archive/2007/11/04/did-you-know-sp2-does-not-limit-the-amount-of-plan-cache-you-can-have.aspx" target=_blank>post last month on the limits of plan cache</A>.&nbsp; </P>
<P>A reader of the article ask some questions on the SQL Server Magazine web site, and I have decided to use my blog to post the answers. </P>
<P><EM>Q:&nbsp; Could you give me an illustration how to calculate target memory please? Let say there is a 64 bit system (64 bit hardware, windows 2003 64 bit enterprise edition, SQL Server 2005 Enterprise edition 64 bit, memory 30 GB), max server memory (in sp_configure) is between 16 (min value) - 30 GB (max value)).</EM> </P>
<BLOCKQUOTE>
<P align=left>A: Target memory refers to the maximum physical memory that can be committed to the buffer pool and ideally is the lesser of the values you’ve configured for “max server memory” and the total amount of visible physical memory available to the OS. On a 64bit system, all your memory is visible, and your max server memory is the same as your physical memory, so target ideally will be 30GB. You can see the target memory value in the metadata view <EM>sys.dm_os_sys_info</EM> (where it's called <B>bpool_commit_target)</B>, along with the value for visible memory (called <B>bpool_visible</B>).
<P align=left>However, there are other factors that can affect the target value. The BOL entry for <EM>sys.dm_os_sys_info</EM> defines <B>bpool_commit_target</B> as follows:
<P align=left><EM>"Number of 8-KB buffers needed by the buffer pool. The target amount is calculated using a variety of inputs such as the current state of the system, including its load, the memory requested by current processes, the amount of memory installed on the computer, and configuration parameters."</EM>
<P align=left>The exact formula is not published. It's best to just use <EM>sys.dm_os_sys_info</EM> to see what your system's target memory value is.
<P align=left>&nbsp;</P></BLOCKQUOTE>
<P><EM>Q:&nbsp; In your article, you give an example how to calculate plan-cache pressure limit, for example for SQL Server 2005 RTM and SP1, it calculates for on 28 target memory as follows : (.75 x 8 GB) + (.5 x 20 GB) = 6 GB. Then you add to 10 GB so pressure limit is 16 GB. Where does 10 GB come from?</EM>
<BLOCKQUOTE>
<P>A: You have rephrased the expression incorrectly. This is what the article says:
<P>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; (.75 x 8 GB) + (.5 x 20 GB) = 6 GB + 10 GB = 16 GB
<P>If you do the math, you’ll see that the first term in parentheses (.75 x 8 GB) is equal to 6 GB and the second term (.5 x 20 GB) is equal to 10 GB, so we add the 6 and the 10 together.
<P>&nbsp;</P></BLOCKQUOTE>
<P><EM>Q. You mention "plan-cache pressure limit". Does it mean that when , let's say pressure limit of 28 GB is 16 GB, 16 GB is reached then SQL Server couldn't remove plan cache to make it less than 16 GB, is my understanding right?</EM>
<BLOCKQUOTE>
<P>A: No, in the above example, we calculated the pressure limit to be 16 GB. That means when your SQL Server hits 16 GB of memory for plan cache, it will start removing plans from cache to keep cache from getting too big.
<P>&nbsp;</P></BLOCKQUOTE>
<P><EM>Q: You show how to remove a prepared query by creating a plan guide with recompile hint; is it possible to remove non-prepared query plan on the following sample:</EM>
<P><EM>EXEC sp_create_plan_guide @name = N'RemovePlan1', @stmt = N' SELECT * FROM Sales WHERE ContactID &lt; 3', @type = N'SQL', @module_or_batch = NULL, @params = N', @hints = N'OPTION(RECOMPILE)'; </EM>
<P><EM>and I issue query twice as below shown SELECT * FROM Sales WHERE ContactID &lt; 3 </EM>
<P><EM>When I check in syscacheobjects with the query: <BR>&nbsp;&nbsp;&nbsp;&nbsp; </EM><EM>SELECT usecounts as uses, sql FROM sys.syscacheobjects WHERE dbid = db_id('AdventureWorks'); </EM>
<P><EM>It shows that the non-prepared query plan is reused with count equal to 2.</EM>
<BLOCKQUOTE>
<P>A: Althought it is possible to create a plan guide for an adhoc (non-prepared) query, your @stmt parameter must be absolutely exactly the same as the query you will run. In your plan guide creation, you have an extra space in front of the SELECT, and your @module_or_batch parameter is incorrect; it should be NULL. A correct plan guide can be used for adhoc queries, but it will NOT remove the adhoc plan from cache when you drop the plan guide, like a plan guide for a prepared query will. You will have to wait for the next version (SQL Server 2008) to get that behavior.</P></BLOCKQUOTE>
<P>I hope this helps!
<P><FONT color=#ff00ff>~Kalen</FONT></P>