[feature-wip] (memory tracker) (step4) Switch TLS mem tracker to separate more detailed memory usage (#8669)

Based on #8605, Separate out the memory usage of each operator from the Query/Load/StorageEngine mem tracker.
This commit is contained in:
Xinyi Zou
2022-04-08 09:02:26 +08:00
committed by GitHub
parent 7fb4b6a6e2
commit 519305cb22
79 changed files with 378 additions and 150 deletions

View File

@ -28,6 +28,7 @@
#include "runtime/mem_tracker.h"
#include "runtime/raw_value.h"
#include "runtime/runtime_state.h"
#include "runtime/thread_context.h"
#include "udf/udf_internal.h"
#include "util/debug_util.h"
#include "util/stack_util.h"
@ -52,6 +53,7 @@ Status ExprContext::prepare(RuntimeState* state, const RowDescriptor& row_desc,
const std::shared_ptr<MemTracker>& tracker) {
DCHECK(!_prepared);
_mem_tracker = tracker;
SCOPED_SWITCH_THREAD_LOCAL_MEM_TRACKER(_mem_tracker);
DCHECK(_pool.get() == nullptr);
_prepared = true;
_pool.reset(new MemPool(_mem_tracker.get()));
@ -63,6 +65,7 @@ Status ExprContext::open(RuntimeState* state) {
if (_opened) {
return Status::OK();
}
SCOPED_SWITCH_THREAD_LOCAL_MEM_TRACKER(_mem_tracker);
_opened = true;
// Fragment-local state is only initialized for original contexts. Clones inherit the
// original's fragment state and only need to have thread-local state initialized.
@ -108,6 +111,7 @@ Status ExprContext::clone(RuntimeState* state, ExprContext** new_ctx) {
DCHECK(_prepared);
DCHECK(_opened);
DCHECK(*new_ctx == nullptr);
SCOPED_SWITCH_THREAD_LOCAL_MEM_TRACKER(_mem_tracker);
*new_ctx = state->obj_pool()->add(new ExprContext(_root));
(*new_ctx)->_pool.reset(new MemPool(_pool->mem_tracker()));
@ -127,6 +131,7 @@ Status ExprContext::clone(RuntimeState* state, ExprContext** new_ctx, Expr* root
DCHECK(_prepared);
DCHECK(_opened);
DCHECK(*new_ctx == nullptr);
SCOPED_SWITCH_THREAD_LOCAL_MEM_TRACKER(_mem_tracker);
*new_ctx = state->obj_pool()->add(new ExprContext(root));
(*new_ctx)->_pool.reset(new MemPool(_pool->mem_tracker()));
@ -143,6 +148,7 @@ Status ExprContext::clone(RuntimeState* state, ExprContext** new_ctx, Expr* root
}
void ExprContext::free_local_allocations() {
SCOPED_SWITCH_THREAD_LOCAL_MEM_TRACKER(_mem_tracker);
free_local_allocations(_fn_contexts);
}