(Republishing, or using this info in a commercial product/website, is prohibited without permission. All other uses are permitted. If in doubt, please ask.)
This wait type is when a thread is waiting for access to a critical section of code around a thread-safe memory object (called CMemThread objects internally) so it can allocate or deallocate memory.
(Books Online description: “Occurs when a task is waiting on a thread-safe memory object. The wait time might increase when there is contention caused by multiple tasks trying to allocate memory from the same memory object.”)
Questions/comments on this wait type? Click here to send Paul an email, especially if you have any information to add to this topic.
Added in SQL Server version:
Removed in SQL Server version:
Extended Events wait_type value:
The map_key value in sys.dm_xe_map_values is 186 in 2008 and 2008 R2, and 190 in 2012 and 2014 RTM. After 2014 RTM, you must check the DMV to get the latest value as some map_key values have changed in later builds.
If this wait type is prevalent, that indicates that a memory object in SQL Server is a contention point. Unfortunately, it is hard to tell which memory object is the contention point without capturing SQL Server call stacks to figure out where most of the CMEMTHREAD waits are occurring.
There is a good CSS post about CMEMTHREAD waits and debugging them here, which explains how the trace flag 8048 may help alleviate the issue if the memory object is one that is currently partitioned by NUMA node. My blog post on collecting SQL Server call stacks for a particular wait type is here.
Note that there have been various bug fixes involving CMEMTHREAD waits over the years, including:
- 3074425, from large number of ad hoc queries on 2012 and 2014
- 2887888, from building large spatial indexes on 2012 and 2014
- 2492381, from using temp tables/variables to load or update rowsets on 2008 R2
- Here, where servers with more than 8 cores per NUMA node may require trace flag 8048
Note also that in SQL Server 2016, CMemThread objects will dynamically be promoted to per-NUMA node or per-CPU when contention is detected (i.e. a superset of the TF 8048 behavior). This should mean that CMEMTHREAD waits become less of an issue on SQL Server 2016. See this blog post for more details.
Additional: I’ve heard of information online that states other reasons for CMEMTHREAD waits occurring, including plan cache lookups on busy systems, or searching through database metadata. These explanations are unfortunately incorrect.
Known occurrences in SQL Server (list number matches call stack list):
- Allocating memory (in this case, to instantiate a data record in memory during the fact generation phase of DBCC CHECKDB)
- Allocating memory (in this case, while building a sort table during a stream aggregate)
- Allocating memory (in this case, to hold the Storage Engine metadata for a temporary sort table during a top-N query)
- Freeing memory (in this case, removing an SSPI entry while closing a client connection)
And many, many more similar call stacks.
Abbreviated call stacks (list number matches known occurrences list):