Skip to content

Commit 8a5d005

Browse files
committed
#1092 sp_BlitzFirst warn on low target memory
If max server memory > 1.5 * target memory, either max memory is too high, or the server is under external memory pressure. Closes #1092.
1 parent 24ed9d4 commit 8a5d005

File tree

2 files changed

+37
-0
lines changed

2 files changed

+37
-0
lines changed

Documentation/sp_BlitzFirst Checks by Priority.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ If you want to change anything about a check - the priority, finding, URL, or ID
1919
| 1 | SQL Server Internal Maintenance | Log File Growing | https://BrentOzar.com/go/logsize | 13 |
2020
| 1 | SQL Server Internal Maintenance | Log File Shrinking | https://BrentOzar.com/go/logsize | 14 |
2121
| 10 | Server Performance | Poison Wait Detected | https://BrentOzar.com/go/poison | 30 |
22+
| 10 | Server Performance | Target Memory Lower Than Max | https://BrentOzar.com/go/target | 35 |
2223
| 40 | Table Problems | Forwarded Fetches/Sec High | https://BrentOzar.com/go/fetch | 29 |
2324
| 50 | In-Memory OLTP | Garbage Collection in Progress | https://BrentOzar.com/go/garbage | 31 |
2425
| 50 | Query Problems | Compilations/Sec High | https://BrentOzar.com/go/compile | 15 |
@@ -29,6 +30,7 @@ If you want to change anything about a check - the priority, finding, URL, or ID
2930
| 50 | Server Performance | Page Life Expectancy Low | https://BrentOzar.com/go/ple | 10 |
3031
| 50 | Server Performance | Slow Data File Reads | https://BrentOzar.com/go/slow | 11 |
3132
| 50 | Server Performance | Slow Log File Writes | https://BrentOzar.com/go/slow | 12 |
33+
| 50 | Server Performance | Too Much Free Memory | https://BrentOzar.com/go/freememory | 34 |
3234
| 100 | In-Memory OLTP | Transactions aborted | https://BrentOzar.com/go/aborted | 32 |
3335
| 100 | Query Problems | Suboptimal Plans/Sec High | https://BrentOzar.com/go/suboptimal | 33 |
3436
| 200 | Wait Stats | (One per wait type) | https://BrentOzar.com/sql/wait-stats/#(waittype) | 6 |

sp_BlitzFirst.sql

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -933,6 +933,41 @@ BEGIN
933933
AND counter_name LIKE 'Page life expectancy%'
934934
AND cntr_value < 300
935935

936+
/* Server Performance - Too Much Free Memory - CheckID 34 */
937+
INSERT INTO #BlitzFirstResults (CheckID, Priority, FindingsGroup, Finding, URL, Details, HowToStopIt)
938+
SELECT 34 AS CheckID,
939+
50 AS Priority,
940+
'Server Performance' AS FindingGroup,
941+
'Too Much Free Memory' AS Finding,
942+
'https://BrentOzar.com/go/freememory' AS URL,
943+
CAST((CAST(cFree.cntr_value AS BIGINT) / 1024 / 1024 ) AS NVARCHAR(100)) + N'GB of free memory inside SQL Server''s buffer pool,' + @LineFeed + ' which is ' + CAST((CAST(cTotal.cntr_value AS BIGINT) / 1024 / 1024) AS NVARCHAR(100)) + N'GB. You would think lots of free memory would be good, but check out the URL for more information.' AS Details,
944+
'Run sp_BlitzCache @SortOrder = ''memory grant'' to find queries with huge memory grants and tune them.' AS HowToStopIt
945+
FROM sys.dm_os_performance_counters cFree
946+
INNER JOIN sys.dm_os_performance_counters cTotal ON cTotal.object_name LIKE N'%Memory Manager%'
947+
AND cTotal.counter_name = N'Total Server Memory (KB) '
948+
WHERE cFree.object_name LIKE N'%Memory Manager%'
949+
AND cFree.counter_name = N'Free Memory (KB) '
950+
AND CAST(cTotal.cntr_value AS BIGINT) > 20480000000
951+
AND CAST(cTotal.cntr_value AS BIGINT) * .3 <= CAST(cFree.cntr_value AS BIGINT)
952+
AND CAST(SERVERPROPERTY('edition') AS VARCHAR(100)) NOT LIKE '%Standard%';
953+
954+
/* Server Performance - Target Memory Lower Than Max - CheckID 35 */
955+
INSERT INTO #BlitzFirstResults (CheckID, Priority, FindingsGroup, Finding, URL, Details, HowToStopIt)
956+
SELECT 35 AS CheckID,
957+
10 AS Priority,
958+
'Server Performance' AS FindingGroup,
959+
'Target Memory Lower Than Max' AS Finding,
960+
'https://BrentOzar.com/go/target' AS URL,
961+
N'Max server memory is ' + CAST(cMax.value_in_use AS NVARCHAR(50)) + N' MB but target server memory is only ' + CAST((CAST(cTarget.cntr_value AS BIGINT) / 1024) AS NVARCHAR(50)) + N' MB,' + @LineFeed
962+
+ N'indicating that SQL Server may be under external memory pressure or max server memory may be set too high.' AS Details,
963+
'Investigate what OS processes are using memory, and double-check the max server memory setting.' AS HowToStopIt
964+
FROM sys.configurations cMax
965+
INNER JOIN sys.dm_os_performance_counters cTarget ON cTarget.object_name LIKE N'%Memory Manager%'
966+
AND cTarget.counter_name = N'Target Server Memory (KB) '
967+
WHERE cMax.name = 'max server memory (MB)'
968+
AND CAST(cMax.value_in_use AS BIGINT) >= 1.5 * (CAST(cTarget.cntr_value AS BIGINT) / 1024)
969+
AND CAST(cMax.value_in_use AS BIGINT) < 2147483647; /* Not set to default of unlimited */
970+
936971
/* Server Info - Database Size, Total GB - CheckID 21 */
937972
INSERT INTO #BlitzFirstResults (CheckID, Priority, FindingsGroup, Finding, Details, DetailsInt, URL)
938973
SELECT 21 AS CheckID,

0 commit comments

Comments
 (0)