3

I have a 64GB Windows Server 2019 Standard server in my TEST Server.

I have SQL Server 2019 CU9 Developer Edition and my the instance is consuming 21,199 MB as shown in sql_physical_memory_in_use_MB.

I have 4 user databases. Their sizes are approximately 5GB, 2GB, 400MB, and 200MB.

My tempdb is configured to be 8GB at instance start-up.

I'm trying to understand why my instance is using 21GB of memory. Just worried about a possible memory leak.

Can anyone calm my nerves?

SELECT
    (CASE WHEN ([database_id] = 32767) THEN 'Resource Database' ELSE DB_NAME (database_id) END) AS 'Database Name',
    SUM(CASE WHEN ([is_modified] = 1) THEN 1 ELSE 0 END) AS DirtyPageCount,
    SUM(CASE WHEN ([is_modified] = 1) THEN 0 ELSE 1 END) AS CleanPageCount,
    count(*)AS TotalPageCount,
    cast(count(*) * 8192.0 / (1024.0 * 1024.0) as decimal(8,2)) as BufferPoolMB
FROM sys.dm_os_buffer_descriptors
GROUP BY database_id
ORDER BY TotalPageCount desc
GO

OUTPUT

Database Name DirtyPageCount CleanPageCount TotalPageCount BufferPoolMB
SFI_WMS 55 805665 805720 6294.69
tempdb 18648 210842 229490 1792.89
DBAtools 483 82035 82518 644.67
Resource Database 0 3896 3896 30.44
msdb 42 1898 1940 15.16
master 24 766 790 6.17
ReportServer 4 476 480 3.75
ReportServerTempDB 0 308 308 2.41
model 0 245 245 1.91
SELECT 
    physical_memory_in_use_kb/1024 AS sql_physical_memory_in_use_MB, 
    large_page_allocations_kb/1024 AS sql_large_page_allocations_MB, 
    locked_page_allocations_kb/1024 AS sql_locked_page_allocations_MB,
    virtual_address_space_reserved_kb/1024 AS sql_VAS_reserved_MB, 
    virtual_address_space_committed_kb/1024 AS sql_VAS_committed_MB, 
    virtual_address_space_available_kb/1024 AS sql_VAS_available_MB,
    page_fault_count AS sql_page_fault_count,
    memory_utilization_percentage AS sql_memory_utilization_percentage, 
    process_physical_memory_low AS sql_process_physical_memory_low, 
    process_virtual_memory_low AS sql_process_virtual_memory_low
FROM sys.dm_os_process_memory; 

OUTPUT

sql_physical_memory_in_use_MB sql_large_page_allocations_MB sql_locked_page_allocations_MB sql_VAS_reserved_MB sql_VAS_committed_MB sql_VAS_available_MB sql_page_fault_count sql_memory_utilization_percentage sql_process_physical_memory_low sql_process_virtual_memory_low
21199 0 0 124464 21461 134093263 9673913 100 0 0
SELECT c.value, c.value_in_use
FROM sys.configurations c WHERE c.[name] = 'max server memory (MB)';
value value_in_use
60288 60288
7
  • 1
    I disagree with the dupe closure and answer here. It seems unusual that SQL Server is using 21 GB of memory when there are only ~8 GB of user databases on the whole instance. I've voted to reopen the question. In the meantime, you could inspect what components are using all that RAM by querying sys.dm_os_memory_clerks (see this post for an example query). Commented Mar 9, 2021 at 13:26
  • OP has max memory set way above 21GB, I don't think this is unusual behavior at all (I originally VtC) Commented Mar 9, 2021 at 20:37
  • 1
    @LowlyDBA-JohnM Sure, but SQL Server doesn't just acquire memory for no reason. If OP loaded all of those tables into memory, there would be 8.5 GB. I think it's worth looking into why an additional 12.5 GB have been allocated. It's not like there has never been a leak patched before 😜 Commented Mar 9, 2021 at 20:53
  • 1
    @sherveyj - please take a quick look at how I formatted the output in my edit to your question, then add the output of DBCC MEMORYSTATUS; from your SQL Server using that style of formatting. It's interesting that your instance is consuming 4x the amount of memory required by just the buffer pool. Not unheard of, just interesting. The output from the DBCC command will show us exactly what is using memory.
    – Hannah Vernon
    Commented Mar 9, 2021 at 21:20
  • How does one cut/paste output in here that is large... it always exceeds the max size of the comment window?
    – sherveyj
    Commented Mar 10, 2021 at 14:50

2 Answers 2

2

Why is my SQL Server consuming so much memory?

