diff --git a/be/src/runtime/memory/mem_tracker_limiter.cpp b/be/src/runtime/memory/mem_tracker_limiter.cpp index cc4218d7653802..e65dea61394a4d 100644 --- a/be/src/runtime/memory/mem_tracker_limiter.cpp +++ b/be/src/runtime/memory/mem_tracker_limiter.cpp @@ -88,6 +88,8 @@ std::shared_ptr MemTrackerLimiter::create_shared(MemTrackerLi auto tracker = std::make_shared(type, label, byte_limit); // Write tracker is only used to tracker the size, so limit == -1 auto write_tracker = std::make_shared(type, "Memtable" + label, -1); + // Memtable has a separate logic to deal with memory flush, so that should not check the limit in memtracker. + write_tracker->set_enable_reserve_memory(true); tracker->_write_tracker.swap(write_tracker); #ifndef BE_TEST DCHECK(ExecEnv::tracking_memory()); diff --git a/be/src/runtime/memory/mem_tracker_limiter.h b/be/src/runtime/memory/mem_tracker_limiter.h index 727e5b1ff40d7b..8c67cc6197ac15 100644 --- a/be/src/runtime/memory/mem_tracker_limiter.h +++ b/be/src/runtime/memory/mem_tracker_limiter.h @@ -381,7 +381,11 @@ inline Status MemTrackerLimiter::check_limit(int64_t bytes) { return Status::OK(); } - // check limit should ignore memtable size, because it is treated as a cache + // If reserve not enabled, then should check limit here to kill the query when limit exceed. + // For insert into select or pure load job, its memtable is accounted in a seperate memtracker limiter, + // and its reserve is set to true. So that it will not reach this logic. + // Only query and load job has exec_mem_limit and the _limit > 0, other memtracker limiter's _limit is -1 so + // it will not take effect. if (_limit > 0 && consumption() + bytes > _limit) { return Status::MemoryLimitExceeded(fmt::format("failed alloc size {}, {}", MemCounter::print_bytes(bytes),