wangbo commented on code in PR #19802: URL: https://github.com/apache/doris/pull/19802#discussion_r1198536864
########## be/src/util/mem_info.cpp: ########## @@ -215,6 +221,52 @@ bool MemInfo::process_full_gc() { return false; } +int64_t MemInfo::tg_hard_memory_limit_gc() { + std::vector<taskgroup::TaskGroupPtr> task_groups; + taskgroup::TaskGroupManager::instance()->get_resource_groups( + [](const taskgroup::TaskGroupPtr& task_group) { + return !task_group->enable_overcommit(); + }, + &task_groups); + + int64_t total_free_memory = 0; + for (const auto& task_group : task_groups) { + total_free_memory += task_group->memory_limit_gc(); + } + return total_free_memory; +} + +int64_t MemInfo::tg_soft_memory_limit_gc(int64_t request_free_memory) { + std::vector<taskgroup::TaskGroupPtr> task_groups; + taskgroup::TaskGroupManager::instance()->get_resource_groups( + [](const taskgroup::TaskGroupPtr& task_group) { + return task_group->enable_overcommit(); + }, + &task_groups); + + int64_t total_exceeded_memory = 0; + std::vector<int64_t> used_memorys; + std::vector<int64_t> exceeded_memorys; + for (const auto& task_group : task_groups) { + auto used_memory = task_group->memory_used(); + auto exceeded = used_memory - task_group->memory_limit(); + auto exceeded_memory = exceeded > 0 ? exceeded : 0; + total_exceeded_memory += exceeded_memory; + used_memorys.emplace_back(used_memory); + exceeded_memorys.emplace_back(exceeded_memory); + } + + int64_t total_free_memory = 0; + for (int i = 0; i < task_groups.size(); ++i) { + // Use resource group exceeded memory as a weight + int64_t tg_need_free_memory = static_cast<double>(exceeded_memorys[i]) / Review Comment: or maybe: if total_exceeded_memory > request_free_memory this means just release some groups is ok, so release TopN overcommit memory group; if total_exceeded_memory <= request_free_memory need release all groups overcommit memory. -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: commits-unsubscr...@doris.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org --------------------------------------------------------------------- To unsubscribe, e-mail: commits-unsubscr...@doris.apache.org For additional commands, e-mail: commits-h...@doris.apache.org