[branch-2.1](memory) Fix reserve memory compatible with memory GC and logging (#37682)

pick
#36307
#36412
This commit is contained in:
Xinyi Zou
2024-07-12 11:43:26 +08:00
committed by GitHub
parent ffa9e49bc7
commit ef031c5fb2
15 changed files with 556 additions and 450 deletions

View File

@ -50,6 +50,7 @@
#include "runtime/memory/global_memory_arbitrator.h"
#include "runtime/memory/mem_tracker.h"
#include "runtime/memory/mem_tracker_limiter.h"
#include "runtime/memory/memory_arbitrator.h"
#include "runtime/runtime_query_statistics_mgr.h"
#include "runtime/workload_group/workload_group_manager.h"
#include "util/cpu_info.h"
@ -192,7 +193,7 @@ void Daemon::memory_maintenance_thread() {
// Refresh process memory metrics.
doris::PerfCounters::refresh_proc_status();
doris::MemInfo::refresh_proc_meminfo();
doris::GlobalMemoryArbitrator::refresh_vm_rss_sub_allocator_cache();
doris::GlobalMemoryArbitrator::reset_refresh_interval_memory_growth();
// Update and print memory stat when the memory changes by 256M.
if (abs(last_print_proc_mem - PerfCounters::get_vm_rss()) > 268435456) {
@ -229,11 +230,11 @@ void Daemon::memory_gc_thread() {
if (config::disable_memory_gc) {
continue;
}
auto sys_mem_available = doris::MemInfo::sys_mem_available();
auto sys_mem_available = doris::GlobalMemoryArbitrator::sys_mem_available();
auto process_memory_usage = doris::GlobalMemoryArbitrator::process_memory_usage();
// GC excess memory for resource groups that not enable overcommit
auto tg_free_mem = doris::MemInfo::tg_disable_overcommit_group_gc();
auto tg_free_mem = doris::MemoryArbitrator::tg_disable_overcommit_group_gc();
sys_mem_available += tg_free_mem;
process_memory_usage -= tg_free_mem;
@ -241,13 +242,13 @@ void Daemon::memory_gc_thread() {
(sys_mem_available < doris::MemInfo::sys_mem_available_low_water_mark() ||
process_memory_usage >= doris::MemInfo::mem_limit())) {
// No longer full gc and minor gc during sleep.
std::string mem_info =
doris::GlobalMemoryArbitrator::process_limit_exceeded_errmsg_str();
memory_full_gc_sleep_time_ms = memory_gc_sleep_time_ms;
memory_minor_gc_sleep_time_ms = memory_gc_sleep_time_ms;
LOG(INFO) << fmt::format(
"[MemoryGC] start full GC, {}.",
doris::GlobalMemoryArbitrator::process_limit_exceeded_errmsg_str());
LOG(INFO) << fmt::format("[MemoryGC] start full GC, {}.", mem_info);
doris::MemTrackerLimiter::print_log_process_usage();
if (doris::MemInfo::process_full_gc()) {
if (doris::MemoryArbitrator::process_full_gc(std::move(mem_info))) {
// If there is not enough memory to be gc, the process memory usage will not be printed in the next continuous gc.
doris::MemTrackerLimiter::enable_print_log_process_usage();
}
@ -255,12 +256,12 @@ void Daemon::memory_gc_thread() {
(sys_mem_available < doris::MemInfo::sys_mem_available_warning_water_mark() ||
process_memory_usage >= doris::MemInfo::soft_mem_limit())) {
// No minor gc during sleep, but full gc is possible.
std::string mem_info =
doris::GlobalMemoryArbitrator::process_soft_limit_exceeded_errmsg_str();
memory_minor_gc_sleep_time_ms = memory_gc_sleep_time_ms;
LOG(INFO) << fmt::format(
"[MemoryGC] start minor GC, {}.",
doris::GlobalMemoryArbitrator::process_soft_limit_exceeded_errmsg_str());
LOG(INFO) << fmt::format("[MemoryGC] start minor GC, {}.", mem_info);
doris::MemTrackerLimiter::print_log_process_usage();
if (doris::MemInfo::process_minor_gc()) {
if (doris::MemoryArbitrator::process_minor_gc(std::move(mem_info))) {
doris::MemTrackerLimiter::enable_print_log_process_usage();
}
} else {