Of late, I'm observing that some of the customers are not setting up Max. Server Memory Properly or they never set Max. Server Memory at all in 64-bit SQL Server installations.
What will happen if I don't set Max. Server Memory?
Working Set trimming, Operating System unresponsiveness, Performance Problems in other applications running on the same server, Downgraded Backup Buffers etc...
How should I set Max. Server Memory?
sp_configure 'max server memory (MB)',<Memory in MB>
Is Max. Server Memory the upper limit to which SQL Server will consume Memory in the box?
No. Max. Server Memory just limits the memory consumed by SQL Server Buffer Pool. Memory consumed by Non-buffer pool portion of SQL Server and memory consumed by external dll's loaded into SQL Server memory space is not controlled using Max. Server Memory
How can I calculate the value for Max. Server Memory?
In general, you should calculate Max. Server Memory using the formula:
Max. Server Memory for a SQL Server Instance =
(Total RAM available to the OS) -
(Memory needed by Operating System which gets allocated to memory pool, filesystem cache, PTE, desktop heap, Driver Images etc...) +
(Memory needed by Non-buffer Pool region of SQL Server which gets allocated to Multi Page Allocators, Worker Threads, COM, Extended SPs, Backup Buffers, CLR, Linked Server...) +
Memory required for SQL Server Agent, Replication Agents, Bulk Copy, SSRS, SSAS, SSIS, and Full Text +
Memory required for Log shipping file copy depending on the size of log backups (if LS is configured) +
Memory required for other SQL Server instances running in the box +
Memory required for other applications running in the box (Antivirus, Monitoring Softwares, Compression softwares etc...)
I'm sure this is not a tough formula. Please note that stack size of SQL Server in x64 is 2 MB so depending on the amount of worker threads calculated by SQL Server (SELECT max_workers_count FROM sys.dm_os_sys_info) you may need to deduct memory in the above formula. Also if you have enabled -g startup parameter then you need to deduct the memory in the above formula accordingly. Make sure that you collect these memory requirements during the peak load.
I'm giving some scenarios explaining how to set Max. Server Memory here:
I have Active-Active SQL Server instances running on Node A and Node B. I have 65 GB of RAM in each Node A and Node B. I have set Max. Server Memory for both the instances InstA and InstB to 60 GB leaving 5 GB to operating systems. Is it a right configuration?
Imagine a situation where both the instances are running on same node due to some issues on the other node. So if both the instances are memory hungry then you will have the worst performance possible. So for a perfect configuration, you should have 125 GB RAM on each node so that at any point, there will be no memory bottleneck immaterial on which node both the instances are running. Atleast you should have physical memory more than sum of Min. Server Memory of both the instances.
I have 3 SQL Server instances running on box SQLSRVR. I have 65 GB of RAM in SQLSRVR. I have set Max. Server Memory on each of the three instances to 60 GB leaving 5 GB to operating systems. Is it a right configuration?
This setting means that all the three instances can grab upto 60 GB of memory and if that happens then all the three instances will be performing poorly. Refer to the formula above and set Max. Server Memory accordingly to all the three instances. If that is something not possible, atleast you should have physical memory on the box which is more than sum of Min. Server Memory of all the instances.
Here is snippet out of a doc I prepared for a customer:
x86 - AWE
Set Max. Server Memory
sp_configure 'awe enabled'
Lock Pages in Memory
Optional(To use AWE API, Large Page Support)
What components within SQL Server use Memory from BPool?
Database Page CacheLog cachesProcedure/Plan cacheQuery WorkspaceLocksConnection context Optimizing queriesSystem-level data structures etc.,
Further Reads:Server Memory Options - http://msdn.microsoft.com/en-us/library/ms178067.aspx awe enabled Option - http://msdn.microsoft.com/en-us/library/ms190731.aspxEnabling Memory Support for Over 4 GB of Physical Memory - http://msdn.microsoft.com/en-us/library/ms179301.aspxUsing AWE and limitation of Memory which SQL Server 32-bit instance can access using AWE - http://msdn.microsoft.com/en-us/library/ms175581.aspxLock Pages in Memory ... do you really need it? - http://blogs.technet.com/b/askperf/archive/2008/03/25/lock-pages-in-memory-do-you-really-need-it.aspxWindows: Physical Memory - http://blogs.technet.com/b/markrussinovich/archive/2008/07/21/3092070.aspx
Sakthivel Chidambaram, SQL Server Support
thanks Shakti...:) was searching for this vkb would have not:)
I have SQL server 208 R2 installed on machine. Machine has 16 GB of RAM. SQL consumes around 14 GB of RAM causing other application on that machine to run slow. Is it because of log file of SQL? Whats the solution.
Check your "Available MBytes" counter to see whether your system is actually encountering Memory pressure.
"Other application run slow" could be because of many things.
For active active setup, if you consider doubling the RAM in order to consider failover situation, it is a poor design buddy. Wasting half of the memory at any given point of time is a stupid idea. I would suggest to implement some automation such as WMI script or startup script etc...
Response from Sakthi:
Thanks for the feedback. What if one node out of Active-Active cluster crashed and it takes 1 day to rebuild the system? Are you planning to run two mission critical instances in 1 node with same amount of RAM which is sufficient to handle one instance? Even in Active/Passive scenario, you always have a passive node which is idle with equivalent RAM.. Do you think A/P clustering itself is a stupid concept?
Silly question, how to run "sp_configure 'max server memory (MB)',<Memory in MB>" what tool do I use to do this? DOS command line doesn't recognize it as a legitimate program or command...
It's a T-SQL command Steve. You need to run this in SSMS or SQLCMD connected to the target SQL Server instance.
this is a joke right? I mean the simple formula comment: you couldn't even lfinish listing the elements here Memory needed by Non-buffer Pool region of SQL Server which gets allocated to Multi Page Allocators, Worker Threads, COM, Extended SPs, Backup Buffers, CLR, Linked Server...) let alone the formula or location for calculating each element, and then, you have to do the same process for each component. REally. Playing keep away with manageable facts to run a manageable system, unless of course you are a giant bureaucracy and all you have to to all day is look at these minutae: but that is the 2012 / 2013 generation of Microsoft "built by bureaucracies for bureaucracies"