diff --git a/be/src/runtime/memory/global_memory_arbitrator.cpp b/be/src/runtime/memory/global_memory_arbitrator.cpp index 344bcbc59846d9c..818424bab1fa1aa 100644 --- a/be/src/runtime/memory/global_memory_arbitrator.cpp +++ b/be/src/runtime/memory/global_memory_arbitrator.cpp @@ -79,4 +79,8 @@ void GlobalMemoryArbitrator::release_process_reserved_memory(int64_t bytes) { } } +int64_t GlobalMemoryArbitrator::sub_thread_reserve_memory(int64_t bytes) { + return bytes - doris::thread_context()->thread_mem_tracker_mgr->reserved_mem(); +} + } // namespace doris diff --git a/be/src/runtime/memory/global_memory_arbitrator.h b/be/src/runtime/memory/global_memory_arbitrator.h index f8fda18d0e9a0c3..597269b8e36f5f1 100644 --- a/be/src/runtime/memory/global_memory_arbitrator.h +++ b/be/src/runtime/memory/global_memory_arbitrator.h @@ -124,12 +124,22 @@ class GlobalMemoryArbitrator { return _s_process_reserved_memory.load(std::memory_order_relaxed); } + static int64_t sub_thread_reserve_memory(int64_t bytes); + static bool is_exceed_soft_mem_limit(int64_t bytes = 0) { + bytes = sub_thread_reserve_memory(bytes); + if (bytes <= 0) { + return false; + } return process_memory_usage() + bytes >= MemInfo::soft_mem_limit() || sys_mem_available() - bytes < MemInfo::sys_mem_available_warning_water_mark(); } static bool is_exceed_hard_mem_limit(int64_t bytes = 0) { + bytes = sub_thread_reserve_memory(bytes); + if (bytes <= 0) { + return false; + } // Limit process memory usage using the actual physical memory of the process in `/proc/self/status`. // This is independent of the consumption value of the mem tracker, which counts the virtual memory // of the process malloc.