Asked by:
what's actually CMEMTHREAD

Question
-
https://www.sqlskills.com/help/waits/cmemthread/
what's actually "TREAD-safe-memory-object" ?
Tuesday, August 11, 2020 8:38 AM
All replies
-
Thread safe is a flag which is put on memory object saying this can be accessed by more than one thread at a time. I would suggest you read below blog for the explanation
Why CMEMTHREAD Wait Type Occurs?
Quoting
MEMOBJ
acts like aHEAP
in SQL Server engine, so SQL Server callsCreateMemoryObject
function instead ofHeapCreate
, which is managed by SQL Server Memory Manager.CMEMOBJ
is responsible to handle any kind of activity in SQL Server such asAlloc
,Free
,ReAlloc
,Size
andValidate
. Remember thatCMEMOBJ
is also not thread safe, therefore only one thread can access it at same time, it is similar toHEAP_NO_SERIALIZE
in Windows.CMEMTHREAD
acts like a serializer aroundCMEMOBJ
, the SQL Server creates a memory object with a thread safe flag andCreateMemoryObject
will return a pointer toCMEMTHREAD
instead of theCMEMOBJ
. By overriding some underling Windows methods, SQL Server is able to share a memory object among any thread and make it thread safe object.Cheers,
Shashank
Please mark this reply as answer if it solved your issue or vote as helpful if it helped so that other forum members can benefit from it
My TechNet Wiki Articles
MVPTuesday, August 11, 2020 11:45 AM -
Hi sakurai_db,
In addition, please refer to How It Works: CMemThread and Debugging Them and Dynamic Memory Object Scaling which might help.
Best Regards,
Amelia
""SQL Server related"" forum will be migrated to a new home on Microsoft Q&A SQL Server!
We invite you to post new questions in the "SQL Server related" forum’s new home on Microsoft Q&A SQL Server !
For more information, please refer to the sticky post.Wednesday, August 12, 2020 6:50 AM -
Hi sakurai_db,
Did the answers above help you?
Please feel free to let us know if you have any other question.
If you find any post in the thread is helpful, you could kindly mark it as answer. This would benefit the community, and encourage the community member to keep working on your issues.
Best Regards,
Amelia
""SQL Server related"" forum will be migrated to a new home on Microsoft Q&A SQL Server!
We invite you to post new questions in the "SQL Server related" forum’s new home on Microsoft Q&A SQL Server !
For more information, please refer to the sticky post.Friday, August 14, 2020 9:01 AM -
I have got the screen from
https://bobsql.com/sql-2016-it-just-runs-faster-dynamic-memory-object-cmemthread-partitioning/
- Proposed as answer by Amelia GuMicrosoft contingent staff Wednesday, August 26, 2020 9:17 AM
Tuesday, August 25, 2020 9:54 AM -
Hi,
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.”)
Many Thanks & Best Regards, Jackson Chen
Wednesday, August 26, 2020 5:05 AM -
any real example for the thread-safe object ?Friday, August 28, 2020 8:34 AM
-
Friday, August 28, 2020 8:53 AM
-
Hi,
Read this
Many Thanks & Best Regards, Jackson Chen
Friday, August 28, 2020 5:23 PM