From 6ac60a4ae42bd9f93da4fede537ee85abcbe8fbc Mon Sep 17 00:00:00 2001 From: Xinyi Zou Date: Wed, 7 Aug 2024 16:27:25 +0800 Subject: [PATCH] 6 --- be/src/vec/common/allocator.cpp | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/be/src/vec/common/allocator.cpp b/be/src/vec/common/allocator.cpp index d7ec122472f433d..75e31d1b50edc3e 100644 --- a/be/src/vec/common/allocator.cpp +++ b/be/src/vec/common/allocator.cpp @@ -215,6 +215,8 @@ void Allocator::memory_ template void Allocator::consume_memory( size_t size) { + // `alloc` requires that the current thread_mem_tracker label is not `Orphan` + // and is the same as the thread_mem_tracker label when Allocator is constructed. DCHECK(doris::thread_context()->thread_mem_tracker()->label() == tracker->label()) << ", thread mem tracker label: " << doris::thread_context()->thread_mem_tracker()->label() @@ -225,6 +227,12 @@ void Allocator::consume template void Allocator::release_memory( size_t size) const { + // If thread_context does not exist or the label of thread_mem_tracker is `Orphan, + // it usually happens during object destruction. This means that the scope of SCOPED_ATTACH_TASK has been left, + // thread_mem_tracker is not set, and reserved memory does not exist, + // so Allocator tracker can be used directly to release memory. + // Otherwise, thread_mem_tracker should be used to release memory, which will do some additional operations, + // such as modifying reserved memory. doris::ThreadContext* thread_context = doris::thread_context(true); if (thread_context && thread_context->thread_mem_tracker()->label() != "Orphan") { DCHECK(thread_context->thread_mem_tracker()->label() == tracker->label())