Reading Memory Clerks to See Where Memory Goes

SQL Server takes memory and keeps it, so a full memory graph tells you very little. Memory clerks show where that memory actually went. A large number in one clerk is a clue, not a diagnosis. Compare it with the instance’s normal baseline and the workload running at the same time.

An open kitchen drawer with wooden compartments, one overflowing with tangled string while others hold cutlery.

What Memory Clerks Represent

Memory clerks account for allocations made by SQL Server components. A clerk type can have multiple rows, including rows associated with different memory nodes. The DMV exposes pages_kb and other allocation measures. It helps answer where engine-managed memory is going, but it does not include every possible consumer inside or outside the SQL Server process.

I use clerk totals as a map, then investigate a component with other views. A large buffer-pool-related clerk is expected on a database server that caches data. An unusual change in a query reservation clerk during a report surge has a different meaning. Context makes the number useful.

Aggregate by Clerk Type

Summing pages_kb by type gives a readable first view. The query below reports megabytes and ranks the largest types. It covers memory accounted through those pages, not an exact reconciliation to every byte of process memory. Run it during normal and problematic periods to compare patterns.

Keep the collection timestamp, max server memory setting, and workload note beside the result. A single list of top memory clerks cannot tell whether the server is under pressure. SQL Server is designed to use memory when available. High use alone is not a fault.

SELECT type,
       SUM(pages_kb) / 1024.0 AS pages_mb,
       COUNT(*) AS clerk_rows
FROM sys.dm_os_memory_clerks
GROUP BY type
ORDER BY pages_mb DESC;

Recognize Common Categories

MEMORYCLERK_SQLBUFFERPOOL relates to cached data pages and is commonly large. CACHESTORE_SQLCP and CACHESTORE_OBJCP are associated with plan caches. MEMORYCLERK_SQLQERESERVATIONS is relevant to query memory grants. OBJECTSTORE_LOCK_MANAGER can grow when many locks are held. Names and accounting details can change by version, so use current documentation for a specific investigation.

Do not treat a high plan cache as waste without checking plan reuse and pressure. Similarly, a high query reservation figure during a large report can be normal for that interval. I compare trends and user symptoms before clearing caches or changing memory settings. A cache reset is a blunt diagnostic tool with production side effects.

Look for Memory Clerks Growing Over Time

Take periodic snapshots and compare the same clerk types across a baseline, peak, and incident window. A clerk that grows steadily without returning after workload completion deserves attention. A clerk that rises during a batch and then falls can reflect expected activity. Include SQL Server restart time so a fresh instance is not compared with a long-running one as if the counters had identical history.

The query shows a focused view of several categories, but real investigations should retain the full set. Do not make a production decision from a filtered list alone.

SELECT type, memory_node_id,
       pages_kb / 1024.0 AS pages_mb,
       virtual_memory_committed_kb / 1024.0
           AS virtual_committed_mb
FROM sys.dm_os_memory_clerks
WHERE type IN ('MEMORYCLERK_SQLBUFFERPOOL',
               'MEMORYCLERK_SQLQERESERVATIONS',
               'OBJECTSTORE_LOCK_MANAGER')
ORDER BY type, memory_node_id;
Reading clerks over time: a diagram about the memory clerks

Connect Grants to Queries

If query reservation memory is prominent and users report RESOURCE_SEMAPHORE waits, inspect active and waiting memory grants. Large grants can come from sorts, hashes, and inaccurate row estimates. An index or statistics correction can reduce the grant more effectively than adding RAM. The memory clerk tells you the category. Query-level views identify the requests.

I examine plan estimates and actual rows for the queries holding grants. A single report can reserve far more memory than it uses, limiting concurrency. Conversely, a grant that is too small can spill to tempdb. The objective is enough memory for useful work, shared fairly among concurrent requests.

Check External Pressure Too

The Windows host and other processes can pressure SQL Server even when no clerk looks abnormal. Antivirus, backup agents, another instance, or VM memory policy can affect available memory. Check process physical memory, operating system available memory, paging, and SQL target versus total memory. A clerk inventory is one layer of the explanation.

When the SQL process is unexpectedly large but clerk totals do not explain it, investigate non-engine allocations and loaded components. Microsoft diagnostic guidance distinguishes internal engine pressure from external pressure. I do not force all memory into the top clerk simply because its name is easiest to find.

Avoid Knee-Jerk Cache Clearing

DBCC FREEPROCCACHE or buffer clearing can make a graph drop, but it also evicts useful state and changes query behavior. It is not a safe general treatment for a high memory clerk. The cache can simply regrow as normal traffic resumes. Such commands require a controlled diagnostic purpose and an understanding of production impact.

I first identify the owning workload and whether memory pressure exists. A healthy instance can keep memory allocated for performance. The question is whether requests are waiting, Windows is paging, or SQL cannot meet its target. Only then does the clerk distribution guide a remedy.

Relate Memory to max server memory

max server memory is a ceiling for SQL Server memory manager allocations, not a promise that every byte of the process stays below it in all circumstances. Leave room for Windows and other processes. Review the current setting with actual host capacity and workload. Changing the ceiling without understanding the pressure can move the problem rather than solve it.

Compare clerk trends with total and target memory and with resource waits. I prefer one coordinated evidence set to separate screenshots from different hours. The numbers gain meaning when they share a timestamp and a workload description.

Turn a Spike in Memory Clerks Into a Test

Form a specific hypothesis: which clerk grew, what query or process ran, what symptom appeared, and what change should reduce it? Test that change in a representative workload and measure the same clerk plus user-facing latency. A lower clerk total is not success if queries now spill or read from disk more.

Memory clerks are a navigation tool for memory investigation. They show where to look next, while plans, grants, host counters, and workload timing explain why. A database server using its memory is doing its job. Trouble begins when useful work cannot get the memory it needs.

Related reading on this blog: Why 'Max Server Memory' Isn’t Always the Limit and Queries Waiting for Memory Grant: Performance Tuning.

Four clerk names worth knowing: a checklist on the memory clerks

A memory clerk is not a verdict on memory health, it is a map to the component worth investigating.

Published by Pinal Dave on SQLAuthority. More of my work at pinaldave.com.

SQL Cache, SQL DMV, SQL Memory, SQL Server
Previous Post
SQL SERVER – Time Out Due to Executing DELETE on Large RecordSet
Next Post
SQL SERVER – 2005 – Find Unused Indexes of Current Database

Related Posts

2 Comments. Leave new

Leave a Reply

Your email address will not be published. Required fields are marked *

Fill out this field
Fill out this field
Please enter a valid email address.