CMEMTHREAD Wait Type in SQL Server

⏳Part of the SQL Server Wait Types Library, every wait type explained.Related deep dive: RESOURCE_SEMAPHORERelated pillar: Performance & Troubleshooting
⚡CMEMTHREAD is a task waiting for a thread-safe memory object, because many tasks are allocating from the same one at once. Small amounts are normal. Sustained at the top of your waits, one memory object has become a serialisation point. Run the check to find which object, then match it to the workload driving it.

Microsoft’s definition: a task waiting on a thread-safe memory object, with the wait time rising when several tasks try to allocate memory from the same object. It is a wait for a section of code around the memory object, internally a CMemThread object, so a thread can allocate or free memory. Working out which object is contended has traditionally needed call stacks. From SQL Server 2016, sys.dm_os_memory_objects shows waiters per memory object, which gets you most of the way.


Is It a Problem?

A little is normal on busy systems. It becomes actionable when it climbs into the top waits and stays there under steady load. On our SQL Server 2025 lab it had about 11,900 waits averaging over 100 ms, a reminder that the average can be high even when the count is modest; read both. Get Wait Statistics does not filter it out, so if it ranks, you will see it.

Judge it over an interval rather than the cumulative totals. The baseline to monitor is its share of wait time per interval, with the top memory objects from the check.


Common Causes

  • Large numbers of ad hoc queries compiling at once; there is a fix for this on SQL Server 2012 and 2014 (Microsoft’s fix article KB3074425).
  • A memory object partitioned only by NUMA node on a server with many cores per node, where per-CPU partitioning would spread the load.
  • Many sessions running the same hot code path at once.

The Check To Run

Rank it against everything else with Get Wait Statistics. Then find the memory objects with the most waiters:

SELECT TOP (10)
    type,
    partition_type_desc,
    contention_factor,
    waiting_tasks_count,
    exclusive_access_count,
    pages_in_bytes / 1048576 AS size_mb
FROM sys.dm_os_memory_objects
ORDER BY waiting_tasks_count DESC;

The object at the top with a rising contention_factor is the lead, and its type usually names the subsystem, such as the plan cache or metadata. partition_type_desc shows whether it is already partitioned. The query needs VIEW SERVER STATE.


What To Do

  1. If the hot object relates to compilation, reduce ad hoc churn: parameterise the common patterns so plans are reused.
  2. Check the build. There have been several CMEMTHREAD fixes over the years, so patch before tuning.
  3. On SQL Server 2012 and earlier, trace flag 8048 moved NUMA-partitioned objects to per-CPU partitions. From SQL Server 2014 SP2 and 2016 this is dynamic and handled by the engine, so the flag is not needed on current versions.
  4. Re-measure after each change, comparing wait share over intervals rather than one snapshot.

The MEMORY Family

These are the memory object and allocation waits: threads queuing for a thread-safe memory object, and preemptive switches while memory is allocated. For memory grant queues, see RESOURCE_SEMAPHORE; otherwise start from the waits that usually matter.

  • CMEMTHREADMemory object contention. Waiting on a thread-safe memory object that many tasks allocate from at once.Worth a look when it climbs. This page.
  • CMEMPARTITIONEDPartitioned memory object. Documented as internal use only; the partitioned counterpart of CMEMTHREAD.Usually noise
  • MEMORY_ALLOCATION_EXTAllocations. Allocating memory from the internal pool or the operating system.Usually noise
  • RESERVED_MEMORY_ALLOCATION_EXTGranted memory. Allocating memory already reserved for a query by its grant.Usually noise

Where To Go Next

If CMEMTHREAD is sitting near the top of your wait stats, these are the next places to look.

Comments

Leave a Reply

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