Quantcast
Channel: CodeSection,代码区,SQL Server(mssql)数据库 技术分享 - CodeSec
Viewing all articles
Browse latest Browse all 3160

SQL Server Target vs Total Memory

$
0
0

For this blog post I want to discuss the meaning behind SQL Server: Memory Manager\Target Server Memory (KB) and SQL Server: Memory Manager \Total memory (KB) Perfmon counters. I will mention how under different situations and configuration settings their behaviour changes.

Target Server Memory (KB) is the amount of memory that SQL Server is willing (potential) to allocate to the buffer pool under its current load. Total Server Memory (KB) is what SQL currently has allocated.

Using SQL Server 2014 developer edition (64 bit) my machine has 12GB RAM and maximum server memory is currently set to 8GB and for the purpose of this post I have set minimum server memory to 1GB (Lock Pages in Memory has not been set).


SQL Server Target vs Total Memory

I set minimum to 1GB to dispel a myth, that SQL Server doesn’t allocate this value at start-up. Just before 08:17:44 the instance was restarted and the time after that the value is still below the 1GB setting (see blue line). Once it goes beyond the 1GB value it will not release memory below that value.


SQL Server Target vs Total Memory

Currently SQL Server is consuming slightly less than 4GB.

Relating this to Perfmon Total server memory is the blue line (currently allocated) and Target server memory is the pink line (SQL’s potential for allocation).

So Perfmon looks like the following.


SQL Server Target vs Total Memory

So what happens if I change the max server setting down to 6GB? The Target Server Memory counter drops to 6GB (Pink line). As you can see via the red circle it happens.


SQL Server Target vs Total Memory

So what happens if I start using SQL Server more actively ? I will see the blue line move closer to the pink line.


SQL Server Target vs Total Memory

Below shows what Perfmon looks like an hour later.


SQL Server Target vs Total Memory

I am now going to set a bad configuration for Max Server memory setting.


SQL Server Target vs Total Memory

SQL adjusts to this request where you can see a big dip in both target and total memory.


SQL Server Target vs Total Memory

I am going to make things even worse and allocate less than 1GB for the max server memory setting and let normal activity resume. Checking the resource monitor ring buffer we can see that RESOURCE_MEMPHYSICAL_LOW notifications have been generated, this is a form of memory pressure.


SQL Server Target vs Total Memory

Setting the Max memory value back to an acceptable value (8GB) you will see the Perfmon counters respond to the change by trying to grow.


SQL Server Target vs Total Memory

After general usage takes place the total and target memory counters look like as shown below.


SQL Server Target vs Total Memory

I will now reset the memory settings as shown below.


SQL Server Target vs Total Memory

Next I created external pressure by activating heavy memory consuming applications on the SQL Server look at the Total server memory (and target) respond. It gets trimmed to its Min. Server setting of 1GB (black arrow).


SQL Server Target vs Total Memory

Re-checking the resource monitor ring buffer you will see more RESOURCE_MEMPHYSICAL_LOW notifications but this time system wide (IndicatorsSystem = 2).


SQL Server Target vs Total Memory

Once I stop the processes causing the external pressure the total server memory becomes the Low memory setting (1GB), this will change once SQL Serverbecomes actively used.


SQL Server Target vs Total Memory

So some activity takes place the blue line adjusts accordingly and goes beyond the 1GB setting.


SQL Server Target vs Total Memory

After couple more minutes of activity the end picture looks similar to our starting point.


SQL Server Target vs Total Memory

Hopefully this article has made it clearer about what Target and Total Perfmon counters are and how they respond to different situations and settings.

Thanks to Gail Shaw for the technical review


Viewing all articles
Browse latest Browse all 3160