You're looking at total process memory, and one particular consumer of memory. To drill down from total process memory and get a high-level allocation of SQL Server's memory use use sys.dm_os_memory_clerks, eg:

select type,name, (pages_kb + virtual_memory_committed_kb + awe_allocated_kb) / 1024. committed_mb
from sys.dm_os_memory_clerks 
order by committed_mb desc 

or the old-school

dbcc memorystatus

If you see large amounts of process memory (large_page_allocations_kb + locked_page_allocations_kb + virtual_address_space_committed_kb) that can't be accounted for by the memory clerks, see if you have any OleDb drivers for linked server loaded in-process. They allocate memory outside of the SQL Server memory managers.

The two biggest consumers of memory are the the buffer pool and the lock manager. Both of these will allocate memory and not release it unless the system is under memory pressure.

MEMORYCLERK_SQLBUFFERPOOL Client-Default        9801MB
OBJECTSTORE_LOCK_MANAGER  Lock Manager : Node 0 6929MB

So there's your answer. Since it's started SQL Server has at some point grown the buffer pool to 9GB and the lock manager memory to 7GB, which accounts for enough of your 21GB to indicate that you don't really have a problem.

See related: memory used by Locks

5
  • You're looking at total process memory, and one particular consumer of memory. He is actually not looking at one particular consumer but total physical memory which includes almost all consumptions. 2nd thing total server memory is not always equal to physical memory value returned by sys.dm_os_process_memory.
    – Shanky
    Commented Mar 10, 2021 at 10:04
  • type name committed_mb MEMORYCLERK_SQLBUFFERPOOL Client-Default 9801.425781 OBJECTSTORE_LOCK_MANAGER Lock Manager : Node 0 6929.070312 CACHESTORE_SQLCP SQL Plans 186.539062 MEMORYCLERK_SQLSTORENG Client-Default 76.687500 MEMORYCLERK_QUERYDISKSTORE_HASHMAP Client-Default 76.078125 MEMORYCLERK_SOSMEMMANAGER SOSMemoryManager 72.765625 MEMORYCLERK_SOSNODE SOS_Node 66.367187 CACHESTORE_PHDR Bound Trees 42.132812 MEMORYCLERK_SQLCLR Client-Default 28.500000 USERSTORE_SCHEMAMGR SchemaMgr Store 19.195312
    – sherveyj
    Commented Mar 10, 2021 at 14:42
  • dbcc memorystatus; Process/System Counts Value Available Physical Memory 39426875392 Available Virtual Memory 140606952742912 Available Paging File 107816660992 Working Set 22408749056 Percent of Committed Memory in WS 100 Page Faults 10797460 System physical memory high 1 System physical memory low 0 Process physical memory low 0 Process virtual memory low 0
    – sherveyj
    Commented Mar 10, 2021 at 14:45
  • @sherveyj I told you that you do not have problem but few peoples had other wrong thought. IF possible restart SQL Server, since this is DEV. and you would start seeing things normal again.
    – Shanky
    Commented Mar 11, 2021 at 9:50
  • Yup I can restart. Left it untouched in case other queries needed to be run and curious if it will grow any larger - it kind of seems to have leveled off. After the particular DB is initially loaded from data formally from Oracle. I will add this DB to an AG and it will be part of a 2 node WFC.
    – sherveyj
    Commented Mar 12, 2021 at 17:29
0

I'm just worried why my instance size is 21GB. Just worried about a memory leak. Can anyone calm my nerves?

Calm down, this is NOT a memory leak. You might have either set max server memory somewhere around 21 GB or might have not set it all and SQL Server would have used 21 GB (which is lot less likely). Please also note once SQL Serve uses a memory portion it will not release unless it sees need of that memory by some other process or low memory notification is flagged by SQL resource monitor. This is how SQL Server memory code is written. You have 5.5 GB of total data and almost 4 times the memory at some point of time your all data will be in memory and SQL Server will not release memory as reading from memory is much much faster than that from disk.

Read Memory Management Architecture Guide

2
  • Yeah - This is a 64GB memory server in TEST. I have max mem for SQL Server set at 58GB. Just was wondering why its so bloaty in size and my data was much smaller. I also dont have memory optimized TEMPDB enabled. Were going to be live with 2019 CU9 in production in maybe a month or so using AG's.
    – sherveyj
    Commented Mar 8, 2021 at 17:08
  • 1
    If you have set max server memory to 58GB and as per sys.dm_os_process_memory output it is using 21GB, this is totally normal so relax. If you go on production my advice would be to lower max server memory a bit to 57 GB and give OS and other components a total of 7 GB. Please keep monitoring the memory via counters.
    – Shanky
    Commented Mar 9, 2021 at 8:25

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.