[feature] (memory) Switch TLS mem tracker to separate more detailed memory usage (#8605)
In pr #8476, all memory usage of a process is recorded in the process mem tracker, and all memory usage of a query is recorded in the query mem tracker, and it is still necessary to manually call `transfer to` to track the cached memory size. We hope to separate out more detailed memory usage based on Hook TCMalloc new/delete + TLS mem tracker. In this pr, the more detailed mem tracker is switched to TLS, which automatically and accurately counts more detailed memory usage than before.
This commit is contained in:
@ -192,11 +192,6 @@ OLAPStatus TabletManager::_add_tablet_to_map_unlocked(TTabletId tablet_id,
|
||||
tablet_map_t& tablet_map = _get_tablet_map(tablet_id);
|
||||
tablet_map[tablet_id] = tablet;
|
||||
_add_tablet_to_partition(tablet);
|
||||
// TODO: remove multiply 2 of tablet meta mem size
|
||||
// Because table schema will copy in tablet, there will be double mem cost
|
||||
// so here multiply 2
|
||||
thread_local_ctx.get()->_thread_mem_tracker_mgr->mem_tracker()->transfer_to(
|
||||
_mem_tracker.get(), tablet->tablet_meta()->mem_size() * 2);
|
||||
|
||||
VLOG_NOTICE << "add tablet to map successfully." << " tablet_id=" << tablet_id ;
|
||||
|
||||
@ -215,6 +210,7 @@ bool TabletManager::_check_tablet_id_exist_unlocked(TTabletId tablet_id) {
|
||||
|
||||
OLAPStatus TabletManager::create_tablet(const TCreateTabletReq& request,
|
||||
std::vector<DataDir*> stores) {
|
||||
SCOPED_SWITCH_THREAD_LOCAL_MEM_TRACKER(_mem_tracker);
|
||||
DorisMetrics::instance()->create_tablet_requests_total->increment(1);
|
||||
|
||||
int64_t tablet_id = request.tablet_id;
|
||||
@ -432,6 +428,7 @@ TabletSharedPtr TabletManager::_create_tablet_meta_and_dir_unlocked(
|
||||
OLAPStatus TabletManager::drop_tablet(TTabletId tablet_id, SchemaHash schema_hash,
|
||||
bool keep_files) {
|
||||
WriteLock wrlock(_get_tablets_shard_lock(tablet_id));
|
||||
SCOPED_SWITCH_THREAD_LOCAL_MEM_TRACKER(_mem_tracker);
|
||||
return _drop_tablet_unlocked(tablet_id, keep_files);
|
||||
}
|
||||
|
||||
@ -460,6 +457,7 @@ OLAPStatus TabletManager::_drop_tablet_unlocked(TTabletId tablet_id, bool keep_f
|
||||
|
||||
OLAPStatus TabletManager::drop_tablets_on_error_root_path(
|
||||
const std::vector<TabletInfo>& tablet_info_vec) {
|
||||
SCOPED_SWITCH_THREAD_LOCAL_MEM_TRACKER(_mem_tracker);
|
||||
OLAPStatus res = OLAP_SUCCESS;
|
||||
if (tablet_info_vec.empty()) { // This is a high probability event
|
||||
return res;
|
||||
@ -670,6 +668,7 @@ OLAPStatus TabletManager::load_tablet_from_meta(DataDir* data_dir, TTabletId tab
|
||||
TSchemaHash schema_hash, const string& meta_binary,
|
||||
bool update_meta, bool force, bool restore,
|
||||
bool check_path) {
|
||||
SCOPED_SWITCH_THREAD_LOCAL_MEM_TRACKER(_mem_tracker);
|
||||
TabletMetaSharedPtr tablet_meta(new TabletMeta());
|
||||
OLAPStatus status = tablet_meta->deserialize(meta_binary);
|
||||
if (status != OLAP_SUCCESS) {
|
||||
@ -752,6 +751,7 @@ OLAPStatus TabletManager::load_tablet_from_dir(DataDir* store, TTabletId tablet_
|
||||
SchemaHash schema_hash,
|
||||
const string& schema_hash_path, bool force,
|
||||
bool restore) {
|
||||
SCOPED_SWITCH_THREAD_LOCAL_MEM_TRACKER(_mem_tracker);
|
||||
LOG(INFO) << "begin to load tablet from dir. "
|
||||
<< " tablet_id=" << tablet_id << " schema_hash=" << schema_hash
|
||||
<< " path = " << schema_hash_path << " force = " << force << " restore = " << restore;
|
||||
@ -1219,11 +1219,6 @@ OLAPStatus TabletManager::_drop_tablet_directly_unlocked(TTabletId tablet_id, bo
|
||||
}
|
||||
|
||||
dropped_tablet->deregister_tablet_from_dir();
|
||||
// The dropped tablet meta is expected to be released in the TabletManager mem tracker,
|
||||
// but is actually released in the tls mem tracker.
|
||||
// So from TabletManager mem tracker compensate memory to tls tracker.
|
||||
_mem_tracker->transfer_to(thread_local_ctx.get()->_thread_mem_tracker_mgr->mem_tracker().get(),
|
||||
dropped_tablet->tablet_meta()->mem_size() * 2);
|
||||
return OLAP_SUCCESS;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user