This is an automated email from the ASF dual-hosted git repository. yiguolei pushed a commit to branch master in repository https://gitbox.apache.org/repos/asf/doris.git
The following commit(s) were added to refs/heads/master by this push: new bd6e3cf132 [improvement]lock_times_limit (#11404) bd6e3cf132 is described below commit bd6e3cf13277743d7f56ea779383cf94f7dac33d Author: muyizi <1661195...@qq.com> AuthorDate: Tue Aug 2 10:59:58 2022 +0800 [improvement]lock_times_limit (#11404) Co-authored-by: songning03 <songnin...@meituan.com> --- be/src/runtime/memory/chunk_allocator.cpp | 25 ++++++++++++++++++------- 1 file changed, 18 insertions(+), 7 deletions(-) diff --git a/be/src/runtime/memory/chunk_allocator.cpp b/be/src/runtime/memory/chunk_allocator.cpp index e69b4c2e82..00223cc714 100644 --- a/be/src/runtime/memory/chunk_allocator.cpp +++ b/be/src/runtime/memory/chunk_allocator.cpp @@ -67,6 +67,8 @@ ChunkAllocator* ChunkAllocator::instance() { // Keep free chunk's ptr in size separated free list. // This class is thread-safe. class ChunkArena { + int TRY_LOCK_TIMES = 3; + public: ChunkArena() : _chunk_lists(64) {} @@ -86,14 +88,23 @@ public: int idx = BitUtil::Log2Ceiling64(size); auto& free_list = _chunk_lists[idx]; - std::lock_guard<SpinLock> l(_lock); - if (free_list.empty()) { - return false; + if (free_list.empty()) return false; + + for (int i = 0; i < TRY_LOCK_TIMES; ++i) { + if (_lock.try_lock()) { + if (free_list.empty()) { + _lock.unlock(); + return false; + } else { + *ptr = free_list.back(); + free_list.pop_back(); + ASAN_UNPOISON_MEMORY_REGION(*ptr, size); + _lock.unlock(); + return true; + } + } } - *ptr = free_list.back(); - free_list.pop_back(); - ASAN_UNPOISON_MEMORY_REGION(*ptr, size); - return true; + return false; } void push_free_chunk(uint8_t* ptr, size_t size) { --------------------------------------------------------------------- To unsubscribe, e-mail: commits-unsubscr...@doris.apache.org For additional commands, e-mail: commits-h...@doris.apache.org