[fix](memtracker) Introduce orphan mem tracker to verify memory tracking accuracy (#12794)

The mem hook consumes the orphan tracker by default. If the thread does not attach other trackers, by default all consumption will be passed to the process tracker through the orphan tracker.

In real time, consumption of all other trackers + orphan tracker consumption = process tracker consumption.

Ideally, all threads are expected to attach to the specified tracker, so that "all memory has its own ownership", and the consumption of the orphan mem tracker is close to 0, but greater than 0.
This commit is contained in:
Xinyi Zou
2022-09-21 15:47:10 +08:00
committed by GitHub
parent 8f4bb0f804
commit b41eaa5ac0
13 changed files with 97 additions and 54 deletions

View File

@ -206,7 +206,8 @@ Status ExecEnv::_init_mem_tracker() {
}
_process_mem_tracker =
std::make_shared<MemTrackerLimiter>(global_memory_limit_bytes, "Process");
_process_mem_tracker_raw = _process_mem_tracker.get();
_orphan_mem_tracker = std::make_shared<MemTrackerLimiter>(-1, "Orphan", _process_mem_tracker);
_orphan_mem_tracker_raw = _orphan_mem_tracker.get();
thread_context()->_thread_mem_tracker_mgr->init();
thread_context()->_thread_mem_tracker_mgr->set_check_attach(false);
#if defined(USE_MEM_TRACKER) && !defined(__SANITIZE_ADDRESS__) && !defined(ADDRESS_SANITIZER) && \