diff options
author | Sergei Golubchik <serg@mariadb.org> | 2020-01-29 13:50:26 +0100 |
---|---|---|
committer | Sergei Golubchik <serg@mariadb.org> | 2020-03-10 19:24:22 +0100 |
commit | 7c58e97bf6f80a251046c5b3e7bce826fe058bd6 (patch) | |
tree | 7d32d26b320cf83296ee0ede2ea164ad116c4de8 /sql | |
parent | 2ac3121af2767186c489054db5d4871d04b8eef4 (diff) | |
download | mariadb-git-7c58e97bf6f80a251046c5b3e7bce826fe058bd6.tar.gz |
perfschema memory related instrumentation changes
Diffstat (limited to 'sql')
122 files changed, 1249 insertions, 649 deletions
diff --git a/sql/create_options.cc b/sql/create_options.cc index 817c4ba46e0..04469120db1 100644 --- a/sql/create_options.cc +++ b/sql/create_options.cc @@ -407,7 +407,7 @@ static bool resolve_sysvars(handlerton *hton, ha_create_table_option *rules) return 1; } DBUG_ASSERT(str.length()); - opt->values= my_strndup(str.ptr(), str.length()-1, MYF(MY_WME)); + opt->values= my_strndup(PSI_INSTRUMENT_ME, str.ptr(), str.length()-1, MYF(MY_WME)); if (!opt->values) return 1; break; diff --git a/sql/datadict.cc b/sql/datadict.cc index da8376d8b1a..5cfda166b2b 100644 --- a/sql/datadict.cc +++ b/sql/datadict.cc @@ -25,7 +25,7 @@ static int read_string(File file, uchar**to, size_t length) DBUG_ENTER("read_string"); /* This can't use MY_THREAD_SPECIFIC as it's used on server start */ - if (!(*to= (uchar*) my_malloc(length+1,MYF(MY_WME))) || + if (!(*to= (uchar*) my_malloc(PSI_INSTRUMENT_ME, length+1,MYF(MY_WME))) || mysql_file_read(file, *to, length, MYF(MY_NABP))) { my_free(*to); diff --git a/sql/debug_sync.cc b/sql/debug_sync.cc index af541b1bb32..759e28b8589 100644 --- a/sql/debug_sync.cc +++ b/sql/debug_sync.cc @@ -236,7 +236,8 @@ void debug_sync_init_thread(THD *thd) if (opt_debug_sync_timeout) { thd->debug_sync_control= (st_debug_sync_control*) - my_malloc(sizeof(st_debug_sync_control), + my_malloc(PSI_NOT_INSTRUMENTED, + sizeof(st_debug_sync_control), MYF(MY_WME | MY_ZEROFILL | MY_THREAD_SPECIFIC)); if (!thd->debug_sync_control) { @@ -657,7 +658,7 @@ static st_debug_sync_action *debug_sync_get_action(THD *thd, if (ds_control->ds_active > ds_control->ds_allocated) { uint new_alloc= ds_control->ds_active + 3; - void *new_action= my_realloc(ds_control->ds_action, + void *new_action= my_realloc(PSI_NOT_INSTRUMENTED, ds_control->ds_action, new_alloc * sizeof(st_debug_sync_action), MYF(MY_WME | MY_ALLOW_ZERO_PTR)); if (!new_action) diff --git a/sql/derror.cc b/sql/derror.cc index 7a79833c26c..1c10bdfdd92 100644 --- a/sql/derror.cc +++ b/sql/derror.cc @@ -120,8 +120,9 @@ bool init_errmessage(void) all_errors+= errors_per_range[i]; if (!(original_error_messages= (const char***) - my_malloc((all_errors + MAX_ERROR_RANGES)* sizeof(void*), - MYF(MY_ZEROFILL)))) + my_malloc(PSI_NOT_INSTRUMENTED, + (all_errors + MAX_ERROR_RANGES)*sizeof(void*), + MYF(MY_ZEROFILL)))) DBUG_RETURN(TRUE); errmsgs= (const char**)(original_error_messages + MAX_ERROR_RANGES); @@ -315,7 +316,8 @@ bool read_texts(const char *file_name, const char *language, DBUG_RETURN(1); if (!(*data= (const char***) - my_malloc((size_t) ((MAX_ERROR_RANGES+1) * sizeof(char**) + + my_malloc(key_memory_errmsgs, + (size_t) ((MAX_ERROR_RANGES+1) * sizeof(char**) + MY_MAX(msg_file.text_length, msg_file.errors * 2)+ msg_file.errors * sizeof(char*)), MYF(MY_WME)))) diff --git a/sql/discover.cc b/sql/discover.cc index 3e41388ed51..e49a2a3b0c0 100644 --- a/sql/discover.cc +++ b/sql/discover.cc @@ -76,7 +76,8 @@ int readfrm(const char *name, const uchar **frmdata, size_t *len) // Read whole frm file error= 3; - if (!(read_data= (uchar*)my_malloc(read_len, MYF(MY_WME)))) + if (!(read_data= (uchar*)my_malloc(key_memory_frm_string, read_len, + MYF(MY_WME)))) goto err; if (mysql_file_read(file, read_data, read_len, MYF(MY_NABP))) { diff --git a/sql/event_data_objects.cc b/sql/event_data_objects.cc index 81e703b5653..39f1889142e 100644 --- a/sql/event_data_objects.cc +++ b/sql/event_data_objects.cc @@ -173,11 +173,13 @@ Event_creation_ctx::load_from_db(THD *thd, */ bool -Event_queue_element_for_exec::init(const LEX_CSTRING *db, const LEX_CSTRING *n) +Event_queue_element_for_exec::init(const LEX_CSTRING &db, const LEX_CSTRING &n) { - if (!(dbname.str= my_strndup(db->str, dbname.length= db->length, MYF(MY_WME)))) + if (!(dbname.str= my_strndup(key_memory_Event_queue_element_for_exec_names, + db.str, dbname.length= db.length, MYF(MY_WME)))) return TRUE; - if (!(name.str= my_strndup(n->str, name.length= n->length, MYF(MY_WME)))) + if (!(name.str= my_strndup(key_memory_Event_queue_element_for_exec_names, + n.str, name.length= n.length, MYF(MY_WME)))) { my_free(const_cast<char*>(dbname.str)); return TRUE; @@ -211,7 +213,7 @@ Event_basic::Event_basic() { DBUG_ENTER("Event_basic::Event_basic"); /* init memory root */ - init_sql_alloc(&mem_root, "Event_basic", 256, 512, MYF(0)); + init_sql_alloc(key_memory_event_basic_root, &mem_root, 256, 512, MYF(0)); dbname.str= name.str= NULL; dbname.length= name.length= 0; time_zone= NULL; diff --git a/sql/event_data_objects.h b/sql/event_data_objects.h index e5e3e4eb087..d7cfefaa948 100644 --- a/sql/event_data_objects.h +++ b/sql/event_data_objects.h @@ -37,7 +37,7 @@ public: ~Event_queue_element_for_exec(); bool - init(const LEX_CSTRING *dbname, const LEX_CSTRING *name); + init(const LEX_CSTRING &dbname, const LEX_CSTRING &name); LEX_CSTRING dbname; LEX_CSTRING name; diff --git a/sql/event_queue.cc b/sql/event_queue.cc index 6b3f5777df3..89bd672671f 100644 --- a/sql/event_queue.cc +++ b/sql/event_queue.cc @@ -637,7 +637,7 @@ Event_queue::get_top_for_execution_if_time(THD *thd, } if (!(*event_name= new Event_queue_element_for_exec()) || - (*event_name)->init(&top->dbname, &top->name)) + (*event_name)->init(top->dbname, top->name)) { ret= TRUE; break; diff --git a/sql/event_scheduler.cc b/sql/event_scheduler.cc index 9a8869e2fb3..bb9676f3bef 100644 --- a/sql/event_scheduler.cc +++ b/sql/event_scheduler.cc @@ -411,7 +411,8 @@ Event_scheduler::start(int *err_no) /* This should not be marked with MY_THREAD_SPECIFIC */ scheduler_param_value= - (struct scheduler_param *)my_malloc(sizeof(struct scheduler_param), MYF(0)); + (struct scheduler_param *)my_malloc(key_memory_Event_scheduler_scheduler_param, + sizeof(struct scheduler_param), MYF(0)); scheduler_param_value->thd= new_thd; scheduler_param_value->scheduler= this; diff --git a/sql/events.cc b/sql/events.cc index f4400abdeb5..0014ce42d28 100644 --- a/sql/events.cc +++ b/sql/events.cc @@ -1027,6 +1027,8 @@ PSI_stage_info stage_waiting_on_empty_queue= { 0, "Waiting on empty queue", 0}; PSI_stage_info stage_waiting_for_next_activation= { 0, "Waiting for next activation", 0}; PSI_stage_info stage_waiting_for_scheduler_to_stop= { 0, "Waiting for the scheduler to stop", 0}; +PSI_memory_key key_memory_event_basic_root; + #ifdef HAVE_PSI_INTERFACE PSI_stage_info *all_events_stages[]= { @@ -1035,6 +1037,11 @@ PSI_stage_info *all_events_stages[]= & stage_waiting_for_scheduler_to_stop }; +static PSI_memory_info all_events_memory[]= +{ + { &key_memory_event_basic_root, "Event_basic::mem_root", PSI_FLAG_GLOBAL} +}; + static void init_events_psi_keys(void) { const char* category= "sql"; @@ -1052,6 +1059,8 @@ static void init_events_psi_keys(void) count= array_elements(all_events_stages); mysql_stage_register(category, all_events_stages, count); + count= array_elements(all_events_memory); + mysql_memory_register(category, all_events_memory, count); } #endif /* HAVE_PSI_INTERFACE */ diff --git a/sql/events.h b/sql/events.h index 9e1651c767a..2fb13d7c807 100644 --- a/sql/events.h +++ b/sql/events.h @@ -31,6 +31,8 @@ extern PSI_cond_key key_event_scheduler_COND_state; extern PSI_thread_key key_thread_event_scheduler, key_thread_event_worker; #endif /* HAVE_PSI_INTERFACE */ +extern PSI_memory_key key_memory_event_basic_root; + /* Always defined, for SHOW PROCESSLIST. */ extern PSI_stage_info stage_waiting_on_empty_queue; extern PSI_stage_info stage_waiting_for_next_activation; diff --git a/sql/field.cc b/sql/field.cc index 5a2dbdfa15c..460c26fbfd2 100644 --- a/sql/field.cc +++ b/sql/field.cc @@ -8074,7 +8074,7 @@ int Field_longstr::compress(char *to, uint to_length, max_length < length) { set_if_smaller(max_length, static_cast<ulonglong>(mbmaxlen()) * length + 1); - if (!(buf= (char*) my_malloc(max_length, MYF(MY_WME)))) + if (!(buf= (char*) my_malloc(PSI_INSTRUMENT_ME, max_length, MYF(MY_WME)))) { *out_length= 0; return -1; diff --git a/sql/filesort.cc b/sql/filesort.cc index ea13e26c698..1e19d492220 100644 --- a/sql/filesort.cc +++ b/sql/filesort.cc @@ -312,7 +312,7 @@ SORT_INFO *filesort(THD *thd, TABLE *table, Filesort *filesort, param.using_pq= false; if ((multi_byte_charset || param.using_packed_sortkeys()) && - !(param.tmp_buffer= (char*) my_malloc(param.sort_length, + !(param.tmp_buffer= (char*) my_malloc(key_memory_Sort_param_tmp_buffer, param.sort_length, MYF(MY_WME | MY_THREAD_SPECIFIC)))) goto err; @@ -619,7 +619,8 @@ static uchar *read_buffpek_from_file(IO_CACHE *buffpek_pointers, uint count, if (count > UINT_MAX/sizeof(Merge_chunk)) return 0; /* sizeof(BUFFPEK)*count will overflow */ if (!tmp) - tmp= (uchar *)my_malloc(length, MYF(MY_WME | MY_THREAD_SPECIFIC)); + tmp= (uchar *)my_malloc(key_memory_Filesort_info_merge, length, + MYF(MY_WME | MY_THREAD_SPECIFIC)); if (tmp) { if (reinit_io_cache(buffpek_pointers,READ_CACHE,0L,0,0) || @@ -1452,8 +1453,8 @@ static bool save_index(Sort_param *param, uint count, res_length= param->res_length; offset= param->rec_length-res_length; if (!(to= table_sort->record_pointers= - (uchar*) my_malloc(res_length*count, - MYF(MY_WME | MY_THREAD_SPECIFIC)))) + (uchar*) my_malloc(key_memory_Filesort_info_record_pointers, + res_length*count, MYF(MY_WME | MY_THREAD_SPECIFIC)))) DBUG_RETURN(1); /* purecov: inspected */ for (uint ix= 0; ix < count; ++ix) { @@ -2380,7 +2381,7 @@ get_addon_fields(TABLE *table, uint sortlength, if (!filesort_use_addons(table, sortlength, &length, &fields, &null_fields, &packable_length) || - !(my_multi_malloc(MYF(MY_WME | MY_THREAD_SPECIFIC), + !(my_multi_malloc(PSI_INSTRUMENT_ME, MYF(MY_WME | MY_THREAD_SPECIFIC), &raw_mem, sizeof(Addon_fields), &raw_mem_addon_field, sizeof(SORT_ADDON_FIELD) * fields, diff --git a/sql/filesort_utils.cc b/sql/filesort_utils.cc index a3b493b4c7a..d178740d24b 100644 --- a/sql/filesort_utils.cc +++ b/sql/filesort_utils.cc @@ -20,6 +20,8 @@ #include "table.h" +PSI_memory_key key_memory_Filesort_buffer_sort_keys; + namespace { /** A local helper function. See comments for get_merge_buffers_cost(). @@ -128,7 +130,8 @@ uchar *Filesort_buffer::alloc_sort_buffer(uint num_records, the old values */ my_free(m_rawmem); - if (!(m_rawmem= (uchar*) my_malloc(buff_size, MYF(MY_THREAD_SPECIFIC)))) + if (!(m_rawmem= (uchar*) my_malloc(key_memory_Filesort_buffer_sort_keys, + buff_size, MYF(MY_THREAD_SPECIFIC)))) { m_size_in_bytes= 0; DBUG_RETURN(0); @@ -137,7 +140,8 @@ uchar *Filesort_buffer::alloc_sort_buffer(uint num_records, } else { - if (!(m_rawmem= (uchar*) my_malloc(buff_size, MYF(MY_THREAD_SPECIFIC)))) + if (!(m_rawmem= (uchar*) my_malloc(key_memory_Filesort_buffer_sort_keys, + buff_size, MYF(MY_THREAD_SPECIFIC)))) { m_size_in_bytes= 0; DBUG_RETURN(0); @@ -177,7 +181,7 @@ void Filesort_buffer::sort_buffer(const Sort_param *param, uint count) uchar **buffer= NULL; if (!param->using_packed_sortkeys() && radixsort_is_appliccable(count, param->sort_length) && - (buffer= (uchar**) my_malloc(count*sizeof(char*), + (buffer= (uchar**) my_malloc(PSI_INSTRUMENT_ME, count*sizeof(char*), MYF(MY_THREAD_SPECIFIC)))) { radixsort_for_str_ptr(m_sort_keys, count, param->sort_length, buffer); diff --git a/sql/gcalc_slicescan.cc b/sql/gcalc_slicescan.cc index 4919e5b959b..6d7ab7e29c3 100644 --- a/sql/gcalc_slicescan.cc +++ b/sql/gcalc_slicescan.cc @@ -204,7 +204,7 @@ void Gcalc_dyn_list::format_blk(void* block) Gcalc_dyn_list::Item *Gcalc_dyn_list::alloc_new_blk() { - void *new_block= my_malloc(m_blk_size, MYF(MY_WME)); + void *new_block= my_malloc(PSI_INSTRUMENT_ME, m_blk_size, MYF(MY_WME)); if (!new_block) return NULL; *m_blk_hook= new_block; diff --git a/sql/gstream.cc b/sql/gstream.cc index b743140ba59..f8e84e70560 100644 --- a/sql/gstream.cc +++ b/sql/gstream.cc @@ -23,6 +23,7 @@ #include "sql_priv.h" #include "gstream.h" #include "m_string.h" // LEX_STRING +#include "mysqld.h" enum Gis_read_stream::enum_tok_types Gis_read_stream::get_next_toc_type() { @@ -140,6 +141,7 @@ bool Gis_read_stream::check_next_symbol(char symbol) void Gis_read_stream::set_error_msg(const char *msg) { size_t len= strlen(msg); // ok in this context - m_err_msg= (char *) my_realloc(m_err_msg, (uint) len + 1, MYF(MY_ALLOW_ZERO_PTR)); + m_err_msg= (char *) my_realloc(key_memory_Gis_read_stream_err_msg, + m_err_msg, (uint) len + 1, MYF(MY_ALLOW_ZERO_PTR)); memcpy(m_err_msg, msg, len + 1); } diff --git a/sql/ha_partition.cc b/sql/ha_partition.cc index d36a58aef20..e1a1e4d45de 100644 --- a/sql/ha_partition.cc +++ b/sql/ha_partition.cc @@ -102,22 +102,43 @@ static const char *ha_partition_ext[]= ha_par_ext, NullS }; +static PSI_memory_key key_memory_Partition_share; +static PSI_memory_key key_memory_partition_sort_buffer; +static PSI_memory_key key_memory_Partition_admin; + +static PSI_memory_key key_memory_ha_partition_file; +static PSI_memory_key key_memory_ha_partition_engine_array; +static PSI_memory_key key_memory_ha_partition_part_ids; #ifdef HAVE_PSI_INTERFACE PSI_mutex_key key_partition_auto_inc_mutex; +PSI_file_key key_file_ha_partition_par; static PSI_mutex_info all_partition_mutexes[]= { { &key_partition_auto_inc_mutex, "Partition_share::auto_inc_mutex", 0} }; +static PSI_memory_info all_partitioning_memory[]= +{ { &key_memory_Partition_share, "Partition_share", 0}, + { &key_memory_partition_sort_buffer, "partition_sort_buffer", 0}, + { &key_memory_Partition_admin, "Partition_admin", 0}, + { &key_memory_ha_partition_file, "ha_partition::file", 0}, + { &key_memory_ha_partition_engine_array, "ha_partition::engine_array", 0}, + { &key_memory_ha_partition_part_ids, "ha_partition::part_ids", 0} }; +static PSI_file_info all_partition_file[]= +{ { &key_file_ha_partition_par, "ha_partition::parfile", 0} }; static void init_partition_psi_keys(void) { const char* category= "partition"; int count; + count= array_elements(all_partitioning_memory); + mysql_memory_register(category, all_partitioning_memory, count); count= array_elements(all_partition_mutexes); mysql_mutex_register(category, all_partition_mutexes, count); + count= array_elements(all_partition_file); + mysql_file_register(category, all_partition_file, count); } #endif /* HAVE_PSI_INTERFACE */ @@ -244,7 +265,7 @@ ha_partition::ha_partition(handlerton *hton, TABLE_SHARE *share) void ha_partition::ha_partition_init() { - init_alloc_root(&m_mem_root, "ha_partition", 512, 512, MYF(0)); + init_alloc_root(PSI_INSTRUMENT_ME, &m_mem_root, 512, 512, MYF(0)); init_handler_variables(); } @@ -649,9 +670,9 @@ int ha_partition::create_partitioning_metadata(const char *path, strxmov(name, path, ha_par_ext, NullS); strxmov(old_name, old_path, ha_par_ext, NullS); if ((action_flag == CHF_DELETE_FLAG && - mysql_file_delete(key_file_partition, name, MYF(MY_WME))) || + mysql_file_delete(key_file_ha_partition_par, name, MYF(MY_WME))) || (action_flag == CHF_RENAME_FLAG && - mysql_file_rename(key_file_partition, old_name, name, MYF(MY_WME)))) + mysql_file_rename(key_file_ha_partition_par, old_name, name, MYF(MY_WME)))) { DBUG_RETURN(TRUE); } @@ -1333,7 +1354,7 @@ bool print_admin_msg(THD* thd, uint len, char *msgbuf; bool error= true; - if (!(msgbuf= (char*) my_malloc(len, MYF(0)))) + if (!(msgbuf= (char*) my_malloc(key_memory_Partition_admin, len, MYF(0)))) return true; va_start(args, fmt); msg_length= my_vsnprintf(msgbuf, len, fmt, args); @@ -2749,7 +2770,8 @@ bool ha_partition::create_handler_file(const char *name) /* 4 static words (tot words, checksum, tot partitions, name length) */ tot_len_words= 4 + tot_partition_words + tot_name_words; tot_len_byte= PAR_WORD_SIZE * tot_len_words; - if (!(file_buffer= (uchar *) my_malloc(tot_len_byte, MYF(MY_ZEROFILL)))) + if (!(file_buffer= (uchar *) my_malloc(key_memory_ha_partition_file, + tot_len_byte, MYF(MY_ZEROFILL)))) DBUG_RETURN(TRUE); engine_array= (file_buffer + PAR_ENGINES_OFFSET); name_buffer_ptr= (char*) (engine_array + tot_partition_words * PAR_WORD_SIZE @@ -2804,7 +2826,7 @@ bool ha_partition::create_handler_file(const char *name) to be used at open, delete_table and rename_table */ fn_format(file_name, name, "", ha_par_ext, MY_APPEND_EXT); - if ((file= mysql_file_create(key_file_partition, + if ((file= mysql_file_create(key_file_ha_partition_par, file_name, CREATE_MODE, O_RDWR | O_TRUNC, MYF(MY_WME))) >= 0) { @@ -2829,7 +2851,7 @@ bool ha_partition::create_handler_file(const char *name) } (void) mysql_file_close(file, MYF(0)); if (result) - mysql_file_delete(key_file_partition, file_name, MYF(MY_WME)); + mysql_file_delete(key_file_ha_partition_par, file_name, MYF(MY_WME)); } else result= TRUE; @@ -2993,7 +3015,7 @@ bool ha_partition::read_par_file(const char *name) fn_format(buff, name, "", ha_par_ext, MY_APPEND_EXT); /* Following could be done with mysql_file_stat to read in whole file */ - if ((file= mysql_file_open(key_file_partition, + if ((file= mysql_file_open(key_file_ha_partition_par, buff, O_RDONLY | O_SHARE, MYF(0))) < 0) DBUG_RETURN(TRUE); if (mysql_file_read(file, (uchar *) &buff[0], PAR_WORD_SIZE, MYF(MY_NABP))) @@ -3219,7 +3241,7 @@ bool ha_partition::insert_partition_name_in_hash(const char *name, uint part_id, Since we use my_multi_malloc, then my_free(part_def) will also free part_name, as a part of my_hash_free. */ - if (!my_multi_malloc(MY_WME, + if (!my_multi_malloc(key_memory_Partition_share, MY_WME, &part_def, sizeof(PART_NAME_DEF), &part_name, part_name_length + 1, NULL)) @@ -3270,7 +3292,7 @@ bool ha_partition::populate_partition_name_hash() if (my_hash_init(&part_share->partition_name_hash, system_charset_info, tot_names, 0, 0, (my_hash_get_key) get_part_name, - my_free, HASH_UNIQUE)) + my_free, HASH_UNIQUE, key_memory_Partition_share)) { unlock_shared_ha_data(); DBUG_RETURN(TRUE); @@ -3506,7 +3528,8 @@ int ha_partition::open(const char *name, int mode, uint test_if_locked) if (!m_part_ids_sorted_by_num_of_records) { if (!(m_part_ids_sorted_by_num_of_records= - (uint32*) my_malloc(m_tot_parts * sizeof(uint32), MYF(MY_WME)))) + (uint32*) my_malloc(key_memory_ha_partition_part_ids, + m_tot_parts * sizeof(uint32), MYF(MY_WME)))) DBUG_RETURN(error); uint32 i; /* Initialize it with all partition ids. */ @@ -3524,7 +3547,7 @@ int ha_partition::open(const char *name, int mode, uint test_if_locked) /* Allocate memory used with MMR */ if (!(m_range_info= (void **) - my_multi_malloc(MYF(MY_WME), + my_multi_malloc(PSI_INSTRUMENT_ME, MYF(MY_WME), &m_range_info, sizeof(range_id_t) * m_tot_parts, &m_stock_range_seq, sizeof(uint) * m_tot_parts, &m_mrr_buffer, sizeof(HANDLER_BUFFER) * m_tot_parts, @@ -3535,8 +3558,7 @@ int ha_partition::open(const char *name, int mode, uint test_if_locked) &m_part_mrr_range_current, sizeof(PARTITION_PART_KEY_MULTI_RANGE *) * m_tot_parts, &m_partition_part_key_multi_range_hld, - sizeof(PARTITION_PART_KEY_MULTI_RANGE_HLD) * - m_tot_parts, + sizeof(PARTITION_PART_KEY_MULTI_RANGE_HLD) * m_tot_parts, NullS))) goto err_alloc; @@ -5315,7 +5337,8 @@ bool ha_partition::init_record_priority_queue() /* Allocate a key for temporary use when setting up the scan. */ alloc_len+= table_share->max_key_length; - if (!(m_ordered_rec_buffer= (uchar*)my_malloc(alloc_len, MYF(MY_WME)))) + if (!(m_ordered_rec_buffer= (uchar*)my_malloc(key_memory_partition_sort_buffer, + alloc_len, MYF(MY_WME)))) DBUG_RETURN(true); /* @@ -6066,9 +6089,8 @@ int ha_partition::multi_range_key_create_key(RANGE_SEQ_IF *seq, if (!m_mrr_range_first) { if (!(m_mrr_range_first= (PARTITION_KEY_MULTI_RANGE *) - my_multi_malloc(MYF(MY_WME), - &m_mrr_range_current, - sizeof(PARTITION_KEY_MULTI_RANGE), + my_multi_malloc(PSI_INSTRUMENT_ME, MYF(MY_WME), + &m_mrr_range_current, sizeof(PARTITION_KEY_MULTI_RANGE), NullS))) DBUG_RETURN(HA_ERR_OUT_OF_MEM); @@ -6085,9 +6107,8 @@ int ha_partition::multi_range_key_create_key(RANGE_SEQ_IF *seq, if (!m_part_mrr_range_first[i]) { if (!(m_part_mrr_range_first[i]= (PARTITION_PART_KEY_MULTI_RANGE *) - my_multi_malloc(MYF(MY_WME | MY_ZEROFILL), - &m_part_mrr_range_current[i], - sizeof(PARTITION_PART_KEY_MULTI_RANGE), + my_multi_malloc(PSI_INSTRUMENT_ME, MYF(MY_WME | MY_ZEROFILL), + &m_part_mrr_range_current[i], sizeof(PARTITION_PART_KEY_MULTI_RANGE), NullS))) DBUG_RETURN(HA_ERR_OUT_OF_MEM); } @@ -6123,7 +6144,7 @@ int ha_partition::multi_range_key_create_key(RANGE_SEQ_IF *seq, if (m_mrr_range_current->key[0]) my_free(m_mrr_range_current->key[0]); if (!(m_mrr_range_current->key[0]= - (uchar *) my_malloc(length, MYF(MY_WME)))) + (uchar *) my_malloc(PSI_INSTRUMENT_ME, length, MYF(MY_WME)))) DBUG_RETURN(HA_ERR_OUT_OF_MEM); m_mrr_range_current->length[0]= length; } @@ -6147,7 +6168,7 @@ int ha_partition::multi_range_key_create_key(RANGE_SEQ_IF *seq, if (m_mrr_range_current->key[1]) my_free(m_mrr_range_current->key[1]); if (!(m_mrr_range_current->key[1]= - (uchar *) my_malloc(length, MYF(MY_WME)))) + (uchar *) my_malloc(PSI_INSTRUMENT_ME, length, MYF(MY_WME)))) DBUG_RETURN(HA_ERR_OUT_OF_MEM); m_mrr_range_current->length[1]= length; } @@ -6181,7 +6202,7 @@ int ha_partition::multi_range_key_create_key(RANGE_SEQ_IF *seq, { PARTITION_PART_KEY_MULTI_RANGE *tmp_part_mrr_range; if (!(tmp_part_mrr_range= (PARTITION_PART_KEY_MULTI_RANGE *) - my_malloc(sizeof(PARTITION_PART_KEY_MULTI_RANGE), + my_malloc(PSI_INSTRUMENT_ME, sizeof(PARTITION_PART_KEY_MULTI_RANGE), MYF(MY_WME | MY_ZEROFILL)))) DBUG_RETURN(HA_ERR_OUT_OF_MEM); @@ -6201,7 +6222,7 @@ int ha_partition::multi_range_key_create_key(RANGE_SEQ_IF *seq, /* Add end of range sentinel */ PARTITION_KEY_MULTI_RANGE *tmp_mrr_range; if (!(tmp_mrr_range= (PARTITION_KEY_MULTI_RANGE *) - my_malloc(sizeof(PARTITION_KEY_MULTI_RANGE), MYF(MY_WME)))) + my_malloc(PSI_INSTRUMENT_ME, sizeof(PARTITION_KEY_MULTI_RANGE), MYF(MY_WME)))) DBUG_RETURN(HA_ERR_OUT_OF_MEM); tmp_mrr_range->id= m_mrr_range_current->id + 1; @@ -6472,7 +6493,7 @@ int ha_partition::multi_range_read_init(RANGE_SEQ_IF *seq, if (m_mrr_full_buffer) my_free(m_mrr_full_buffer); if (!(m_mrr_full_buffer= - (uchar *) my_malloc(m_mrr_new_full_buffer_size, MYF(MY_WME)))) + (uchar *) my_malloc(PSI_INSTRUMENT_ME, m_mrr_new_full_buffer_size, MYF(MY_WME)))) { m_mrr_full_buffer_size= 0; error= HA_ERR_OUT_OF_MEM; @@ -6870,11 +6891,9 @@ FT_INFO *ha_partition::ft_init_ext(uint flags, uint inx, String *key) { FT_INFO **tmp_ft_info; if (!(ft_target= (st_partition_ft_info *) - my_multi_malloc(MYF(MY_WME | MY_ZEROFILL), - &ft_target, - sizeof(st_partition_ft_info), - &tmp_ft_info, - sizeof(FT_INFO *) * m_tot_parts, + my_multi_malloc(PSI_INSTRUMENT_ME, MYF(MY_WME | MY_ZEROFILL), + &ft_target, sizeof(st_partition_ft_info), + &tmp_ft_info, sizeof(FT_INFO *) * m_tot_parts, NullS))) { my_error(ER_OUT_OF_RESOURCES, MYF(ME_FATAL)); diff --git a/sql/handler.cc b/sql/handler.cc index 109c7dd01bf..7f79ce98eec 100644 --- a/sql/handler.cc +++ b/sql/handler.cc @@ -361,7 +361,8 @@ int ha_init_errors(void) /* Allocate a pointer array for the error message strings. */ /* Zerofill it to avoid uninitialized gaps. */ - if (! (handler_errmsgs= (const char**) my_malloc(HA_ERR_ERRORS * sizeof(char*), + if (! (handler_errmsgs= (const char**) my_malloc(key_memory_handler_errmsgs, + HA_ERR_ERRORS * sizeof(char*), MYF(MY_WME | MY_ZEROFILL)))) return 1; @@ -531,7 +532,7 @@ int ha_initialize_handlerton(st_plugin_int *plugin) DBUG_ENTER("ha_initialize_handlerton"); DBUG_PRINT("plugin", ("initialize plugin: '%s'", plugin->name.str)); - hton= (handlerton *)my_malloc(sizeof(handlerton), + hton= (handlerton *)my_malloc(key_memory_handlerton, sizeof(handlerton), MYF(MY_WME | MY_ZEROFILL)); if (hton == NULL) { @@ -2216,7 +2217,7 @@ int ha_recover(HASH *commit_list) info.list==0 && info.len > MIN_XID_LIST_SIZE; info.len/=2) { DBUG_EXECUTE_IF("min_xa_len", info.len = 16;); - info.list=(XID *)my_malloc(info.len*sizeof(XID), MYF(0)); + info.list=(XID *)my_malloc(key_memory_XID, info.len*sizeof(XID), MYF(0)); } if (!info.list) { @@ -4941,7 +4942,7 @@ void handler::update_global_table_stats() table->s->table_cache_key.length))) { if (!(table_stats = ((TABLE_STATS*) - my_malloc(sizeof(TABLE_STATS), + my_malloc(PSI_INSTRUMENT_ME, sizeof(TABLE_STATS), MYF(MY_WME | MY_ZEROFILL))))) { /* Out of memory error already given */ @@ -5006,7 +5007,7 @@ void handler::update_global_index_stats() key_length))) { if (!(index_stats = ((INDEX_STATS*) - my_malloc(sizeof(INDEX_STATS), + my_malloc(PSI_INSTRUMENT_ME, sizeof(INDEX_STATS), MYF(MY_WME | MY_ZEROFILL))))) goto end; // Error is already given @@ -7221,7 +7222,7 @@ int del_global_table_stat(THD *thd, const LEX_CSTRING *db, const LEX_CSTRING *ta cache_key_length= db->length + 1 + table->length + 1; - if(!(cache_key= (uchar *)my_malloc(cache_key_length, + if(!(cache_key= (uchar *)my_malloc(PSI_INSTRUMENT_ME, cache_key_length, MYF(MY_WME | MY_ZEROFILL)))) { /* Out of memory error already given */ diff --git a/sql/hash_filo.h b/sql/hash_filo.h index d815c428ac6..864e91594b2 100644 --- a/sql/hash_filo.h +++ b/sql/hash_filo.h @@ -48,6 +48,7 @@ private: class hash_filo { private: + PSI_memory_key m_psi_key; const uint key_offset, key_length; const my_hash_get_key get_key; /** Size of this hash table. */ @@ -61,15 +62,13 @@ public: mysql_mutex_t lock; HASH cache; - hash_filo(uint size_arg, uint key_offset_arg , uint key_length_arg, - my_hash_get_key get_key_arg, my_hash_free_key free_element_arg, - CHARSET_INFO *hash_charset_arg) - :key_offset(key_offset_arg), key_length(key_length_arg), - get_key(get_key_arg), m_size(size_arg), - free_element(free_element_arg),init(0), - hash_charset(hash_charset_arg), - first_link(NULL), - last_link(NULL) + hash_filo(PSI_memory_key psi_key, uint size_arg, uint key_offset_arg, + uint key_length_arg, my_hash_get_key get_key_arg, + my_hash_free_key free_element_arg, CHARSET_INFO *hash_charset_arg) + : m_psi_key(psi_key), key_offset(key_offset_arg), + key_length(key_length_arg), get_key(get_key_arg), m_size(size_arg), + free_element(free_element_arg),init(0), hash_charset(hash_charset_arg), + first_link(NULL), last_link(NULL) { bzero((char*) &cache,sizeof(cache)); } @@ -96,7 +95,7 @@ public: last_link= NULL; (void) my_hash_free(&cache); (void) my_hash_init(&cache,hash_charset,m_size,key_offset, - key_length, get_key, free_element,0); + key_length, get_key, free_element, 0, m_psi_key); if (!locked) mysql_mutex_unlock(&lock); } @@ -202,10 +201,10 @@ public: template <class T> class Hash_filo: public hash_filo { public: - Hash_filo(uint size_arg, uint key_offset_arg, uint key_length_arg, - my_hash_get_key get_key_arg, my_hash_free_key free_element_arg, - CHARSET_INFO *hash_charset_arg) : - hash_filo(size_arg, key_offset_arg, key_length_arg, + Hash_filo(PSI_memory_key psi_key, uint size_arg, uint key_offset_arg, uint + key_length_arg, my_hash_get_key get_key_arg, my_hash_free_key + free_element_arg, CHARSET_INFO *hash_charset_arg) : + hash_filo(psi_key, size_arg, key_offset_arg, key_length_arg, get_key_arg, free_element_arg, hash_charset_arg) {} T* first() { return (T*)hash_filo::first(); } T* last() { return (T*)hash_filo::last(); } diff --git a/sql/hostname.cc b/sql/hostname.cc index 968914fd56e..edf31c11081 100644 --- a/sql/hostname.cc +++ b/sql/hostname.cc @@ -150,10 +150,9 @@ bool hostname_cache_init() Host_entry tmp; uint key_offset= (uint) ((char*) (&tmp.ip_key) - (char*) &tmp); - if (!(hostname_cache= new Hash_filo<Host_entry>(host_cache_size, - key_offset, HOST_ENTRY_KEY_SIZE, - NULL, (my_hash_free_key) free, - &my_charset_bin))) + if (!(hostname_cache= new Hash_filo<Host_entry>(key_memory_host_cache_hostname, + host_cache_size, key_offset, HOST_ENTRY_KEY_SIZE, + NULL, (my_hash_free_key) free, &my_charset_bin))) return 1; hostname_cache->clear(); @@ -476,7 +475,8 @@ int ip_to_hostname(struct sockaddr_storage *ip_storage, if (entry->m_host_validated) { if (entry->m_hostname_length) - *hostname= my_strdup(entry->m_hostname, MYF(0)); + *hostname= my_strdup(key_memory_host_cache_hostname, + entry->m_hostname, MYF(0)); DBUG_PRINT("info",("IP (%s) has been found in the cache. " "Hostname: '%s'", @@ -926,7 +926,8 @@ int ip_to_hostname(struct sockaddr_storage *ip_storage, { /* Copy host name string to be stored in the cache. */ - *hostname= my_strdup(hostname_buffer, MYF(0)); + *hostname= my_strdup(key_memory_host_cache_hostname, + hostname_buffer, MYF(0)); if (!*hostname) { diff --git a/sql/item.cc b/sql/item.cc index c7454b789fb..89e23173b0e 100644 --- a/sql/item.cc +++ b/sql/item.cc @@ -2771,7 +2771,8 @@ Item_sp::execute_impl(THD *thd, Item **args, uint arg_count) (m_sp->agg_type() == NOT_AGGREGATE && !func_ctx)); if (!func_ctx) { - init_sql_alloc(&sp_mem_root, "Item_sp", MEM_ROOT_BLOCK_SIZE, 0, MYF(0)); + init_sql_alloc(key_memory_sp_head_call_root, &sp_mem_root, + MEM_ROOT_BLOCK_SIZE, 0, MYF(0)); *sp_query_arena= Query_arena(&sp_mem_root, Query_arena::STMT_INITIALIZED_FOR_SP); } diff --git a/sql/item_create.cc b/sql/item_create.cc index 2bd605286d0..e437b3fc724 100644 --- a/sql/item_create.cc +++ b/sql/item_create.cc @@ -5624,7 +5624,7 @@ int item_create_init() 0, (my_hash_get_key) get_native_fct_hash_key, NULL, /* Nothing to free */ - MYF(0))) + MYF(0), key_memory_native_functions)) DBUG_RETURN(1); if (native_func_registry_array.append_to_hash(&native_functions_hash)) diff --git a/sql/item_func.cc b/sql/item_func.cc index a263391a41a..da7b523d830 100644 --- a/sql/item_func.cc +++ b/sql/item_func.cc @@ -4020,7 +4020,8 @@ longlong Item_func_get_lock::val_int() /* HASH entries are of type User_level_lock. */ if (! my_hash_inited(&thd->ull_hash) && my_hash_init(&thd->ull_hash, &my_charset_bin, - 16 /* small hash */, 0, 0, ull_get_key, NULL, 0)) + 16 /* small hash */, 0, 0, ull_get_key, NULL, 0, + key_memory_User_level_lock)) { DBUG_RETURN(0); } @@ -4052,7 +4053,8 @@ longlong Item_func_get_lock::val_int() DBUG_RETURN(0); } - ull= (User_level_lock*) my_malloc(sizeof(User_level_lock), + ull= (User_level_lock*) my_malloc(key_memory_User_level_lock, + sizeof(User_level_lock), MYF(MY_WME|MY_THREAD_SPECIFIC)); if (ull == NULL) { @@ -4420,7 +4422,7 @@ user_var_entry *get_variable(HASH *hash, LEX_CSTRING *name, size_t size=ALIGN_SIZE(sizeof(user_var_entry))+name->length+1+extra_size; if (!my_hash_inited(hash)) return 0; - if (!(entry = (user_var_entry*) my_malloc(size, + if (!(entry = (user_var_entry*) my_malloc(key_memory_user_var_entry, size, MYF(MY_WME | ME_FATAL | MY_THREAD_SPECIFIC)))) return 0; @@ -4680,7 +4682,8 @@ update_hash(user_var_entry *entry, bool set_null, void *ptr, size_t length, char *pos= (char*) entry+ ALIGN_SIZE(sizeof(user_var_entry)); if (entry->value == pos) entry->value=0; - entry->value= (char*) my_realloc(entry->value, length, + entry->value= (char*) my_realloc(key_memory_user_var_entry_value, + entry->value, length, MYF(MY_ALLOW_ZERO_PTR | MY_WME | ME_FATAL | MY_THREAD_SPECIFIC)); if (!entry->value) @@ -6793,7 +6796,7 @@ longlong Item_func_nextval::val_int() if (!(entry= ((SEQUENCE_LAST_VALUE*) my_hash_search(&thd->sequences, (uchar*) key, length)))) { - if (!(key= (char*) my_memdup(key, length, MYF(MY_WME))) || + if (!(key= (char*) my_memdup(PSI_INSTRUMENT_ME, key, length, MYF(MY_WME))) || !(entry= new SEQUENCE_LAST_VALUE((uchar*) key, length))) { /* EOM, error given */ diff --git a/sql/item_subselect.cc b/sql/item_subselect.cc index 4b781152c33..e494e9d84e1 100644 --- a/sql/item_subselect.cc +++ b/sql/item_subselect.cc @@ -5808,8 +5808,9 @@ bool Ordered_key::alloc_keys_buffers() { DBUG_ASSERT(key_buff_elements > 0); - if (!(key_buff= (rownum_t*) my_malloc((size_t)(key_buff_elements * - sizeof(rownum_t)), MYF(MY_WME | MY_THREAD_SPECIFIC)))) + if (!(key_buff= (rownum_t*) my_malloc(PSI_INSTRUMENT_ME, + static_cast<size_t>(key_buff_elements * sizeof(rownum_t)), + MYF(MY_WME | MY_THREAD_SPECIFIC)))) return TRUE; /* @@ -6240,8 +6241,9 @@ subselect_rowid_merge_engine::init(MY_BITMAP *non_null_key_parts, sizeof(Ordered_key*))) || !(null_bitmaps= (MY_BITMAP**) thd->alloc(merge_keys_count * sizeof(MY_BITMAP*))) || - !(row_num_to_rowid= (uchar*) my_malloc((size_t)(row_count * rowid_length), - MYF(MY_WME | MY_THREAD_SPECIFIC)))) + !(row_num_to_rowid= (uchar*) my_malloc(PSI_INSTRUMENT_ME, + static_cast<size_t>(row_count * rowid_length), + MYF(MY_WME | MY_THREAD_SPECIFIC)))) return TRUE; /* Create the only non-NULL key if there is any. */ diff --git a/sql/keycaches.cc b/sql/keycaches.cc index 60049cdd67d..10bec7c1de8 100644 --- a/sql/keycaches.cc +++ b/sql/keycaches.cc @@ -23,6 +23,9 @@ NAMED_ILIST key_caches; NAMED_ILIST rpl_filters; +extern "C" PSI_memory_key key_memory_KEY_CACHE; +extern PSI_memory_key key_memory_NAMED_ILINK_name; + /** ilink (intrusive list element) with a name */ @@ -37,7 +40,8 @@ public: size_t name_length_arg, uchar* data_arg) :name_length(name_length_arg), data(data_arg) { - name= my_strndup(name_arg, name_length, MYF(MY_WME)); + name= my_strndup(key_memory_NAMED_ILINK_name, name_arg, name_length, + MYF(MY_WME)); links->push_back(this); } inline bool cmp(const char *name_cmp, size_t length) @@ -118,8 +122,8 @@ KEY_CACHE *create_key_cache(const char *name, size_t length) DBUG_ENTER("create_key_cache"); DBUG_PRINT("enter",("name: %.*s", (int)length, name)); - if ((key_cache= (KEY_CACHE*) my_malloc(sizeof(KEY_CACHE), - MYF(MY_ZEROFILL | MY_WME)))) + if ((key_cache= (KEY_CACHE*) my_malloc(key_memory_KEY_CACHE, + sizeof(KEY_CACHE), MYF(MY_ZEROFILL | MY_WME)))) { if (!new NAMED_ILINK(&key_caches, name, length, (uchar*) key_cache)) { diff --git a/sql/lock.cc b/sql/lock.cc index 6f86c0a38f6..92f4ea0c279 100644 --- a/sql/lock.cc +++ b/sql/lock.cc @@ -645,7 +645,7 @@ MYSQL_LOCK *mysql_lock_merge(MYSQL_LOCK *a,MYSQL_LOCK *b) a->lock_count, b->lock_count)); if (!(sql_lock= (MYSQL_LOCK*) - my_malloc(sizeof(*sql_lock)+ + my_malloc(key_memory_MYSQL_LOCK, sizeof(*sql_lock) + sizeof(THR_LOCK_DATA*)*((a->lock_count+b->lock_count)*2) + sizeof(TABLE*)*(a->table_count+b->table_count),MYF(MY_WME)))) DBUG_RETURN(0); // Fatal error @@ -764,7 +764,8 @@ MYSQL_LOCK *get_lock_data(THD *thd, TABLE **table_ptr, uint count, uint flags) sizeof(table_ptr) * table_count; if (!(sql_lock= (MYSQL_LOCK*) (flags & GET_LOCK_ON_THD ? thd->alloc(amount) : - my_malloc(amount, MYF(0))))) + my_malloc(key_memory_MYSQL_LOCK, amount, + MYF(0))))) DBUG_RETURN(0); locks= locks_buf= sql_lock->locks= (THR_LOCK_DATA**) (sql_lock + 1); to= table_buf= sql_lock->table= (TABLE**) (locks + lock_count * 2); diff --git a/sql/log.cc b/sql/log.cc index b2d971f3a4f..935bfda79d9 100644 --- a/sql/log.cc +++ b/sql/log.cc @@ -253,7 +253,7 @@ void make_default_log_name(char **out, const char* log_ext, bool once) else { my_free(*out); - *out= my_strdup(buff, MYF(MY_WME)); + *out= my_strdup(PSI_INSTRUMENT_ME, buff, MYF(MY_WME)); } } @@ -2653,7 +2653,7 @@ bool MYSQL_LOG::open( write_error= 0; - if (!(name= my_strdup(log_name, MYF(MY_WME)))) + if (!(name= my_strdup(key_memory_MYSQL_LOG_name, log_name, MYF(MY_WME)))) { name= (char *)log_name; // for the error message goto err; @@ -4443,14 +4443,16 @@ int MYSQL_BIN_LOG::purge_first_log(Relay_log_info* rli, bool included) { rli->last_inuse_relaylog= NULL; included= 1; - to_purge_if_included= my_strdup(ir->name, MYF(0)); + to_purge_if_included= my_strdup(key_memory_Relay_log_info_group_relay_log_name, + ir->name, MYF(0)); } rli->free_inuse_relaylog(ir); ir= next; } rli->inuse_relaylog_list= ir; if (ir) - to_purge_if_included= my_strdup(ir->name, MYF(0)); + to_purge_if_included= my_strdup(key_memory_Relay_log_info_group_relay_log_name, + ir->name, MYF(0)); /* Read the next log file name from the index file and pass it back to @@ -5589,7 +5591,8 @@ binlog_cache_mngr *THD::binlog_setup_trx_data() if (cache_mngr) DBUG_RETURN(cache_mngr); // Already set up - cache_mngr= (binlog_cache_mngr*) my_malloc(sizeof(binlog_cache_mngr), MYF(MY_ZEROFILL)); + cache_mngr= (binlog_cache_mngr*) my_malloc(key_memory_binlog_cache_mngr, + sizeof(binlog_cache_mngr), MYF(MY_ZEROFILL)); if (!cache_mngr || open_cached_file(&cache_mngr->stmt_cache.cache_log, mysql_tmpdir, LOG_PREFIX, (size_t)binlog_stmt_cache_size, MYF(MY_WME)) || @@ -9109,7 +9112,8 @@ int TC_LOG_MMAP::open(const char *opt_name) npages=(uint)file_length/tc_log_page_size; if (npages < 3) // to guarantee non-empty pool goto err; - if (!(pages=(PAGE *)my_malloc(npages*sizeof(PAGE), MYF(MY_WME|MY_ZEROFILL)))) + if (!(pages=(PAGE *)my_malloc(key_memory_TC_LOG_MMAP_pages, + npages*sizeof(PAGE), MYF(MY_WME|MY_ZEROFILL)))) goto err; inited=3; for (pg=pages, i=0; i < npages; i++, pg++) @@ -9419,7 +9423,8 @@ int TC_LOG_MMAP::unlog(ulong cookie, my_xid xid) { uint32 size= sizeof(*pending_checkpoint) + sizeof(ulong) * (ncookies - 1); if (!(pending_checkpoint= - (pending_cookies *)my_malloc(size, MYF(MY_ZEROFILL)))) + (pending_cookies *)my_malloc(PSI_INSTRUMENT_ME, size, + MYF(MY_ZEROFILL)))) { my_error(ER_OUTOFMEMORY, MYF(0), size); mysql_mutex_unlock(&LOCK_pending_checkpoint); @@ -9559,7 +9564,7 @@ int TC_LOG_MMAP::recover() } if (my_hash_init(&xids, &my_charset_bin, tc_log_page_size/3, 0, - sizeof(my_xid), 0, 0, MYF(0))) + sizeof(my_xid), 0, 0, MYF(0), PSI_INSTRUMENT_ME)) goto err1; for ( ; p < end_p ; p++) @@ -10073,12 +10078,13 @@ int TC_LOG_BINLOG::recover(LOG_INFO *linfo, const char *last_log_name, if (! fdle->is_valid() || (do_xa && my_hash_init(&xids, &my_charset_bin, TC_LOG_PAGE_SIZE/3, 0, - sizeof(my_xid), 0, 0, MYF(0)))) + sizeof(my_xid), 0, 0, MYF(0), + key_memory_binlog_recover_exec))) goto err1; if (do_xa) - init_alloc_root(&mem_root, "TC_LOG_BINLOG", TC_LOG_PAGE_SIZE, - TC_LOG_PAGE_SIZE, MYF(0)); + init_alloc_root(key_memory_binlog_recover_exec, &mem_root, + TC_LOG_PAGE_SIZE, TC_LOG_PAGE_SIZE, MYF(0)); fdle->flags&= ~LOG_EVENT_BINLOG_IN_USE_F; // abort on the first error diff --git a/sql/log.h b/sql/log.h index fa8b9fca37e..52e4d31ddd9 100644 --- a/sql/log.h +++ b/sql/log.h @@ -587,7 +587,7 @@ public: :binlog_id(0), xid_count(0), notify_count(0) { binlog_name_len= log_file_name_len; - binlog_name= (char *) my_malloc(binlog_name_len, MYF(MY_ZEROFILL)); + binlog_name= (char *) my_malloc(PSI_INSTRUMENT_ME, binlog_name_len, MYF(MY_ZEROFILL)); if (binlog_name) memcpy(binlog_name, log_file_name, binlog_name_len); } diff --git a/sql/log_event.cc b/sql/log_event.cc index 4c1c18fffff..7ee38a007d1 100644 --- a/sql/log_event.cc +++ b/sql/log_event.cc @@ -56,6 +56,10 @@ #define my_b_write_string(A, B) my_b_write((A), (uchar*)(B), (uint) (sizeof(B) - 1)) +PSI_memory_key key_memory_log_event; +PSI_memory_key key_memory_Incident_log_event_message; +PSI_memory_key key_memory_Rows_query_log_event_rows_query; + /** BINLOG_CHECKSUM variable. */ @@ -410,7 +414,7 @@ query_event_uncompress(const Format_description_log_event *description_event, } else { - new_dst = (char *)my_malloc(alloc_size, MYF(MY_WME)); + new_dst = (char *)my_malloc(PSI_INSTRUMENT_ME, alloc_size, MYF(MY_WME)); if (!new_dst) return 1; @@ -532,7 +536,7 @@ row_log_event_uncompress(const Format_description_log_event *description_event, } else { - new_dst = (char *)my_malloc(alloc_size, MYF(MY_WME)); + new_dst = (char *)my_malloc(PSI_INSTRUMENT_ME, alloc_size, MYF(MY_WME)); if (!new_dst) return 1; @@ -873,7 +877,7 @@ int Log_event::read_log_event(IO_CACHE* file, String* packet, */ sz += MY_AES_BLOCK_SIZE; #endif - char *newpkt= (char*)my_malloc(sz, MYF(MY_WME)); + char *newpkt= (char*)my_malloc(PSI_INSTRUMENT_ME, sz, MYF(MY_WME)); if (!newpkt) DBUG_RETURN(LOG_READ_MEM); memcpy(newpkt, packet->ptr(), ev_offset); @@ -1665,7 +1669,8 @@ Query_log_event::Query_log_event(const char* buf, uint event_len, */ #if !defined(MYSQL_CLIENT) && defined(HAVE_QUERY_CACHE) - if (!(start= data_buf = (Log_event::Byte*) my_malloc(catalog_len + 1 + if (!(start= data_buf = (Log_event::Byte*) my_malloc(PSI_INSTRUMENT_ME, + catalog_len + 1 + time_zone_len + 1 + user.length + 1 + host.length + 1 @@ -1676,7 +1681,8 @@ Query_log_event::Query_log_event(const char* buf, uint event_len, + QUERY_CACHE_FLAGS_SIZE, MYF(MY_WME)))) #else - if (!(start= data_buf = (Log_event::Byte*) my_malloc(catalog_len + 1 + if (!(start= data_buf = (Log_event::Byte*) my_malloc(PSI_INSTRUMENT_ME, + catalog_len + 1 + time_zone_len + 1 + user.length + 1 + host.length + 1 @@ -1783,8 +1789,8 @@ Query_compressed_log_event::Query_compressed_log_event(const char *buf, } /* Reserve one byte for '\0' */ - query_buf = (Log_event::Byte*)my_malloc(ALIGN_SIZE(un_len + 1), - MYF(MY_WME)); + query_buf = (Log_event::Byte*)my_malloc(PSI_INSTRUMENT_ME, + ALIGN_SIZE(un_len + 1), MYF(MY_WME)); if(query_buf && !binlog_buf_uncompress(query, (char *)query_buf, q_len, &un_len)) { @@ -2033,7 +2039,8 @@ Format_description_log_event(uint8 binlog_ver, const char* server_ver) common_header_len= LOG_EVENT_HEADER_LEN; number_of_event_types= LOG_EVENT_TYPES; /* we'll catch my_malloc() error in is_valid() */ - post_header_len=(uint8*) my_malloc(number_of_event_types*sizeof(uint8) + post_header_len=(uint8*) my_malloc(PSI_INSTRUMENT_ME, + number_of_event_types*sizeof(uint8) + BINLOG_CHECKSUM_ALG_DESC_LEN, MYF(0)); /* @@ -2159,8 +2166,8 @@ Format_description_log_event(uint8 binlog_ver, const char* server_ver) make the slave detect less corruptions). */ number_of_event_types= FORMAT_DESCRIPTION_EVENT - 1; - post_header_len=(uint8*) my_malloc(number_of_event_types*sizeof(uint8), - MYF(0)); + post_header_len=(uint8*) my_malloc(PSI_INSTRUMENT_ME, + number_of_event_types*sizeof(uint8), MYF(0)); if (post_header_len) { post_header_len[START_EVENT_V3-1]= START_V3_HEADER_LEN; @@ -2228,7 +2235,8 @@ Format_description_log_event(const char* buf, common_header_len, number_of_event_types)); /* If alloc fails, we'll detect it in is_valid() */ - post_header_len= (uint8*) my_memdup((uchar*)buf+ST_COMMON_HEADER_LEN_OFFSET+1, + post_header_len= (uint8*) my_memdup(PSI_INSTRUMENT_ME, + buf+ST_COMMON_HEADER_LEN_OFFSET+1, number_of_event_types* sizeof(*post_header_len), MYF(0)); @@ -2517,7 +2525,7 @@ Rotate_log_event::Rotate_log_event(const char* buf, uint event_len, ident_len= (uint)(event_len - (LOG_EVENT_MINIMAL_HEADER_LEN + post_header_len)); ident_offset= post_header_len; set_if_smaller(ident_len,FN_REFLEN-1); - new_log_ident= my_strndup(buf + ident_offset, (uint) ident_len, MYF(MY_WME)); + new_log_ident= my_strndup(PSI_INSTRUMENT_ME, buf + ident_offset, (uint) ident_len, MYF(MY_WME)); DBUG_PRINT("debug", ("new_log_ident: '%s'", new_log_ident)); DBUG_VOID_RETURN; } @@ -2544,7 +2552,7 @@ Binlog_checkpoint_log_event::Binlog_checkpoint_log_event( binlog_file_len= uint4korr(buf); if (event_len - (header_size + post_header_len) < binlog_file_len) return; - binlog_file_name= my_strndup(buf + post_header_len, binlog_file_len, + binlog_file_name= my_strndup(PSI_INSTRUMENT_ME, buf + post_header_len, binlog_file_len, MYF(MY_WME)); return; } @@ -2603,8 +2611,8 @@ Gtid_list_log_event::Gtid_list_log_event(const char *buf, uint event_len, gl_flags= val & ((uint32)0xf << 28); buf+= 4; if (event_len - (header_size + post_header_len) < count*element_size || - (!(list= (rpl_gtid *)my_malloc(count*sizeof(*list) + (count == 0), - MYF(MY_WME))))) + (!(list= (rpl_gtid *)my_malloc(PSI_INSTRUMENT_ME, + count*sizeof(*list) + (count == 0), MYF(MY_WME))))) return; for (i= 0; i < count; ++i) @@ -2621,7 +2629,8 @@ Gtid_list_log_event::Gtid_list_log_event(const char *buf, uint event_len, if ((gl_flags & FLAG_IGN_GTIDS)) { uint32 i; - if (!(sub_id_list= (uint64 *)my_malloc(count*sizeof(uint64), MYF(MY_WME)))) + if (!(sub_id_list= (uint64 *)my_malloc(PSI_INSTRUMENT_ME, + count*sizeof(uint64), MYF(MY_WME)))) { my_free(list); list= NULL; @@ -2678,8 +2687,8 @@ Gtid_list_log_event::peek(const char *event_start, size_t event_len, if (event_len < (uint32)fdev->common_header_len + GTID_LIST_HEADER_LEN + 16 * count) return true; - if (!(gtid_list= (rpl_gtid *)my_malloc(sizeof(rpl_gtid)*count + (count == 0), - MYF(MY_WME)))) + if (!(gtid_list= (rpl_gtid *)my_malloc(PSI_INSTRUMENT_ME, + sizeof(rpl_gtid)*count + (count == 0), MYF(MY_WME)))) return true; *out_gtid_list= gtid_list; *out_list_len= count; @@ -2886,7 +2895,7 @@ Create_file_log_event::Create_file_log_event(const char* buf, uint len, uint header_len= description_event->common_header_len; uint8 load_header_len= description_event->post_header_len[LOAD_EVENT-1]; uint8 create_file_header_len= description_event->post_header_len[CREATE_FILE_EVENT-1]; - if (!(event_buf= (char*) my_memdup(buf, len, MYF(MY_WME))) || + if (!(event_buf= (char*) my_memdup(PSI_INSTRUMENT_ME, buf, len, MYF(MY_WME))) || copy_log_event(event_buf,len, (((uchar)buf[EVENT_TYPE_OFFSET] == LOAD_EVENT) ? load_header_len + header_len : @@ -3188,7 +3197,7 @@ Rows_log_event::Rows_log_event(const char *buf, uint event_len, /* Just store/use the first tag of this type, skip others */ if (likely(!m_extra_row_data)) { - m_extra_row_data= (uchar*) my_malloc(infoLen, + m_extra_row_data= (uchar*) my_malloc(PSI_INSTRUMENT_ME, infoLen, MYF(MY_WME)); if (likely(m_extra_row_data != NULL)) { @@ -3277,7 +3286,7 @@ Rows_log_event::Rows_log_event(const char *buf, uint event_len, DBUG_PRINT("info",("m_table_id: %llu m_flags: %d m_width: %lu data_size: %lu", m_table_id, m_flags, m_width, (ulong) data_size)); - m_rows_buf= (uchar*) my_malloc(data_size, MYF(MY_WME)); + m_rows_buf= (uchar*) my_malloc(PSI_INSTRUMENT_ME, data_size, MYF(MY_WME)); if (likely((bool)m_rows_buf)) { #if !defined(MYSQL_CLIENT) && defined(HAVE_REPLICATION) @@ -3300,7 +3309,7 @@ void Rows_log_event::uncompress_buf() if (!un_len) return; - uchar *new_buf= (uchar*) my_malloc(ALIGN_SIZE(un_len), MYF(MY_WME)); + uchar *new_buf= (uchar*) my_malloc(PSI_INSTRUMENT_ME, ALIGN_SIZE(un_len), MYF(MY_WME)); if (new_buf) { if(!binlog_buf_uncompress((char *)m_rows_buf, (char *)new_buf, @@ -3535,7 +3544,7 @@ Table_map_log_event::Table_map_log_event(const char *buf, uint event_len, m_colcnt, (long) (ptr_colcnt-(const uchar*)vpart))); /* Allocate mem for all fields in one go. If fails, caught in is_valid() */ - m_memory= (uchar*) my_multi_malloc(MYF(MY_WME), + m_memory= (uchar*) my_multi_malloc(PSI_INSTRUMENT_ME, MYF(MY_WME), &m_dbnam, (uint) m_dblen + 1, &m_tblnam, (uint) m_tbllen + 1, &m_coltype, (uint) m_colcnt, @@ -3554,7 +3563,7 @@ Table_map_log_event::Table_map_log_event(const char *buf, uint event_len, if (m_field_metadata_size <= (m_colcnt * 2)) { uint num_null_bytes= (m_colcnt + 7) / 8; - m_meta_memory= (uchar *)my_multi_malloc(MYF(MY_WME), + m_meta_memory= (uchar *)my_multi_malloc(PSI_INSTRUMENT_ME, MYF(MY_WME), &m_null_bits, num_null_bytes, &m_field_metadata, m_field_metadata_size, NULL); @@ -3578,7 +3587,7 @@ Table_map_log_event::Table_map_log_event(const char *buf, uint event_len, { m_optional_metadata_len= event_len - bytes_read; m_optional_metadata= - static_cast<unsigned char*>(my_malloc(m_optional_metadata_len, MYF(MY_WME))); + static_cast<unsigned char*>(my_malloc(PSI_INSTRUMENT_ME, m_optional_metadata_len, MYF(MY_WME))); memcpy(m_optional_metadata, ptr_after_colcnt, m_optional_metadata_len); } } @@ -3958,7 +3967,7 @@ Incident_log_event::Incident_log_event(const char *buf, uint event_len, m_incident= INCIDENT_NONE; DBUG_VOID_RETURN; } - if (!(m_message.str= (char*) my_malloc(len+1, MYF(MY_WME)))) + if (!(m_message.str= (char*) my_malloc(key_memory_log_event, len+1, MYF(MY_WME)))) { /* Mark this event invalid */ m_incident= INCIDENT_NONE; diff --git a/sql/log_event.h b/sql/log_event.h index f2d27282a6f..67cf27b60a0 100644 --- a/sql/log_event.h +++ b/sql/log_event.h @@ -1357,7 +1357,8 @@ public: static void *operator new(size_t size) { - return (void*) my_malloc((uint)size, MYF(MY_WME|MY_FAE)); + extern PSI_memory_key key_memory_log_event; + return my_malloc(key_memory_log_event, size, MYF(MY_WME|MY_FAE)); } static void operator delete(void *ptr, size_t) @@ -5368,11 +5369,12 @@ public: Incident_log_event(THD *thd_arg, Incident incident, const LEX_CSTRING *msg) : Log_event(thd_arg, 0, FALSE), m_incident(incident) { + extern PSI_memory_key key_memory_Incident_log_event_message; DBUG_ENTER("Incident_log_event::Incident_log_event"); DBUG_PRINT("enter", ("m_incident: %d", m_incident)); m_message.length= 0; - if (unlikely(!(m_message.str= (char*) my_malloc(msg->length+1, - MYF(MY_WME))))) + if (!(m_message.str= (char*) my_malloc(key_memory_Incident_log_event_message, + msg->length + 1, MYF(MY_WME)))) { /* Mark this event invalid */ m_incident= INCIDENT_NONE; diff --git a/sql/log_event_client.cc b/sql/log_event_client.cc index cae4842355a..83a7eaf06b0 100644 --- a/sql/log_event_client.cc +++ b/sql/log_event_client.cc @@ -1104,7 +1104,7 @@ void Rows_log_event::change_to_flashback_event(PRINT_EVENT_INFO *print_event_inf if (((get_general_type_code() == WRITE_ROWS_EVENT) && (m_rows_buf==m_rows_end))) goto end; - (void) my_init_dynamic_array(&rows_arr, sizeof(LEX_STRING), 8, 8, MYF(0)); + (void) my_init_dynamic_array(&rows_arr, PSI_NOT_INSTRUMENTED, sizeof(LEX_STRING), 8, 8, MYF(0)); for (uchar *value= m_rows_buf; value < m_rows_end; ) { @@ -1119,7 +1119,7 @@ void Rows_log_event::change_to_flashback_event(PRINT_EVENT_INFO *print_event_inf } value+= length1; - swap_buff1= (uchar *) my_malloc(length1, MYF(0)); + swap_buff1= (uchar *) my_malloc(PSI_NOT_INSTRUMENTED, length1, MYF(0)); if (!swap_buff1) { fprintf(stderr, "\nError: Out of memory. " @@ -1142,7 +1142,7 @@ void Rows_log_event::change_to_flashback_event(PRINT_EVENT_INFO *print_event_inf } value+= length2; - swap_buff2= (uchar *) my_malloc(length2, MYF(0)); + swap_buff2= (uchar *) my_malloc(PSI_NOT_INSTRUMENTED, length2, MYF(0)); if (!swap_buff2) { fprintf(stderr, "\nError: Out of memory. " @@ -1170,7 +1170,7 @@ void Rows_log_event::change_to_flashback_event(PRINT_EVENT_INFO *print_event_inf LEX_STRING one_row; one_row.length= length1 + length2; - one_row.str= (char *) my_malloc(one_row.length, MYF(0)); + one_row.str= (char *) my_malloc(PSI_NOT_INSTRUMENTED, one_row.length, MYF(0)); memcpy(one_row.str, start_pos, one_row.length); if (one_row.str == NULL || push_dynamic(&rows_arr, (uchar *) &one_row)) { @@ -1637,7 +1637,7 @@ bool Log_event::print_base64(IO_CACHE* file, { size_t const tmp_str_sz= my_base64_needed_encoded_length((int) size); char *tmp_str; - if (!(tmp_str= (char *) my_malloc(tmp_str_sz, MYF(MY_WME)))) + if (!(tmp_str= (char *) my_malloc(PSI_NOT_INSTRUMENTED, tmp_str_sz, MYF(MY_WME)))) goto err; if (my_base64_encode(ptr, (size_t) size, tmp_str)) @@ -2491,7 +2491,7 @@ bool User_var_log_event::print(FILE* file, PRINT_EVENT_INFO* print_event_info) bool error; // 2 hex digits / byte - hex_str= (char *) my_malloc(2 * val_len + 1 + 3, MYF(MY_WME)); + hex_str= (char *) my_malloc(PSI_NOT_INSTRUMENTED, 2 * val_len + 1 + 3, MYF(MY_WME)); if (!hex_str) goto err; str_to_hex(hex_str, val, val_len); @@ -2853,7 +2853,7 @@ bool copy_cache_to_string_wrapped(IO_CACHE *cache, if (reinit_io_cache(cache, READ_CACHE, 0L, FALSE, FALSE)) goto err; - if (!(to->str= (char*) my_malloc((size_t)cache->end_of_file + fmt_size, + if (!(to->str= (char*) my_malloc(PSI_NOT_INSTRUMENTED, (size_t)cache->end_of_file + fmt_size, MYF(0)))) { perror("Out of memory: can't allocate memory in " @@ -3108,7 +3108,7 @@ int Table_map_log_event::rewrite_db(const char* new_db, size_t new_len, // Create new temp_buf ulong event_cur_len= uint4korr(temp_buf + EVENT_LEN_OFFSET); ulong event_new_len= event_cur_len + len_diff; - char* new_temp_buf= (char*) my_malloc(event_new_len, MYF(MY_WME)); + char* new_temp_buf= (char*) my_malloc(PSI_NOT_INSTRUMENTED, event_new_len, MYF(MY_WME)); if (!new_temp_buf) { @@ -3150,7 +3150,7 @@ int Table_map_log_event::rewrite_db(const char* new_db, size_t new_len, char const* tblnam= m_tblnam; uchar* coltype= m_coltype; - m_memory= (uchar*) my_multi_malloc(MYF(MY_WME), + m_memory= (uchar*) my_multi_malloc(PSI_NOT_INSTRUMENTED, MYF(MY_WME), &m_dbnam, (uint) m_dblen + 1, &m_tblnam, (uint) m_tbllen + 1, &m_coltype, (uint) m_colcnt, @@ -3801,7 +3801,7 @@ bool copy_event_cache_to_string_and_reinit(IO_CACHE *cache, LEX_STRING *to) { reinit_io_cache(cache, READ_CACHE, 0L, FALSE, FALSE); if (cache->end_of_file > SIZE_T_MAX || - !(to->str= (char*) my_malloc((to->length= (size_t)cache->end_of_file), MYF(0)))) + !(to->str= (char*) my_malloc(PSI_NOT_INSTRUMENTED, (to->length= (size_t)cache->end_of_file), MYF(0)))) { perror("Out of memory: can't allocate memory in copy_event_cache_to_string_and_reinit()."); goto err; diff --git a/sql/log_event_old.cc b/sql/log_event_old.cc index e01488abbb3..c6ccfc5a2c0 100644 --- a/sql/log_event_old.cc +++ b/sql/log_event_old.cc @@ -32,6 +32,8 @@ #include "rpl_record_old.h" #include "transaction.h" +PSI_memory_key key_memory_log_event_old; + #if !defined(MYSQL_CLIENT) && defined(HAVE_REPLICATION) // Old implementation of do_apply_event() @@ -899,7 +901,7 @@ int Delete_rows_log_event_old::do_before_row_operations(TABLE *table) if (table->s->keys > 0) { - m_memory= (uchar*) my_multi_malloc(MYF(MY_WME), + m_memory= (uchar*) my_multi_malloc(key_memory_log_event_old, MYF(MY_WME), &m_after_image, (uint) table->s->reclength, &m_key, @@ -908,7 +910,7 @@ int Delete_rows_log_event_old::do_before_row_operations(TABLE *table) } else { - m_after_image= (uchar*) my_malloc(table->s->reclength, MYF(MY_WME)); + m_after_image= (uchar*) my_malloc(key_memory_log_event_old, table->s->reclength, MYF(MY_WME)); m_memory= (uchar*)m_after_image; m_key= NULL; } @@ -997,7 +999,7 @@ int Update_rows_log_event_old::do_before_row_operations(TABLE *table) if (table->s->keys > 0) { - m_memory= (uchar*) my_multi_malloc(MYF(MY_WME), + m_memory= (uchar*) my_multi_malloc(key_memory_log_event_old, MYF(MY_WME), &m_after_image, (uint) table->s->reclength, &m_key, @@ -1006,7 +1008,7 @@ int Update_rows_log_event_old::do_before_row_operations(TABLE *table) } else { - m_after_image= (uchar*) my_malloc(table->s->reclength, MYF(MY_WME)); + m_after_image= (uchar*) my_malloc(key_memory_log_event_old, table->s->reclength, MYF(MY_WME)); m_memory= m_after_image; m_key= NULL; } @@ -1252,7 +1254,7 @@ Old_rows_log_event::Old_rows_log_event(const char *buf, uint event_len, m_table_id, m_flags, m_width, data_size)); DBUG_DUMP("rows_data", (uchar*) ptr_rows_data, data_size); - m_rows_buf= (uchar*) my_malloc(data_size, MYF(MY_WME)); + m_rows_buf= (uchar*) my_malloc(key_memory_log_event_old, data_size, MYF(MY_WME)); if (likely((bool)m_rows_buf)) { #if !defined(MYSQL_CLIENT) && defined(HAVE_REPLICATION) @@ -1326,7 +1328,7 @@ int Old_rows_log_event::do_add_row_data(uchar *row_data, size_t length) my_ptrdiff_t const new_alloc= block_size * ((cur_size + length + block_size - 1) / block_size); - uchar* const new_buf= (uchar*)my_realloc((uchar*)m_rows_buf, (uint) new_alloc, + uchar* const new_buf= (uchar*)my_realloc(key_memory_log_event_old, (uchar*)m_rows_buf, (uint) new_alloc, MYF(MY_ALLOW_ZERO_PTR|MY_WME)); if (unlikely(!new_buf)) DBUG_RETURN(HA_ERR_OUT_OF_MEM); @@ -2555,7 +2557,7 @@ Delete_rows_log_event_old::do_before_row_operations(const Slave_reporting_capabi if (m_table->s->keys > 0) { // Allocate buffer for key searches - m_key= (uchar*)my_malloc(m_table->key_info->key_length, MYF(MY_WME)); + m_key= (uchar*)my_malloc(key_memory_log_event_old, m_table->key_info->key_length, MYF(MY_WME)); if (!m_key) return HA_ERR_OUT_OF_MEM; } @@ -2653,7 +2655,7 @@ Update_rows_log_event_old::do_before_row_operations(const Slave_reporting_capabi if (m_table->s->keys > 0) { // Allocate buffer for key searches - m_key= (uchar*)my_malloc(m_table->key_info->key_length, MYF(MY_WME)); + m_key= (uchar*)my_malloc(key_memory_log_event_old, m_table->key_info->key_length, MYF(MY_WME)); if (!m_key) return HA_ERR_OUT_OF_MEM; } diff --git a/sql/log_event_server.cc b/sql/log_event_server.cc index d371992c6c0..e2a200d3a3b 100644 --- a/sql/log_event_server.cc +++ b/sql/log_event_server.cc @@ -3014,7 +3014,7 @@ Rotate_log_event::Rotate_log_event(const char* new_log_ident_arg, pos_arg, (ulong) flags)); cache_type= EVENT_NO_CACHE; if (flags & DUP_NAME) - new_log_ident= my_strndup(new_log_ident_arg, ident_len, MYF(MY_WME)); + new_log_ident= my_strndup(PSI_INSTRUMENT_ME, new_log_ident_arg, ident_len, MYF(MY_WME)); if (flags & RELAY_LOG) set_relay_log_event(); DBUG_VOID_RETURN; @@ -3170,7 +3170,7 @@ Binlog_checkpoint_log_event::Binlog_checkpoint_log_event( const char *binlog_file_name_arg, uint binlog_file_len_arg) :Log_event(), - binlog_file_name(my_strndup(binlog_file_name_arg, binlog_file_len_arg, + binlog_file_name(my_strndup(PSI_INSTRUMENT_ME, binlog_file_name_arg, binlog_file_len_arg, MYF(MY_WME))), binlog_file_len(binlog_file_len_arg) { @@ -3443,8 +3443,8 @@ Gtid_list_log_event::Gtid_list_log_event(rpl_binlog_state *gtid_set, cache_type= EVENT_NO_CACHE; /* Failure to allocate memory will be caught by is_valid() returning false. */ if (count < (1<<28) && - (list = (rpl_gtid *)my_malloc(count * sizeof(*list) + (count == 0), - MYF(MY_WME)))) + (list = (rpl_gtid *)my_malloc(PSI_INSTRUMENT_ME, + count * sizeof(*list) + (count == 0), MYF(MY_WME)))) gtid_set->get_gtid_list(list, count); } @@ -3456,8 +3456,8 @@ Gtid_list_log_event::Gtid_list_log_event(slave_connection_state *gtid_set, cache_type= EVENT_NO_CACHE; /* Failure to allocate memory will be caught by is_valid() returning false. */ if (count < (1<<28) && - (list = (rpl_gtid *)my_malloc(count * sizeof(*list) + (count == 0), - MYF(MY_WME)))) + (list = (rpl_gtid *)my_malloc(PSI_INSTRUMENT_ME, + count * sizeof(*list) + (count == 0), MYF(MY_WME)))) { gtid_set->get_gtid_list(list, count); #if defined(HAVE_REPLICATION) @@ -3465,8 +3465,8 @@ Gtid_list_log_event::Gtid_list_log_event(slave_connection_state *gtid_set, { uint32 i; - if (!(sub_id_list= (uint64 *)my_malloc(count * sizeof(uint64), - MYF(MY_WME)))) + if (!(sub_id_list= (uint64 *)my_malloc(PSI_INSTRUMENT_ME, + count * sizeof(uint64), MYF(MY_WME)))) { my_free(list); list= NULL; @@ -4691,7 +4691,7 @@ int Execute_load_log_event::do_apply_event(rpl_group_info *rgi) don't want to overwrite it with the filename. What we want instead is add the filename to the current error message. */ - char *tmp= my_strdup(rli->last_error().message, MYF(MY_WME)); + char *tmp= my_strdup(PSI_INSTRUMENT_ME, rli->last_error().message, MYF(MY_WME)); if (tmp) { rli->report(ERROR_LEVEL, rli->last_error().number, rgi->gtid_info(), @@ -4823,8 +4823,8 @@ Execute_load_query_log_event::do_apply_event(rpl_group_info *rgi) int error; Relay_log_info const *rli= rgi->rli; - buf= (char*) my_malloc(q_len + 1 - (fn_pos_end - fn_pos_start) + - (FN_REFLEN + 10) + 10 + 8 + 5, MYF(MY_WME)); + buf= (char*) my_malloc(PSI_INSTRUMENT_ME, q_len + 1 - + (fn_pos_end - fn_pos_start) + (FN_REFLEN + 10) + 10 + 8 + 5, MYF(MY_WME)); DBUG_EXECUTE_IF("LOAD_DATA_INFILE_has_fatal_error", my_free(buf); buf= NULL;); @@ -5036,8 +5036,8 @@ int Rows_log_event::do_add_row_data(uchar *row_data, size_t length) size_t const new_alloc= block_size * ((cur_size + length + block_size - 1) / block_size); - uchar* const new_buf= (uchar*)my_realloc((uchar*)m_rows_buf, new_alloc, - MYF(MY_ALLOW_ZERO_PTR|MY_WME)); + uchar* const new_buf= (uchar*)my_realloc(PSI_INSTRUMENT_ME, m_rows_buf, + new_alloc, MYF(MY_ALLOW_ZERO_PTR|MY_WME)); if (unlikely(!new_buf)) DBUG_RETURN(HA_ERR_OUT_OF_MEM); @@ -5990,7 +5990,7 @@ Table_map_log_event::Table_map_log_event(THD *thd, TABLE *tbl, ulong tid, m_flags|= TM_BIT_HAS_TRIGGERS_F; /* If malloc fails, caught in is_valid() */ - if ((m_memory= (uchar*) my_malloc(m_colcnt, MYF(MY_WME)))) + if ((m_memory= (uchar*) my_malloc(PSI_INSTRUMENT_ME, m_colcnt, MYF(MY_WME)))) { m_coltype= reinterpret_cast<uchar*>(m_memory); for (unsigned int i= 0 ; i < m_table->s->fields ; ++i) @@ -6006,7 +6006,7 @@ Table_map_log_event::Table_map_log_event(THD *thd, TABLE *tbl, ulong tid, */ uint num_null_bytes= (m_table->s->fields + 7) / 8; m_data_size+= num_null_bytes; - m_meta_memory= (uchar *)my_multi_malloc(MYF(MY_WME), + m_meta_memory= (uchar *)my_multi_malloc(PSI_INSTRUMENT_ME, MYF(MY_WME), &m_null_bits, num_null_bytes, &m_field_metadata, (m_colcnt * 2), NULL); @@ -6158,7 +6158,7 @@ int Table_map_log_event::do_apply_event(rpl_group_info *rgi) /* Step the query id to mark what columns that are actually used. */ thd->set_query_id(next_query_id()); - if (!(memory= my_multi_malloc(MYF(MY_WME), + if (!(memory= my_multi_malloc(PSI_INSTRUMENT_ME, MYF(MY_WME), &table_list, (uint) sizeof(RPL_TABLE_LIST), &db_mem, (uint) NAME_LEN + 1, &tname_mem, (uint) NAME_LEN + 1, @@ -7438,7 +7438,7 @@ int Rows_log_event::find_key() } // Allocate buffer for key searches - m_key= (uchar *) my_malloc(best_key->key_length, MYF(MY_WME)); + m_key= (uchar *) my_malloc(PSI_INSTRUMENT_ME, best_key->key_length, MYF(MY_WME)); if (m_key == NULL) DBUG_RETURN(HA_ERR_OUT_OF_MEM); m_key_info= best_key; diff --git a/sql/mdl.cc b/sql/mdl.cc index c4d6f89644b..0d6588cd6a4 100644 --- a/sql/mdl.cc +++ b/sql/mdl.cc @@ -26,6 +26,8 @@ #include <mysql/psi/mysql_stage.h> #include <tpool.h> +static PSI_memory_key key_memory_MDL_context_acquire_locks; + #ifdef HAVE_PSI_INTERFACE static PSI_mutex_key key_MDL_wait_LOCK_wait_status; @@ -50,6 +52,11 @@ static PSI_cond_info all_mdl_conds[]= { &key_MDL_wait_COND_wait_status, "MDL_context::COND_wait_status", 0} }; +static PSI_memory_info all_mdl_memory[]= +{ + { &key_memory_MDL_context_acquire_locks, "MDL_context::acquire_locks", 0} +}; + /** Initialise all the performance schema instrumentation points used by the MDL subsystem. @@ -67,6 +74,9 @@ static void init_mdl_psi_keys(void) count= array_elements(all_mdl_conds); mysql_cond_register("sql", all_mdl_conds, count); + count= array_elements(all_mdl_memory); + mysql_memory_register("sql", all_mdl_memory, count); + MDL_key::init_psi_keys(); } #endif /* HAVE_PSI_INTERFACE */ @@ -2435,8 +2445,8 @@ bool MDL_context::acquire_locks(MDL_request_list *mdl_requests, DBUG_RETURN(FALSE); /* Sort requests according to MDL_key. */ - if (! (sort_buf= (MDL_request **)my_malloc(req_count * - sizeof(MDL_request*), + if (! (sort_buf= (MDL_request **)my_malloc(key_memory_MDL_context_acquire_locks, + req_count * sizeof(MDL_request*), MYF(MY_WME)))) DBUG_RETURN(TRUE); diff --git a/sql/mysqld.cc b/sql/mysqld.cc index a94ffa900eb..a153801c35f 100644 --- a/sql/mysqld.cc +++ b/sql/mysqld.cc @@ -1109,7 +1109,7 @@ PSI_file_key key_file_binlog, key_file_binlog_index, key_file_casetest, key_file_dbopt, key_file_des_key_file, key_file_ERRMSG, key_select_to_file, key_file_fileparser, key_file_frm, key_file_global_ddl_log, key_file_load, key_file_loadfile, key_file_log_event_data, key_file_log_event_info, - key_file_master_info, key_file_misc, key_file_partition, + key_file_master_info, key_file_misc, key_file_partition_ddl_log, key_file_pid, key_file_relay_log_info, key_file_send_file, key_file_tclog, key_file_trg, key_file_trn, key_file_init; PSI_file_key key_file_query_log, key_file_slow_log; @@ -1291,7 +1291,7 @@ private: void Buffered_logs::init() { - init_alloc_root(&m_root, "Buffered_logs", 1024, 0, MYF(0)); + init_alloc_root(PSI_NOT_INSTRUMENTED, &m_root, 1024, 0, MYF(0)); } void Buffered_logs::cleanup() @@ -1671,7 +1671,7 @@ void kill_mysql(THD *thd) make_user_name(thd, user_host_buff); - if ((user= my_strdup(user_host_buff, MYF(0))) && + if ((user= my_strdup(PSI_NOT_INSTRUMENTED, user_host_buff, MYF(0))) && !shutdown_user.compare_exchange_strong(expected_shutdown_user, user, std::memory_order_relaxed, @@ -3205,10 +3205,18 @@ extern "C" void *my_str_malloc_mysqld(size_t size); void *my_str_malloc_mysqld(size_t size) { - return my_malloc(size, MYF(MY_FAE)); + return my_malloc(key_memory_my_str_malloc, size, MYF(MY_FAE)); } +#if 0 +extern "C" void *my_str_realloc_mysqld(void *ptr, size_t size); +void *my_str_realloc_mysqld(void *ptr, size_t size) +{ + return my_realloc(key_memory_my_str_malloc, ptr, size, MYF(MY_FAE)); +} +#endif + #include <mysqld_default_groups.h> #if defined(__WIN__) && !defined(EMBEDDED_LIBRARY) @@ -3631,10 +3639,8 @@ int json_unescape_json(const char *json_str, const char *json_end, @returns Pointer to string containing the full file path, or NULL if it was not possible to create the path. */ -static inline const char * -rpl_make_log_name(const char *opt, - const char *def, - const char *ext) +static const char *rpl_make_log_name(PSI_memory_key key, const char *opt, + const char *def, const char *ext) { DBUG_ENTER("rpl_make_log_name"); DBUG_PRINT("enter", ("opt: %s, def: %s, ext: %s", opt, def, ext)); @@ -3652,7 +3658,7 @@ rpl_make_log_name(const char *opt, mysql_real_data_home_ptr= mysql_real_data_home; if (fn_format(buff, base, mysql_real_data_home_ptr, ext, options)) - DBUG_RETURN(my_strdup(buff, MYF(MY_WME))); + DBUG_RETURN(my_strdup(key, buff, MYF(MY_WME))); else DBUG_RETURN(NULL); } @@ -4960,10 +4966,12 @@ static int init_server_components() } log_bin_basename= - rpl_make_log_name(opt_bin_logname, pidfile_name, + rpl_make_log_name(key_memory_MYSQL_BIN_LOG_basename, + opt_bin_logname, pidfile_name, opt_bin_logname ? "" : "-bin"); log_bin_index= - rpl_make_log_name(opt_binlog_index_name, log_bin_basename, ".index"); + rpl_make_log_name(key_memory_MYSQL_BIN_LOG_index, + opt_binlog_index_name, log_bin_basename, ".index"); if (log_bin_basename == NULL || log_bin_index == NULL) { sql_print_error("Unable to create replication path names:" @@ -4981,10 +4989,12 @@ static int init_server_components() if (opt_relay_logname) { relay_log_basename= - rpl_make_log_name(opt_relay_logname, pidfile_name, + rpl_make_log_name(key_memory_MYSQL_RELAY_LOG_basename, + opt_relay_logname, pidfile_name, opt_relay_logname ? "" : "-relay-bin"); relay_log_index= - rpl_make_log_name(opt_relaylog_index_name, relay_log_basename, ".index"); + rpl_make_log_name(key_memory_MYSQL_RELAY_LOG_index, + opt_relaylog_index_name, relay_log_basename, ".index"); if (relay_log_basename == NULL || relay_log_index == NULL) { sql_print_error("Unable to create replication path names:" @@ -6357,7 +6367,8 @@ int handle_early_options() my_getopt_skip_unknown= TRUE; /* prepare all_early_options array */ - my_init_dynamic_array(&all_early_options, sizeof(my_option), 100, 25, MYF(0)); + my_init_dynamic_array(&all_early_options, PSI_NOT_INSTRUMENTED, + sizeof(my_option), 100, 25, MYF(0)); add_many_options(&all_early_options, pfs_early_options, array_elements(pfs_early_options)); sys_var_add_options(&all_early_options, sys_var::PARSE_EARLY); @@ -7676,7 +7687,7 @@ static int option_cmp(my_option *a, my_option *b) static void print_help() { MEM_ROOT mem_root; - init_alloc_root(&mem_root, "help", 4096, 4096, MYF(0)); + init_alloc_root(PSI_NOT_INSTRUMENTED, &mem_root, 4096, 4096, MYF(0)); pop_dynamic(&all_options); add_many_options(&all_options, pfs_early_options, @@ -8531,7 +8542,7 @@ static int get_options(int *argc_ptr, char ***argv_ptr) my_getopt_error_reporter= option_error_reporter; /* prepare all_options array */ - my_init_dynamic_array(&all_options, sizeof(my_option), + my_init_dynamic_array(&all_options, PSI_INSTRUMENT_ME, sizeof(my_option), array_elements(my_long_options) + sys_var_elements(), array_elements(my_long_options)/4, MYF(0)); add_many_options(&all_options, my_long_options, array_elements(my_long_options)); @@ -8963,7 +8974,7 @@ static int fix_paths(void) sql_print_warning("Failed to normalize the argument for --secure-file-priv."); DBUG_RETURN(1); } - char *secure_file_real_path= (char *)my_malloc(FN_REFLEN, MYF(MY_FAE)); + char *secure_file_real_path= (char *)my_malloc(PSI_INSTRUMENT_ME, FN_REFLEN, MYF(MY_FAE)); convert_dirname(secure_file_real_path, buff, NullS); my_free(opt_secure_file_priv); opt_secure_file_priv= secure_file_real_path; @@ -9118,7 +9129,7 @@ static PSI_file_info all_server_files[]= { &key_file_log_event_info, "log_event_info", 0}, { &key_file_master_info, "master_info", 0}, { &key_file_misc, "misc", 0}, - { &key_file_partition, "partition", 0}, + { &key_file_partition_ddl_log, "partition_ddl_log", 0}, { &key_file_pid, "pid", 0}, { &key_file_query_log, "query_log", 0}, { &key_file_relay_log_info, "relay_log_info", 0}, @@ -9419,6 +9430,227 @@ static PSI_socket_info all_server_sockets[]= { &key_socket_client_connection, "client_connection", 0} }; + +PSI_memory_key key_memory_DATE_TIME_FORMAT; +PSI_memory_key key_memory_DDL_LOG_MEMORY_ENTRY; +PSI_memory_key key_memory_Event_queue_element_for_exec_names; +PSI_memory_key key_memory_Event_scheduler_scheduler_param; +PSI_memory_key key_memory_Filesort_info_merge; +PSI_memory_key key_memory_Filesort_info_record_pointers; +PSI_memory_key key_memory_Gis_read_stream_err_msg; +PSI_memory_key key_memory_JOIN_CACHE; +PSI_memory_key key_memory_MPVIO_EXT_auth_info; +PSI_memory_key key_memory_MYSQL_BIN_LOG_basename; +PSI_memory_key key_memory_MYSQL_BIN_LOG_index; +PSI_memory_key key_memory_MYSQL_LOCK; +PSI_memory_key key_memory_MYSQL_LOG_name; +PSI_memory_key key_memory_MYSQL_RELAY_LOG_basename; +PSI_memory_key key_memory_MYSQL_RELAY_LOG_index; +PSI_memory_key key_memory_NAMED_ILINK_name; +PSI_memory_key key_memory_PROFILE; +PSI_memory_key key_memory_QUICK_RANGE_SELECT_mrr_buf_desc; +PSI_memory_key key_memory_Query_cache; +PSI_memory_key key_memory_Relay_log_info_group_relay_log_name; +PSI_memory_key key_memory_Row_data_memory_memory; +PSI_memory_key key_memory_Rpl_info_file_buffer; +PSI_memory_key key_memory_SLAVE_INFO; +PSI_memory_key key_memory_ST_SCHEMA_TABLE; +PSI_memory_key key_memory_Sort_param_tmp_buffer; +PSI_memory_key key_memory_Sys_var_charptr_value; +PSI_memory_key key_memory_TABLE; +PSI_memory_key key_memory_TABLE_RULE_ENT; +PSI_memory_key key_memory_TC_LOG_MMAP_pages; +PSI_memory_key key_memory_THD_db; +PSI_memory_key key_memory_THD_handler_tables_hash; +PSI_memory_key key_memory_THD_variables; +PSI_memory_key key_memory_Table_trigger_dispatcher; +PSI_memory_key key_memory_Unique_merge_buffer; +PSI_memory_key key_memory_Unique_sort_buffer; +PSI_memory_key key_memory_User_level_lock; +PSI_memory_key key_memory_XID; +PSI_memory_key key_memory_acl_cache; +PSI_memory_key key_memory_acl_mem; +PSI_memory_key key_memory_acl_memex; +PSI_memory_key key_memory_binlog_cache_mngr; +PSI_memory_key key_memory_binlog_pos; +PSI_memory_key key_memory_binlog_recover_exec; +PSI_memory_key key_memory_binlog_statement_buffer; +PSI_memory_key key_memory_binlog_ver_1_event; +PSI_memory_key key_memory_bison_stack; +PSI_memory_key key_memory_blob_mem_storage; +PSI_memory_key key_memory_dboptions_hash; +PSI_memory_key key_memory_errmsgs; +PSI_memory_key key_memory_frm_string; +PSI_memory_key key_memory_gdl; +PSI_memory_key key_memory_global_system_variables; +PSI_memory_key key_memory_handler_errmsgs; +PSI_memory_key key_memory_handlerton; +PSI_memory_key key_memory_hash_index_key_buffer; +PSI_memory_key key_memory_host_cache_hostname; +PSI_memory_key key_memory_ignored_db; +PSI_memory_key key_memory_locked_table_list; +PSI_memory_key key_memory_locked_thread_list; +PSI_memory_key key_memory_my_str_malloc; +PSI_memory_key key_memory_native_functions; +PSI_memory_key key_memory_prepared_statement_main_mem_root; +PSI_memory_key key_memory_prepared_statement_map; +PSI_memory_key key_memory_queue_item; +PSI_memory_key key_memory_quick_range_select_root; +PSI_memory_key key_memory_rpl_filter; +PSI_memory_key key_memory_sp_cache; +PSI_memory_key key_memory_sp_head_call_root; +PSI_memory_key key_memory_sp_head_execute_root; +PSI_memory_key key_memory_sp_head_main_root; +PSI_memory_key key_memory_table_mapping_root; +PSI_memory_key key_memory_table_share; +PSI_memory_key key_memory_table_triggers_list; +PSI_memory_key key_memory_thd_main_mem_root; +PSI_memory_key key_memory_thd_transactions; +PSI_memory_key key_memory_user_conn; +PSI_memory_key key_memory_user_var_entry; +PSI_memory_key key_memory_user_var_entry_value; + +PSI_memory_key key_memory_String_value; + +static PSI_memory_info all_server_memory[]= +{ + { &key_memory_locked_table_list, "Locked_tables_list::m_locked_tables_root", 0}, + { &key_memory_locked_thread_list, "display_table_locks", PSI_FLAG_THREAD}, + { &key_memory_thd_transactions, "THD::transactions::mem_root", PSI_FLAG_THREAD}, +// { &key_memory_delegate, "Delegate::memroot", 0}, + { &key_memory_acl_mem, "sql_acl_mem", PSI_FLAG_GLOBAL}, + { &key_memory_acl_memex, "sql_acl_memex", PSI_FLAG_GLOBAL}, + { &key_memory_acl_cache, "acl_cache", PSI_FLAG_GLOBAL}, + { &key_memory_thd_main_mem_root, "thd::main_mem_root", PSI_FLAG_THREAD}, +// { &key_memory_help, "help", 0}, +// { &key_memory_new_frm_mem, "new_frm_mem", 0}, + { &key_memory_table_share, "TABLE_SHARE::mem_root", PSI_FLAG_GLOBAL}, /* table definition cache */ + { &key_memory_gdl, "gdl", 0}, + { &key_memory_table_triggers_list, "Table_triggers_list", 0}, +// { &key_memory_servers, "servers", 0}, + { &key_memory_prepared_statement_map, "Prepared_statement_map", PSI_FLAG_THREAD}, + { &key_memory_prepared_statement_main_mem_root, "Prepared_statement::main_mem_root", PSI_FLAG_THREAD}, +// { &key_memory_protocol_rset_root, "Protocol_local::m_rset_root", PSI_FLAG_THREAD}, +// { &key_memory_warning_info_warn_root, "Warning_info::m_warn_root", PSI_FLAG_THREAD}, + { &key_memory_sp_cache, "THD::sp_cache", 0}, + { &key_memory_sp_head_main_root, "sp_head::main_mem_root", 0}, + { &key_memory_sp_head_execute_root, "sp_head::execute_mem_root", PSI_FLAG_THREAD}, + { &key_memory_sp_head_call_root, "sp_head::call_mem_root", PSI_FLAG_THREAD}, + { &key_memory_table_mapping_root, "table_mapping::m_mem_root", 0}, + { &key_memory_quick_range_select_root, "QUICK_RANGE_SELECT::alloc", PSI_FLAG_THREAD}, +// { &key_memory_quick_index_merge_root, "QUICK_INDEX_MERGE_SELECT::alloc", PSI_FLAG_THREAD}, +// { &key_memory_quick_ror_intersect_select_root, "QUICK_ROR_INTERSECT_SELECT::alloc", PSI_FLAG_THREAD}, +// { &key_memory_quick_ror_union_select_root, "QUICK_ROR_UNION_SELECT::alloc", PSI_FLAG_THREAD}, +// { &key_memory_quick_group_min_max_select_root, "QUICK_GROUP_MIN_MAX_SELECT::alloc", PSI_FLAG_THREAD}, +// { &key_memory_test_quick_select_exec, "test_quick_select", PSI_FLAG_THREAD}, +// { &key_memory_prune_partitions_exec, "prune_partitions::exec", 0}, + { &key_memory_binlog_recover_exec, "MYSQL_BIN_LOG::recover", 0}, + { &key_memory_blob_mem_storage, "Blob_mem_storage::storage", 0}, + { &key_memory_NAMED_ILINK_name, "NAMED_ILINK::name", 0}, + { &key_memory_String_value, "String::value", 0}, + { &key_memory_Sys_var_charptr_value, "Sys_var_charptr::value", 0}, + { &key_memory_queue_item, "Queue::queue_item", 0}, + { &key_memory_THD_db, "THD::db", 0}, + { &key_memory_user_var_entry, "user_var_entry", 0}, +// { &key_memory_Slave_job_group_group_relay_log_name, "Slave_job_group::group_relay_log_name", 0}, + { &key_memory_Relay_log_info_group_relay_log_name, "Relay_log_info::group_relay_log_name", 0}, + { &key_memory_binlog_cache_mngr, "binlog_cache_mngr", 0}, + { &key_memory_Row_data_memory_memory, "Row_data_memory::memory", 0}, +// { &key_memory_Gtid_set_to_string, "Gtid_set::to_string", 0}, +// { &key_memory_Gtid_state_to_string, "Gtid_state::to_string", 0}, +// { &key_memory_Owned_gtids_to_string, "Owned_gtids::to_string", 0}, +// { &key_memory_log_event, "Log_event", 0}, +// { &key_memory_Incident_log_event_message, "Incident_log_event::message", 0}, +// { &key_memory_Rows_query_log_event_rows_query, "Rows_query_log_event::rows_query", 0}, + { &key_memory_Sort_param_tmp_buffer, "Sort_param::tmp_buffer", 0}, + { &key_memory_Filesort_info_merge, "Filesort_info::merge", 0}, + { &key_memory_Filesort_info_record_pointers, "Filesort_info::record_pointers", 0}, +// { &key_memory_Filesort_buffer_sort_keys, "Filesort_buffer::sort_keys", 0}, + { &key_memory_handler_errmsgs, "handler::errmsgs", 0}, + { &key_memory_handlerton, "handlerton", 0}, + { &key_memory_XID, "XID", 0}, + { &key_memory_host_cache_hostname, "host_cache::hostname", 0}, + { &key_memory_user_var_entry_value, "user_var_entry::value", 0}, + { &key_memory_User_level_lock, "User_level_lock", 0}, + { &key_memory_MYSQL_LOG_name, "MYSQL_LOG::name", 0}, + { &key_memory_TC_LOG_MMAP_pages, "TC_LOG_MMAP::pages", 0}, +// { &key_memory_my_bitmap_map, "my_bitmap_map", 0}, + { &key_memory_QUICK_RANGE_SELECT_mrr_buf_desc, "QUICK_RANGE_SELECT::mrr_buf_desc", 0}, + { &key_memory_Event_queue_element_for_exec_names, "Event_queue_element_for_exec::names", 0}, + { &key_memory_my_str_malloc, "my_str_malloc", 0}, + { &key_memory_MYSQL_BIN_LOG_basename, "MYSQL_BIN_LOG::basename", 0}, + { &key_memory_MYSQL_BIN_LOG_index, "MYSQL_BIN_LOG::index", 0}, + { &key_memory_MYSQL_RELAY_LOG_basename, "MYSQL_RELAY_LOG::basename", 0}, + { &key_memory_MYSQL_RELAY_LOG_index, "MYSQL_RELAY_LOG::index", 0}, + { &key_memory_rpl_filter, "rpl_filter memory", 0}, + { &key_memory_errmsgs, "errmsgs", 0}, + { &key_memory_Gis_read_stream_err_msg, "Gis_read_stream::err_msg", 0}, +// { &key_memory_Geometry_objects_data, "Geometry::ptr_and_wkb_data", 0}, + { &key_memory_MYSQL_LOCK, "MYSQL_LOCK", 0}, +// { &key_memory_NET_buff, "NET::buff", 0}, +// { &key_memory_NET_compress_packet, "NET::compress_packet", 0}, + { &key_memory_Event_scheduler_scheduler_param, "Event_scheduler::scheduler_param", 0}, +// { &key_memory_Gtid_set_Interval_chunk, "Gtid_set::Interval_chunk", 0}, +// { &key_memory_Owned_gtids_sidno_to_hash, "Owned_gtids::sidno_to_hash", 0}, +// { &key_memory_Sid_map_Node, "Sid_map::Node", 0}, +// { &key_memory_Gtid_state_group_commit_sidno, "Gtid_state::group_commit_sidno_locks", 0}, +// { &key_memory_Mutex_cond_array_Mutex_cond, "Mutex_cond_array::Mutex_cond", 0}, + { &key_memory_TABLE_RULE_ENT, "TABLE_RULE_ENT", 0}, +// { &key_memory_Rpl_info_table, "Rpl_info_table", 0}, + { &key_memory_Rpl_info_file_buffer, "Rpl_info_file::buffer", 0}, +// { &key_memory_db_worker_hash_entry, "db_worker_hash_entry", 0}, +// { &key_memory_rpl_slave_check_temp_dir, "rpl_slave::check_temp_dir", 0}, +// { &key_memory_rpl_slave_command_buffer, "rpl_slave::command_buffer", 0}, + { &key_memory_binlog_ver_1_event, "binlog_ver_1_event", 0}, + { &key_memory_SLAVE_INFO, "SLAVE_INFO", 0}, + { &key_memory_binlog_pos, "binlog_pos", 0}, +// { &key_memory_HASH_ROW_ENTRY, "HASH_ROW_ENTRY", 0}, + { &key_memory_binlog_statement_buffer, "binlog_statement_buffer", 0}, +// { &key_memory_partition_syntax_buffer, "partition_syntax_buffer", 0}, +// { &key_memory_READ_INFO, "READ_INFO", 0}, + { &key_memory_JOIN_CACHE, "JOIN_CACHE", 0}, +// { &key_memory_TABLE_sort_io_cache, "TABLE::sort_io_cache", 0}, +// { &key_memory_frm, "frm", 0}, + { &key_memory_Unique_sort_buffer, "Unique::sort_buffer", 0}, + { &key_memory_Unique_merge_buffer, "Unique::merge_buffer", 0}, + { &key_memory_TABLE, "TABLE", PSI_FLAG_GLOBAL}, /* Table cache */ +// { &key_memory_frm_extra_segment_buff, "frm::extra_segment_buff", 0}, +// { &key_memory_frm_form_pos, "frm::form_pos", 0}, + { &key_memory_frm_string, "frm::string", 0}, +// { &key_memory_LOG_name, "LOG_name", 0}, + { &key_memory_DATE_TIME_FORMAT, "DATE_TIME_FORMAT", 0}, + { &key_memory_DDL_LOG_MEMORY_ENTRY, "DDL_LOG_MEMORY_ENTRY", 0}, + { &key_memory_ST_SCHEMA_TABLE, "ST_SCHEMA_TABLE", 0}, + { &key_memory_ignored_db, "ignored_db", 0}, + { &key_memory_PROFILE, "PROFILE", 0}, + { &key_memory_global_system_variables, "global_system_variables", 0}, + { &key_memory_THD_variables, "THD::variables", 0}, +// { &key_memory_Security_context, "Security_context", 0}, +// { &key_memory_shared_memory_name, "Shared_memory_name", 0}, + { &key_memory_bison_stack, "bison_stack", 0}, + { &key_memory_THD_handler_tables_hash, "THD::handler_tables_hash", 0}, + { &key_memory_hash_index_key_buffer, "hash_index_key_buffer", 0}, + { &key_memory_dboptions_hash, "dboptions_hash", 0}, + { &key_memory_user_conn, "user_conn", 0}, +// { &key_memory_LOG_POS_COORD, "LOG_POS_COORD", 0}, +// { &key_memory_XID_STATE, "XID_STATE", 0}, + { &key_memory_MPVIO_EXT_auth_info, "MPVIO_EXT::auth_info", 0}, +// { &key_memory_opt_bin_logname, "opt_bin_logname", 0}, + { &key_memory_Query_cache, "Query_cache", PSI_FLAG_GLOBAL}, +// { &key_memory_READ_RECORD_cache, "READ_RECORD_cache", 0}, +// { &key_memory_Quick_ranges, "Quick_ranges", 0}, +// { &key_memory_File_query_log_name, "File_query_log::name", 0}, + { &key_memory_Table_trigger_dispatcher, "Table_trigger_dispatcher::m_mem_root", 0}, +// { &key_memory_thd_timer, "thd_timer", 0}, +// { &key_memory_THD_Session_tracker, "THD::Session_tracker", 0}, +// { &key_memory_THD_Session_sysvar_resource_manager, "THD::Session_sysvar_resource_manager", 0}, +// { &key_memory_show_slave_status_io_gtid_set, "show_slave_status_io_gtid_set", 0}, +// { &key_memory_write_set_extraction, "write_set_extraction", 0}, +// { &key_memory_get_all_tables, "get_all_tables", 0}, +// { &key_memory_fill_schema_schemata, "fill_schema_schemata", 0}, + { &key_memory_native_functions, "native_functions", PSI_FLAG_GLOBAL}, +}; + /** Initialise all the performance schema instrumentation points used by the server. @@ -9449,6 +9681,9 @@ void init_server_psi_keys(void) count= array_elements(all_server_sockets); mysql_socket_register(category, all_server_sockets, count); + count= array_elements(all_server_memory); + mysql_memory_register(category, all_server_memory, count); + #ifdef HAVE_PSI_STATEMENT_INTERFACE init_sql_statement_info(); count= array_elements(sql_statement_info); diff --git a/sql/mysqld.h b/sql/mysqld.h index 4f4e608e811..74b71d397e5 100644 --- a/sql/mysqld.h +++ b/sql/mysqld.h @@ -394,7 +394,7 @@ extern PSI_file_key key_file_binlog, key_file_binlog_index, key_file_casetest, key_file_dbopt, key_file_des_key_file, key_file_ERRMSG, key_select_to_file, key_file_fileparser, key_file_frm, key_file_global_ddl_log, key_file_load, key_file_loadfile, key_file_log_event_data, key_file_log_event_info, - key_file_master_info, key_file_misc, key_file_partition, + key_file_master_info, key_file_misc, key_file_partition_ddl_log, key_file_pid, key_file_relay_log_info, key_file_send_file, key_file_tclog, key_file_trg, key_file_trn, key_file_init; extern PSI_file_key key_file_query_log, key_file_slow_log; @@ -406,6 +406,134 @@ extern PSI_file_key key_file_binlog_state; void init_server_psi_keys(); #endif /* HAVE_PSI_INTERFACE */ +extern PSI_memory_key key_memory_locked_table_list; +extern PSI_memory_key key_memory_locked_thread_list; +extern PSI_memory_key key_memory_thd_transactions; +extern PSI_memory_key key_memory_delegate; +extern PSI_memory_key key_memory_acl_mem; +extern PSI_memory_key key_memory_acl_memex; +extern PSI_memory_key key_memory_acl_cache; +extern PSI_memory_key key_memory_thd_main_mem_root; +extern PSI_memory_key key_memory_help; +extern PSI_memory_key key_memory_frm; +extern PSI_memory_key key_memory_table_share; +extern PSI_memory_key key_memory_gdl; +extern PSI_memory_key key_memory_table_triggers_list; +extern PSI_memory_key key_memory_prepared_statement_map; +extern PSI_memory_key key_memory_prepared_statement_main_mem_root; +extern PSI_memory_key key_memory_protocol_rset_root; +extern PSI_memory_key key_memory_warning_info_warn_root; +extern PSI_memory_key key_memory_sp_cache; +extern PSI_memory_key key_memory_sp_head_main_root; +extern PSI_memory_key key_memory_sp_head_execute_root; +extern PSI_memory_key key_memory_sp_head_call_root; +extern PSI_memory_key key_memory_table_mapping_root; +extern PSI_memory_key key_memory_quick_range_select_root; +extern PSI_memory_key key_memory_quick_index_merge_root; +extern PSI_memory_key key_memory_quick_ror_intersect_select_root; +extern PSI_memory_key key_memory_quick_ror_union_select_root; +extern PSI_memory_key key_memory_quick_group_min_max_select_root; +extern PSI_memory_key key_memory_test_quick_select_exec; +extern PSI_memory_key key_memory_prune_partitions_exec; +extern PSI_memory_key key_memory_binlog_recover_exec; +extern PSI_memory_key key_memory_blob_mem_storage; + +extern PSI_memory_key key_memory_Sys_var_charptr_value; +extern PSI_memory_key key_memory_THD_db; +extern PSI_memory_key key_memory_user_var_entry; +extern PSI_memory_key key_memory_user_var_entry_value; +extern PSI_memory_key key_memory_Slave_job_group_group_relay_log_name; +extern PSI_memory_key key_memory_Relay_log_info_group_relay_log_name; +extern PSI_memory_key key_memory_binlog_cache_mngr; +extern PSI_memory_key key_memory_Row_data_memory_memory; +extern PSI_memory_key key_memory_errmsgs; +extern PSI_memory_key key_memory_Event_queue_element_for_exec_names; +extern PSI_memory_key key_memory_Event_scheduler_scheduler_param; +extern PSI_memory_key key_memory_Gis_read_stream_err_msg; +extern PSI_memory_key key_memory_Geometry_objects_data; +extern PSI_memory_key key_memory_host_cache_hostname; +extern PSI_memory_key key_memory_User_level_lock; +extern PSI_memory_key key_memory_Filesort_info_record_pointers; +extern PSI_memory_key key_memory_Sort_param_tmp_buffer; +extern PSI_memory_key key_memory_Filesort_info_merge; +extern PSI_memory_key key_memory_Filesort_buffer_sort_keys; +extern PSI_memory_key key_memory_handler_errmsgs; +extern PSI_memory_key key_memory_handlerton; +extern PSI_memory_key key_memory_XID; +extern PSI_memory_key key_memory_MYSQL_LOCK; +extern PSI_memory_key key_memory_MYSQL_LOG_name; +extern PSI_memory_key key_memory_TC_LOG_MMAP_pages; +extern PSI_memory_key key_memory_my_str_malloc; +extern PSI_memory_key key_memory_MYSQL_BIN_LOG_basename; +extern PSI_memory_key key_memory_MYSQL_BIN_LOG_index; +extern PSI_memory_key key_memory_MYSQL_RELAY_LOG_basename; +extern PSI_memory_key key_memory_MYSQL_RELAY_LOG_index; +extern PSI_memory_key key_memory_rpl_filter; +extern PSI_memory_key key_memory_Security_context; +extern PSI_memory_key key_memory_NET_buff; +extern PSI_memory_key key_memory_NET_compress_packet; +extern PSI_memory_key key_memory_my_bitmap_map; +extern PSI_memory_key key_memory_QUICK_RANGE_SELECT_mrr_buf_desc; +extern PSI_memory_key key_memory_TABLE_RULE_ENT; +extern PSI_memory_key key_memory_Mutex_cond_array_Mutex_cond; +extern PSI_memory_key key_memory_Owned_gtids_sidno_to_hash; +extern PSI_memory_key key_memory_Sid_map_Node; +extern PSI_memory_key key_memory_bison_stack; +extern PSI_memory_key key_memory_TABLE_sort_io_cache; +extern PSI_memory_key key_memory_DATE_TIME_FORMAT; +extern PSI_memory_key key_memory_DDL_LOG_MEMORY_ENTRY; +extern PSI_memory_key key_memory_ST_SCHEMA_TABLE; +extern PSI_memory_key key_memory_ignored_db; +extern PSI_memory_key key_memory_SLAVE_INFO; +extern PSI_memory_key key_memory_log_event_old; +extern PSI_memory_key key_memory_HASH_ROW_ENTRY; +extern PSI_memory_key key_memory_table_def_memory; +extern PSI_memory_key key_memory_MPVIO_EXT_auth_info; +extern PSI_memory_key key_memory_LOG_POS_COORD; +extern PSI_memory_key key_memory_XID_STATE; +extern PSI_memory_key key_memory_Rpl_info_file_buffer; +extern PSI_memory_key key_memory_Rpl_info_table; +extern PSI_memory_key key_memory_binlog_pos; +extern PSI_memory_key key_memory_db_worker_hash_entry; +extern PSI_memory_key key_memory_rpl_slave_command_buffer; +extern PSI_memory_key key_memory_binlog_ver_1_event; +extern PSI_memory_key key_memory_rpl_slave_check_temp_dir; +extern PSI_memory_key key_memory_TABLE; +extern PSI_memory_key key_memory_binlog_statement_buffer; +extern PSI_memory_key key_memory_user_conn; +extern PSI_memory_key key_memory_dboptions_hash; +extern PSI_memory_key key_memory_hash_index_key_buffer; +extern PSI_memory_key key_memory_THD_handler_tables_hash; +extern PSI_memory_key key_memory_JOIN_CACHE; +extern PSI_memory_key key_memory_READ_INFO; +extern PSI_memory_key key_memory_partition_syntax_buffer; +extern PSI_memory_key key_memory_global_system_variables; +extern PSI_memory_key key_memory_THD_variables; +extern PSI_memory_key key_memory_PROFILE; +extern PSI_memory_key key_memory_LOG_name; +extern PSI_memory_key key_memory_string_iterator; +extern PSI_memory_key key_memory_frm_extra_segment_buff; +extern PSI_memory_key key_memory_frm_form_pos; +extern PSI_memory_key key_memory_frm_string; +extern PSI_memory_key key_memory_Unique_sort_buffer; +extern PSI_memory_key key_memory_Unique_merge_buffer; +extern PSI_memory_key key_memory_shared_memory_name; +extern PSI_memory_key key_memory_opt_bin_logname; +extern PSI_memory_key key_memory_Query_cache; +extern PSI_memory_key key_memory_READ_RECORD_cache; +extern PSI_memory_key key_memory_Quick_ranges; +extern PSI_memory_key key_memory_File_query_log_name; +extern PSI_memory_key key_memory_Table_trigger_dispatcher; +extern PSI_memory_key key_memory_show_slave_status_io_gtid_set; +extern PSI_memory_key key_memory_write_set_extraction; +extern PSI_memory_key key_memory_thd_timer; +extern PSI_memory_key key_memory_THD_Session_tracker; +extern PSI_memory_key key_memory_THD_Session_sysvar_resource_manager; +extern PSI_memory_key key_memory_get_all_tables; +extern PSI_memory_key key_memory_fill_schema_schemata; +extern PSI_memory_key key_memory_native_functions; +extern PSI_memory_key key_memory_JSON; + /* MAINTAINER: Please keep this list in order, to limit merge collisions. Hint: grep PSI_stage_info | sort -u diff --git a/sql/net_serv.cc b/sql/net_serv.cc index 4fecf8bffd0..840593cd2db 100644 --- a/sql/net_serv.cc +++ b/sql/net_serv.cc @@ -47,6 +47,9 @@ #include "probes_mysql.h" #include "proxy_protocol.h" +PSI_memory_key key_memory_NET_buff; +PSI_memory_key key_memory_NET_compress_packet; + #ifdef EMBEDDED_LIBRARY #undef MYSQL_SERVER #undef MYSQL_CLIENT @@ -176,8 +179,9 @@ my_bool my_net_init(NET *net, Vio *vio, void *thd, uint my_flags) my_bool net_allocate_new_packet(NET *net, void *thd, uint my_flags) { DBUG_ENTER("net_allocate_new_packet"); - if (!(net->buff=(uchar*) my_malloc((size_t) net->max_packet+ - NET_HEADER_SIZE + COMP_HEADER_SIZE +1, + if (!(net->buff=(uchar*) my_malloc(key_memory_NET_buff, + (size_t) net->max_packet + + NET_HEADER_SIZE + COMP_HEADER_SIZE + 1, MYF(MY_WME | my_flags)))) DBUG_RETURN(1); net->buff_end=net->buff+net->max_packet; @@ -221,11 +225,11 @@ my_bool net_realloc(NET *net, size_t length) my_real_read() may actually read 4 bytes depending on build flags and platform. */ - if (!(buff= (uchar*) my_realloc((char*) net->buff, pkt_length + + if (!(buff= (uchar*) my_realloc(key_memory_NET_buff, + (char*) net->buff, pkt_length + NET_HEADER_SIZE + COMP_HEADER_SIZE + 1, - MYF(MY_WME | - (net->thread_specific_malloc ? - MY_THREAD_SPECIFIC : 0))))) + MYF(MY_WME | (net->thread_specific_malloc + ? MY_THREAD_SPECIFIC : 0))))) { /* @todo: 1 and 2 codes are identical. */ net->error= 1; @@ -636,11 +640,10 @@ net_real_write(NET *net,const uchar *packet, size_t len) size_t complen; uchar *b; uint header_length=NET_HEADER_SIZE+COMP_HEADER_SIZE; - if (!(b= (uchar*) my_malloc(len + NET_HEADER_SIZE + - COMP_HEADER_SIZE + 1, - MYF(MY_WME | - (net->thread_specific_malloc ? - MY_THREAD_SPECIFIC : 0))))) + if (!(b= (uchar*) my_malloc(key_memory_NET_compress_packet, + len + NET_HEADER_SIZE + COMP_HEADER_SIZE + 1, + MYF(MY_WME | (net->thread_specific_malloc + ? MY_THREAD_SPECIFIC : 0))))) { net->error= 2; net->last_errno= ER_OUT_OF_RESOURCES; diff --git a/sql/opt_range.cc b/sql/opt_range.cc index b4e2cfdf599..e3672d2c47f 100644 --- a/sql/opt_range.cc +++ b/sql/opt_range.cc @@ -1267,9 +1267,8 @@ QUICK_RANGE_SELECT::QUICK_RANGE_SELECT(THD *thd, TABLE *table, uint key_nr, if (!no_alloc && !parent_alloc) { // Allocates everything through the internal memroot - init_sql_alloc(&alloc, "QUICK_RANGE_SELECT", - thd->variables.range_alloc_block_size, 0, - MYF(MY_THREAD_SPECIFIC)); + init_sql_alloc(key_memory_quick_range_select_root, &alloc, + thd->variables.range_alloc_block_size, 0, MYF(MY_THREAD_SPECIFIC)); thd->mem_root= &alloc; } else @@ -1277,7 +1276,7 @@ QUICK_RANGE_SELECT::QUICK_RANGE_SELECT(THD *thd, TABLE *table, uint key_nr, file= head->file; record= head->record[0]; - my_init_dynamic_array2(&ranges, sizeof(QUICK_RANGE*), + my_init_dynamic_array2(&ranges, PSI_INSTRUMENT_ME, sizeof(QUICK_RANGE*), thd->alloc(sizeof(QUICK_RANGE*) * 16), 16, 16, MYF(MY_THREAD_SPECIFIC)); @@ -1363,9 +1362,8 @@ QUICK_INDEX_SORT_SELECT::QUICK_INDEX_SORT_SELECT(THD *thd_param, TABLE *table) DBUG_ENTER("QUICK_INDEX_SORT_SELECT::QUICK_INDEX_SORT_SELECT"); index= MAX_KEY; head= table; - init_sql_alloc(&alloc, "QUICK_INDEX_SORT_SELECT", - thd->variables.range_alloc_block_size, 0, - MYF(MY_THREAD_SPECIFIC)); + init_sql_alloc(key_memory_quick_range_select_root, &alloc, + thd->variables.range_alloc_block_size, 0, MYF(MY_THREAD_SPECIFIC)); DBUG_VOID_RETURN; } @@ -1435,9 +1433,8 @@ QUICK_ROR_INTERSECT_SELECT::QUICK_ROR_INTERSECT_SELECT(THD *thd_param, head= table; record= head->record[0]; if (!parent_alloc) - init_sql_alloc(&alloc, "QUICK_ROR_INTERSECT_SELECT", - thd->variables.range_alloc_block_size, 0, - MYF(MY_THREAD_SPECIFIC)); + init_sql_alloc(key_memory_quick_range_select_root, &alloc, + thd->variables.range_alloc_block_size, 0, MYF(MY_THREAD_SPECIFIC)); else bzero(&alloc, sizeof(MEM_ROOT)); last_rowid= (uchar*) alloc_root(parent_alloc? parent_alloc : &alloc, @@ -1713,9 +1710,8 @@ QUICK_ROR_UNION_SELECT::QUICK_ROR_UNION_SELECT(THD *thd_param, head= table; rowid_length= table->file->ref_length; record= head->record[0]; - init_sql_alloc(&alloc, "QUICK_ROR_UNION_SELECT", - thd->variables.range_alloc_block_size, 0, - MYF(MY_THREAD_SPECIFIC)); + init_sql_alloc(key_memory_quick_range_select_root, &alloc, + thd->variables.range_alloc_block_size, 0, MYF(MY_THREAD_SPECIFIC)); thd_param->mem_root= &alloc; } @@ -2726,9 +2722,8 @@ int SQL_SELECT::test_quick_select(THD *thd, key_map keys_to_use, param.possible_keys.clear_all(); thd->no_errors=1; // Don't warn about NULL - init_sql_alloc(&alloc, "test_quick_select", - thd->variables.range_alloc_block_size, 0, - MYF(MY_THREAD_SPECIFIC)); + init_sql_alloc(key_memory_quick_range_select_root, &alloc, + thd->variables.range_alloc_block_size, 0, MYF(MY_THREAD_SPECIFIC)); if (!(param.key_parts= (KEY_PART*) alloc_root(&alloc, sizeof(KEY_PART) * @@ -3407,9 +3402,8 @@ bool calculate_cond_selectivity_for_table(THD *thd, TABLE *table, Item **cond) SEL_TREE *tree; double rows; - init_sql_alloc(&alloc, "calculate_cond_selectivity_for_table", - thd->variables.range_alloc_block_size, 0, - MYF(MY_THREAD_SPECIFIC)); + init_sql_alloc(key_memory_quick_range_select_root, &alloc, + thd->variables.range_alloc_block_size, 0, MYF(MY_THREAD_SPECIFIC)); param.thd= thd; param.mem_root= &alloc; param.old_root= thd->mem_root; @@ -3839,9 +3833,8 @@ bool prune_partitions(THD *thd, TABLE *table, Item *pprune_cond) my_bitmap_map *old_sets[2]; prune_param.part_info= part_info; - init_sql_alloc(&alloc, "prune_partitions", - thd->variables.range_alloc_block_size, 0, - MYF(MY_THREAD_SPECIFIC)); + init_sql_alloc(key_memory_quick_range_select_root, &alloc, + thd->variables.range_alloc_block_size, 0, MYF(MY_THREAD_SPECIFIC)); range_par->mem_root= &alloc; range_par->old_root= thd->mem_root; @@ -12098,7 +12091,8 @@ int QUICK_RANGE_SELECT::reset() if (mrr_buf_size && !mrr_buf_desc) { buf_size= mrr_buf_size; - while (buf_size && !my_multi_malloc(MYF(MY_WME), + while (buf_size && !my_multi_malloc(key_memory_QUICK_RANGE_SELECT_mrr_buf_desc, + MYF(MY_WME), &mrr_buf_desc, sizeof(*mrr_buf_desc), &mrange_buff, buf_size, NullS)) @@ -14450,10 +14444,10 @@ QUICK_GROUP_MIN_MAX_SELECT(TABLE *table, JOIN *join_arg, bool have_min_arg, DBUG_ASSERT(!parent_alloc); if (!parent_alloc) { - init_sql_alloc(&alloc, "QUICK_GROUP_MIN_MAX_SELECT", - join->thd->variables.range_alloc_block_size, 0, - MYF(MY_THREAD_SPECIFIC)); - join->thd->mem_root= &alloc; + THD *thd= join->thd; + init_sql_alloc(key_memory_quick_range_select_root, &alloc, + thd->variables.range_alloc_block_size, 0, MYF(MY_THREAD_SPECIFIC)); + thd->mem_root= &alloc; } else bzero(&alloc, sizeof(MEM_ROOT)); // ensure that it's not used @@ -14513,8 +14507,8 @@ int QUICK_GROUP_MIN_MAX_SELECT::init() if (min_max_arg_part) { - if (my_init_dynamic_array(&min_max_ranges, sizeof(QUICK_RANGE*), 16, 16, - MYF(MY_THREAD_SPECIFIC))) + if (my_init_dynamic_array(&min_max_ranges, PSI_INSTRUMENT_ME, + sizeof(QUICK_RANGE*), 16, 16, MYF(MY_THREAD_SPECIFIC))) return 1; if (have_min) diff --git a/sql/opt_split.cc b/sql/opt_split.cc index 6f8248c315c..8fe3749c2df 100644 --- a/sql/opt_split.cc +++ b/sql/opt_split.cc @@ -341,7 +341,7 @@ bool JOIN::check_for_splittable_materialized() return false; ORDER *ord; - Dynamic_array<SplM_field_ext_info> candidates; + Dynamic_array<SplM_field_ext_info> candidates(PSI_INSTRUMENT_MEM); /* Select from partition_list all candidates for splitting. @@ -712,7 +712,7 @@ void JOIN::add_keyuses_for_splitting() KEY_FIELD *added_key_field; if (!spl_opt_info->added_key_fields.elements) goto err; - if (!(ext_keyuses_for_splitting= new Dynamic_array<KEYUSE_EXT>)) + if (!(ext_keyuses_for_splitting= new Dynamic_array<KEYUSE_EXT>(PSI_INSTRUMENT_MEM))) goto err; while ((added_key_field= li++)) { @@ -742,13 +742,11 @@ void JOIN::add_keyuses_for_splitting() save_query_plan(save_qep); if (!keyuse.buffer && - my_init_dynamic_array(&keyuse, sizeof(KEYUSE), 20, 64, - MYF(MY_THREAD_SPECIFIC))) + my_init_dynamic_array(&keyuse, PSI_INSTRUMENT_ME, sizeof(KEYUSE), + 20, 64, MYF(MY_THREAD_SPECIFIC))) goto err; - if (allocate_dynamic(&keyuse, - save_qep->keyuse.elements + - added_keyuse_count)) + if (allocate_dynamic(&keyuse, save_qep->keyuse.elements + added_keyuse_count)) goto err; memcpy(keyuse.buffer, diff --git a/sql/opt_subselect.cc b/sql/opt_subselect.cc index c7d95fdadec..6c491300d17 100644 --- a/sql/opt_subselect.cc +++ b/sql/opt_subselect.cc @@ -4470,8 +4470,8 @@ SJ_TMP_TABLE::create_sj_weedout_tmp_table(THD *thd) using_unique_constraint= TRUE; /* STEP 3: Allocate memory for temptable description */ - init_sql_alloc(&own_root, "SJ_TMP_TABLE", - TABLE_ALLOC_BLOCK_SIZE, 0, MYF(MY_THREAD_SPECIFIC)); + init_sql_alloc(PSI_INSTRUMENT_ME, &own_root, TABLE_ALLOC_BLOCK_SIZE, 0, + MYF(MY_THREAD_SPECIFIC)); if (!multi_alloc_root(&own_root, &table, sizeof(*table), &share, sizeof(*share), diff --git a/sql/opt_trace.cc b/sql/opt_trace.cc index 7ff11e65a30..057c6f3cc0a 100644 --- a/sql/opt_trace.cc +++ b/sql/opt_trace.cc @@ -449,7 +449,7 @@ bool Opt_trace_context::is_enabled() return false; } -Opt_trace_context::Opt_trace_context() +Opt_trace_context::Opt_trace_context() : traces(PSI_INSTRUMENT_MEM) { current_trace= NULL; max_mem_size= 0; diff --git a/sql/partition_info.cc b/sql/partition_info.cc index 252744a3a73..5a0e7426713 100644 --- a/sql/partition_info.cc +++ b/sql/partition_info.cc @@ -734,7 +734,8 @@ char *partition_info::find_duplicate_name() if (is_sub_partitioned()) max_names+= num_parts * num_subparts; if (my_hash_init(&partition_names, system_charset_info, max_names, 0, 0, - (my_hash_get_key) get_part_name_from_elem, 0, HASH_UNIQUE)) + (my_hash_get_key) get_part_name_from_elem, 0, HASH_UNIQUE, + PSI_INSTRUMENT_ME)) { DBUG_ASSERT(0); curr_name= (const uchar*) "Internal failure"; diff --git a/sql/proxy_protocol.cc b/sql/proxy_protocol.cc index 550813c6457..689d1af88f0 100644 --- a/sql/proxy_protocol.cc +++ b/sql/proxy_protocol.cc @@ -364,7 +364,8 @@ static int parse_networks(const char *subnets_str, subnet **out_subnets, size_t } max_subnets= MY_MAX(3,strlen(subnets_str)/2); - subnets= (subnet *)my_malloc(max_subnets * sizeof(subnet),MY_ZEROFILL); + subnets= (subnet *)my_malloc(PSI_INSTRUMENT_ME, + max_subnets * sizeof(subnet), MY_ZEROFILL); /* Check for special case '*'. */ if (strcmp(subnets_str, "*") == 0) diff --git a/sql/repl_failsafe.cc b/sql/repl_failsafe.cc index 7905e112e2e..09b3269371e 100644 --- a/sql/repl_failsafe.cc +++ b/sql/repl_failsafe.cc @@ -101,7 +101,7 @@ void THD::unregister_slave() mysql_mutex_lock(&LOCK_thd_data); slave_info= 0; mysql_mutex_unlock(&LOCK_thd_data); - delete old_si; + my_free(old_si); binlog_dump_thread_count--; } } @@ -124,7 +124,8 @@ int THD::register_slave(uchar *packet, size_t packet_length) if (check_access(this, REPL_SLAVE_ACL, any_db, NULL, NULL, 0, 0)) return 1; - if (!(si= new Slave_info)) + if (!(si= (Slave_info*)my_malloc(key_memory_SLAVE_INFO, sizeof(Slave_info), + MYF(MY_WME)))) return 1; variables.server_id= si->server_id= uint4korr(p); diff --git a/sql/rpl_filter.cc b/sql/rpl_filter.cc index e96f9640098..d9dc7e499ea 100644 --- a/sql/rpl_filter.cc +++ b/sql/rpl_filter.cc @@ -286,7 +286,7 @@ Rpl_filter::parse_filter_rule(const char* spec, Add_filter add) if (!spec) return false; - if (! (ptr= my_strdup(spec, MYF(MY_WME)))) + if (! (ptr= my_strdup(key_memory_rpl_filter, spec, MYF(MY_WME)))) return true; pstr= ptr; @@ -461,8 +461,9 @@ Rpl_filter::add_table_rule(HASH* h, const char* table_spec) if (!dot) return 1; // len is always > 0 because we know the there exists a '.' uint len = (uint)strlen(table_spec); - TABLE_RULE_ENT* e = (TABLE_RULE_ENT*)my_malloc(sizeof(TABLE_RULE_ENT) - + len, MYF(MY_WME)); + TABLE_RULE_ENT* e = (TABLE_RULE_ENT*)my_malloc(key_memory_TABLE_RULE_ENT, + sizeof(TABLE_RULE_ENT) + len, + MYF(MY_WME)); if (!e) return 1; e->db= (char*)e + sizeof(TABLE_RULE_ENT); e->tbl_name= e->db + (dot - table_spec) + 1; @@ -483,8 +484,9 @@ Rpl_filter::add_wild_table_rule(DYNAMIC_ARRAY* a, const char* table_spec) const char* dot = strchr(table_spec, '.'); if (!dot) return 1; uint len = (uint)strlen(table_spec); - TABLE_RULE_ENT* e = (TABLE_RULE_ENT*)my_malloc(sizeof(TABLE_RULE_ENT) - + len, MYF(MY_WME)); + TABLE_RULE_ENT* e = (TABLE_RULE_ENT*)my_malloc(key_memory_TABLE_RULE_ENT, + sizeof(TABLE_RULE_ENT) + len, + MYF(MY_WME)); if (!e) return 1; e->db= (char*)e + sizeof(TABLE_RULE_ENT); e->tbl_name= e->db + (dot - table_spec) + 1; @@ -500,7 +502,7 @@ Rpl_filter::add_string_list(I_List<i_string> *list, const char* spec) char *str; i_string *node; - if (! (str= my_strdup(spec, MYF(MY_WME)))) + if (! (str= my_strdup(key_memory_rpl_filter, spec, MYF(MY_WME)))) return true; if (! (node= new i_string(str))) @@ -572,7 +574,7 @@ void Rpl_filter::init_table_rule_hash(HASH* h, bool* h_inited) { my_hash_init(h, system_charset_info,TABLE_RULE_HASH_SIZE,0,0, - get_table_key, free_table_ent, 0); + get_table_key, free_table_ent, 0, key_memory_TABLE_RULE_ENT); *h_inited = 1; } @@ -580,8 +582,8 @@ Rpl_filter::init_table_rule_hash(HASH* h, bool* h_inited) void Rpl_filter::init_table_rule_array(DYNAMIC_ARRAY* a, bool* a_inited) { - my_init_dynamic_array(a, sizeof(TABLE_RULE_ENT*), TABLE_RULE_ARR_SIZE, - TABLE_RULE_ARR_SIZE, MYF(0)); + my_init_dynamic_array(a, key_memory_TABLE_RULE_ENT, sizeof(TABLE_RULE_ENT*), + TABLE_RULE_ARR_SIZE, TABLE_RULE_ARR_SIZE, MYF(0)); *a_inited = 1; } diff --git a/sql/rpl_gtid.cc b/sql/rpl_gtid.cc index 599129b98f4..e9c1dc8c5d7 100644 --- a/sql/rpl_gtid.cc +++ b/sql/rpl_gtid.cc @@ -249,8 +249,10 @@ rpl_slave_state::rpl_slave_state() mysql_mutex_init(key_LOCK_slave_state, &LOCK_slave_state, MY_MUTEX_INIT_SLOW); my_hash_init(&hash, &my_charset_bin, 32, offsetof(element, domain_id), - sizeof(uint32), NULL, rpl_slave_state_free_element, HASH_UNIQUE); - my_init_dynamic_array(>id_sort_array, sizeof(rpl_gtid), 8, 8, MYF(0)); + sizeof(uint32), NULL, rpl_slave_state_free_element, HASH_UNIQUE, + PSI_INSTRUMENT_ME); + my_init_dynamic_array(>id_sort_array, PSI_INSTRUMENT_ME, sizeof(rpl_gtid), + 8, 8, MYF(0)); } @@ -333,7 +335,8 @@ rpl_slave_state::update(uint32 domain_id, uint32 server_id, uint64 sub_id, rgi->gtid_ignore_duplicate_state= rpl_group_info::GTID_DUPLICATE_NULL; } - if (!(list_elem= (list_element *)my_malloc(sizeof(*list_elem), MYF(MY_WME)))) + if (!(list_elem= (list_element *)my_malloc(PSI_INSTRUMENT_ME, + sizeof(*list_elem), MYF(MY_WME)))) return 1; list_elem->domain_id= domain_id; list_elem->server_id= server_id; @@ -367,7 +370,7 @@ rpl_slave_state::get_element(uint32 domain_id) if (elem) return elem; - if (!(elem= (element *)my_malloc(sizeof(*elem), MYF(MY_WME)))) + if (!(elem= (element *)my_malloc(PSI_INSTRUMENT_ME, sizeof(*elem), MYF(MY_WME)))) return NULL; elem->list= NULL; elem->domain_id= domain_id; @@ -1112,7 +1115,7 @@ rpl_slave_state::iterate(int (*cb)(rpl_gtid *, void *), void *data, bool locked= false; my_hash_init(>id_hash, &my_charset_bin, 32, offsetof(rpl_gtid, domain_id), - sizeof(uint32), NULL, NULL, HASH_UNIQUE); + sizeof(uint32), NULL, NULL, HASH_UNIQUE, PSI_INSTRUMENT_ME); for (i= 0; i < num_extra; ++i) if (extra_gtids[i].server_id == global_system_variables.server_id && my_hash_insert(>id_hash, (uchar *)(&extra_gtids[i]))) @@ -1329,7 +1332,7 @@ gtid_parse_string_to_list(const char *str, size_t str_len, uint32 *out_len) } if ((!list || len >= alloc_len) && !(list= - (rpl_gtid *)my_realloc(list, + (rpl_gtid *)my_realloc(PSI_INSTRUMENT_ME, list, (alloc_len= alloc_len*2) * sizeof(rpl_gtid), MYF(MY_FREE_ON_ERROR|MY_ALLOW_ZERO_PTR)))) return NULL; @@ -1466,10 +1469,8 @@ rpl_slave_state::alloc_gtid_pos_table(LEX_CSTRING *table_name, void *hton, struct gtid_pos_table *p; char *allocated_str; - if (!my_multi_malloc(MYF(MY_WME), - &p, sizeof(*p), - &allocated_str, table_name->length+1, - NULL)) + if (!my_multi_malloc(PSI_INSTRUMENT_ME, MYF(MY_WME), &p, sizeof(*p), + &allocated_str, table_name->length+1, NULL)) { my_error(ER_OUTOFMEMORY, MYF(0), (int)(sizeof(*p) + table_name->length+1)); return NULL; @@ -1487,8 +1488,8 @@ rpl_slave_state::alloc_gtid_pos_table(LEX_CSTRING *table_name, void *hton, void rpl_binlog_state::init() { my_hash_init(&hash, &my_charset_bin, 32, offsetof(element, domain_id), - sizeof(uint32), NULL, my_free, HASH_UNIQUE); - my_init_dynamic_array(>id_sort_array, sizeof(rpl_gtid), 8, 8, MYF(0)); + sizeof(uint32), NULL, my_free, HASH_UNIQUE, PSI_INSTRUMENT_ME); + my_init_dynamic_array(>id_sort_array, PSI_INSTRUMENT_ME, sizeof(rpl_gtid), 8, 8, MYF(0)); mysql_mutex_init(key_LOCK_binlog_state, &LOCK_binlog_state, MY_MUTEX_INIT_SLOW); initialized= 1; @@ -1685,7 +1686,8 @@ rpl_binlog_state::element::update_element(const rpl_gtid *gtid) } /* Allocate a new GTID and insert it. */ - lookup_gtid= (rpl_gtid *)my_malloc(sizeof(*lookup_gtid), MYF(MY_WME)); + lookup_gtid= (rpl_gtid *)my_malloc(PSI_INSTRUMENT_ME, sizeof(*lookup_gtid), + MYF(MY_WME)); if (!lookup_gtid) return 1; memcpy(lookup_gtid, gtid, sizeof(*lookup_gtid)); @@ -1706,14 +1708,15 @@ rpl_binlog_state::alloc_element_nolock(const rpl_gtid *gtid) rpl_gtid *lookup_gtid; /* First time we see this domain_id; allocate a new element. */ - elem= (element *)my_malloc(sizeof(*elem), MYF(MY_WME)); - lookup_gtid= (rpl_gtid *)my_malloc(sizeof(*lookup_gtid), MYF(MY_WME)); + elem= (element *)my_malloc(PSI_INSTRUMENT_ME, sizeof(*elem), MYF(MY_WME)); + lookup_gtid= (rpl_gtid *)my_malloc(PSI_INSTRUMENT_ME, sizeof(*lookup_gtid), + MYF(MY_WME)); if (elem && lookup_gtid) { elem->domain_id= gtid->domain_id; my_hash_init(&elem->hash, &my_charset_bin, 32, offsetof(rpl_gtid, server_id), sizeof(uint32), NULL, my_free, - HASH_UNIQUE); + HASH_UNIQUE, PSI_INSTRUMENT_ME); elem->last_gtid= lookup_gtid; elem->seq_no_counter= gtid->seq_no; memcpy(lookup_gtid, gtid, sizeof(*lookup_gtid)); @@ -1784,7 +1787,8 @@ rpl_binlog_state::bump_seq_no_if_needed(uint32 domain_id, uint64 seq_no) } /* We need to allocate a new, empty element to remember the next seq_no. */ - if (!(elem= (element *)my_malloc(sizeof(*elem), MYF(MY_WME)))) + if (!(elem= (element *)my_malloc(PSI_INSTRUMENT_ME, sizeof(*elem), + MYF(MY_WME)))) { res= 1; goto end; @@ -1793,7 +1797,7 @@ rpl_binlog_state::bump_seq_no_if_needed(uint32 domain_id, uint64 seq_no) elem->domain_id= domain_id; my_hash_init(&elem->hash, &my_charset_bin, 32, offsetof(rpl_gtid, server_id), sizeof(uint32), NULL, my_free, - HASH_UNIQUE); + HASH_UNIQUE, PSI_INSTRUMENT_ME); elem->last_gtid= NULL; elem->seq_no_counter= seq_no; if (0 == my_hash_insert(&hash, (const uchar *)elem)) @@ -2006,8 +2010,8 @@ rpl_binlog_state::get_most_recent_gtid_list(rpl_gtid **list, uint32 *size) out_size= 0; mysql_mutex_lock(&LOCK_binlog_state); alloc_size= hash.records; - if (!(*list= (rpl_gtid *)my_malloc(alloc_size * sizeof(rpl_gtid), - MYF(MY_WME)))) + if (!(*list= (rpl_gtid *)my_malloc(PSI_INSTRUMENT_ME, + alloc_size * sizeof(rpl_gtid), MYF(MY_WME)))) { res= 1; goto end; @@ -2122,7 +2126,7 @@ rpl_binlog_state::drop_domain(DYNAMIC_ARRAY *ids, DBUG_ENTER("rpl_binlog_state::drop_domain"); - my_init_dynamic_array2(&domain_unique, + my_init_dynamic_array2(&domain_unique, PSI_INSTRUMENT_ME, sizeof(element*), domain_unique_buffer, sizeof(domain_unique_buffer) / sizeof(element*), 4, 0); @@ -2249,8 +2253,8 @@ slave_connection_state::slave_connection_state() { my_hash_init(&hash, &my_charset_bin, 32, offsetof(entry, gtid) + offsetof(rpl_gtid, domain_id), - sizeof(uint32), NULL, my_free, HASH_UNIQUE); - my_init_dynamic_array(>id_sort_array, sizeof(rpl_gtid), 8, 8, MYF(0)); + sizeof(uint32), NULL, my_free, HASH_UNIQUE, PSI_INSTRUMENT_ME); + my_init_dynamic_array(>id_sort_array, PSI_INSTRUMENT_ME, sizeof(rpl_gtid), 8, 8, MYF(0)); } @@ -2294,7 +2298,7 @@ slave_connection_state::load(const char *slave_request, size_t len) return 0; for (;;) { - if (!(rec= (uchar *)my_malloc(sizeof(entry), MYF(MY_WME)))) + if (!(rec= (uchar *)my_malloc(PSI_INSTRUMENT_ME, sizeof(entry), MYF(MY_WME)))) return 1; gtid= &((entry *)rec)->gtid; if (gtid_parser_helper(&p, end, gtid)) @@ -2397,7 +2401,7 @@ slave_connection_state::update(const rpl_gtid *in_gtid) return 0; } - if (!(e= (entry *)my_malloc(sizeof(*e), MYF(MY_WME)))) + if (!(e= (entry *)my_malloc(PSI_INSTRUMENT_ME, sizeof(*e), MYF(MY_WME)))) return 1; e->gtid= *in_gtid; e->flags= 0; @@ -2875,7 +2879,7 @@ gtid_waiting::init() { my_hash_init(&hash, &my_charset_bin, 32, offsetof(hash_element, domain_id), sizeof(uint32), NULL, - free_hash_element, HASH_UNIQUE); + free_hash_element, HASH_UNIQUE, PSI_INSTRUMENT_ME); mysql_mutex_init(key_LOCK_gtid_waiting, &LOCK_gtid_waiting, 0); } @@ -2910,7 +2914,7 @@ gtid_waiting::get_entry(uint32 domain_id) if ((e= (hash_element *)my_hash_search(&hash, (const uchar *)&domain_id, 0))) return e; - if (!(e= (hash_element *)my_malloc(sizeof(*e), MYF(MY_WME)))) + if (!(e= (hash_element *)my_malloc(PSI_INSTRUMENT_ME, sizeof(*e), MYF(MY_WME)))) return NULL; if (init_queue(&e->queue, 8, offsetof(queue_element, wait_seq_no), 0, diff --git a/sql/rpl_injector.cc b/sql/rpl_injector.cc index 597a357e4e2..b0b6e30bed6 100644 --- a/sql/rpl_injector.cc +++ b/sql/rpl_injector.cc @@ -37,7 +37,8 @@ injector::transaction::transaction(MYSQL_BIN_LOG *log, THD *thd) LOG_INFO log_info; log->get_current_log(&log_info); /* !!! binlog_pos does not follow RAII !!! */ - m_start_pos.m_file_name= my_strdup(log_info.log_file_name, MYF(0)); + m_start_pos.m_file_name= my_strdup(key_memory_binlog_pos, + log_info.log_file_name, MYF(0)); m_start_pos.m_file_pos= log_info.pos; m_thd->lex->start_transaction_opt= 0; /* for begin_trans() */ diff --git a/sql/rpl_mi.cc b/sql/rpl_mi.cc index f3c87517f21..fcbd988509d 100644 --- a/sql/rpl_mi.cc +++ b/sql/rpl_mi.cc @@ -58,7 +58,7 @@ Master_info::Master_info(LEX_CSTRING *connection_name_arg, connection_name.length= cmp_connection_name.length= connection_name_arg->length; if ((connection_name.str= tmp= (char*) - my_malloc(connection_name_arg->length*2+2, MYF(MY_WME)))) + my_malloc(PSI_INSTRUMENT_ME, connection_name_arg->length*2+2, MYF(MY_WME)))) { strmake(tmp, connection_name_arg->str, connection_name.length); tmp+= connection_name_arg->length+1; @@ -77,7 +77,7 @@ Master_info::Master_info(LEX_CSTRING *connection_name_arg, parallel_mode= rpl_filter->get_parallel_mode(); - my_init_dynamic_array(&ignore_server_ids, + my_init_dynamic_array(&ignore_server_ids, PSI_INSTRUMENT_ME, sizeof(global_system_variables.server_id), 16, 16, MYF(0)); bzero((char*) &file, sizeof(file)); @@ -742,7 +742,8 @@ int flush_master_info(Master_info* mi, char* ignore_server_ids_buf; { ignore_server_ids_buf= - (char *) my_malloc((sizeof(global_system_variables.server_id) * 3 + 1) * + (char *) my_malloc(PSI_INSTRUMENT_ME, + (sizeof(global_system_variables.server_id) * 3 + 1) * (1 + mi->ignore_server_ids.elements), MYF(MY_WME)); if (!ignore_server_ids_buf) DBUG_RETURN(1); /* error */ @@ -1101,7 +1102,8 @@ bool Master_info_index::init_all_master_info() if (my_hash_init(&master_info_hash, system_charset_info, MAX_REPLICATION_THREAD, 0, 0, (my_hash_get_key) get_key_master_info, - (my_hash_free_key)free_key_master_info, HASH_UNIQUE)) + (my_hash_free_key)free_key_master_info, HASH_UNIQUE, + PSI_INSTRUMENT_ME)) { sql_print_error("Initializing Master_info hash table failed"); DBUG_RETURN(1); @@ -1741,7 +1743,8 @@ Domain_id_filter::Domain_id_filter() : m_filter(false) { for (int i= DO_DOMAIN_IDS; i <= IGNORE_DOMAIN_IDS; i ++) { - my_init_dynamic_array(&m_domain_ids[i], sizeof(ulong), 16, 16, MYF(0)); + my_init_dynamic_array(&m_domain_ids[i], PSI_INSTRUMENT_ME, + sizeof(ulong), 16, 16, MYF(0)); } } @@ -1904,7 +1907,7 @@ char *Domain_id_filter::as_string(enum_list_type type) sz= (sizeof(ulong) * 3 + 1) * (1 + ids->elements); - if (!(buf= (char *) my_malloc(sz, MYF(MY_WME)))) + if (!(buf= (char *) my_malloc(PSI_INSTRUMENT_ME, sz, MYF(MY_WME)))) return NULL; // Store the total number of elements followed by the individual elements. diff --git a/sql/rpl_parallel.cc b/sql/rpl_parallel.cc index 4313840119e..cbdc5a548be 100644 --- a/sql/rpl_parallel.cc +++ b/sql/rpl_parallel.cc @@ -1557,7 +1557,7 @@ rpl_parallel_change_thread_count(rpl_parallel_thread_pool *pool, to allocate, and will not be left with a half-functional thread pool. */ if (new_count && - !my_multi_malloc(MYF(MY_WME|MY_ZEROFILL), + !my_multi_malloc(PSI_INSTRUMENT_ME, MYF(MY_WME|MY_ZEROFILL), &new_list, new_count*sizeof(*new_list), &rpt_array, new_count*sizeof(*rpt_array), NULL)) @@ -1789,7 +1789,7 @@ rpl_parallel_thread::get_qev_common(Log_event *ev, ulonglong event_size) mysql_mutex_assert_owner(&LOCK_rpl_thread); if ((qev= qev_free_list)) qev_free_list= qev->next; - else if(!(qev= (queued_event *)my_malloc(sizeof(*qev), MYF(0)))) + else if(!(qev= (queued_event *)my_malloc(PSI_INSTRUMENT_ME, sizeof(*qev), MYF(0)))) { my_error(ER_OUTOFMEMORY, MYF(0), (int)sizeof(*qev)); return NULL; @@ -1952,7 +1952,7 @@ rpl_parallel_thread::get_gco(uint64 wait_count, group_commit_orderer *prev, mysql_mutex_assert_owner(&LOCK_rpl_thread); if ((gco= gco_free_list)) gco_free_list= gco->next_gco; - else if(!(gco= (group_commit_orderer *)my_malloc(sizeof(*gco), MYF(0)))) + else if(!(gco= (group_commit_orderer *)my_malloc(PSI_INSTRUMENT_ME, sizeof(*gco), MYF(0)))) { my_error(ER_OUTOFMEMORY, MYF(0), (int)sizeof(*gco)); return NULL; @@ -2201,7 +2201,7 @@ rpl_parallel::rpl_parallel() : { my_hash_init(&domain_hash, &my_charset_bin, 32, offsetof(rpl_parallel_entry, domain_id), sizeof(uint32), - NULL, free_rpl_parallel_entry, HASH_UNIQUE); + NULL, free_rpl_parallel_entry, HASH_UNIQUE, PSI_INSTRUMENT_ME); } @@ -2233,7 +2233,7 @@ rpl_parallel::find(uint32 domain_id) if (count == 0 || count > opt_slave_parallel_threads) count= opt_slave_parallel_threads; rpl_parallel_thread **p; - if (!my_multi_malloc(MYF(MY_WME|MY_ZEROFILL), + if (!my_multi_malloc(PSI_INSTRUMENT_ME, MYF(MY_WME|MY_ZEROFILL), &e, sizeof(*e), &p, count*sizeof(*p), NULL)) diff --git a/sql/rpl_rli.cc b/sql/rpl_rli.cc index 6d55b06b497..c4ca425aaa2 100644 --- a/sql/rpl_rli.cc +++ b/sql/rpl_rli.cc @@ -1435,14 +1435,15 @@ Relay_log_info::alloc_inuse_relaylog(const char *name) uint32 gtid_count; rpl_gtid *gtid_list; - if (!(ir= (inuse_relaylog *)my_malloc(sizeof(*ir), MYF(MY_WME|MY_ZEROFILL)))) + if (!(ir= (inuse_relaylog *)my_malloc(PSI_INSTRUMENT_ME, sizeof(*ir), + MYF(MY_WME|MY_ZEROFILL)))) { my_error(ER_OUTOFMEMORY, MYF(0), (int)sizeof(*ir)); return 1; } gtid_count= relay_log_state.count(); - if (!(gtid_list= (rpl_gtid *)my_malloc(sizeof(*gtid_list)*gtid_count, - MYF(MY_WME)))) + if (!(gtid_list= (rpl_gtid *)my_malloc(PSI_INSTRUMENT_ME, + sizeof(*gtid_list)*gtid_count, MYF(MY_WME)))) { my_free(ir); my_error(ER_OUTOFMEMORY, MYF(0), (int)sizeof(*gtid_list)*gtid_count); @@ -1589,8 +1590,8 @@ scan_one_gtid_slave_pos_table(THD *thd, HASH *hash, DYNAMIC_ARRAY *array, } else { - if (!(entry= (struct gtid_pos_element *)my_malloc(sizeof(*entry), - MYF(MY_WME)))) + if (!(entry= (struct gtid_pos_element *)my_malloc(PSI_INSTRUMENT_ME, + sizeof(*entry), MYF(MY_WME)))) { my_error(ER_OUTOFMEMORY, MYF(0), (int)sizeof(*entry)); err= 1; @@ -1833,8 +1834,9 @@ rpl_load_gtid_slave_state(THD *thd) cb_data.default_entry= NULL; my_hash_init(&hash, &my_charset_bin, 32, offsetof(gtid_pos_element, gtid) + offsetof(rpl_gtid, domain_id), - sizeof(uint32), NULL, my_free, HASH_UNIQUE); - if ((err= my_init_dynamic_array(&array, sizeof(gtid_pos_element), 0, 0, MYF(0)))) + sizeof(uint32), NULL, my_free, HASH_UNIQUE, PSI_INSTRUMENT_ME); + if ((err= my_init_dynamic_array(&array, PSI_INSTRUMENT_ME, + sizeof(gtid_pos_element), 0, 0, MYF(0)))) goto end; array_inited= true; diff --git a/sql/rpl_tblmap.cc b/sql/rpl_tblmap.cc index b2da9092e3a..db0c11473d1 100644 --- a/sql/rpl_tblmap.cc +++ b/sql/rpl_tblmap.cc @@ -34,6 +34,12 @@ table_mapping::table_mapping() : m_free(0) { +#ifdef MYSQL_CLIENT + PSI_memory_key psi_key= PSI_NOT_INSTRUMENTED; +#else + PSI_memory_key psi_key= key_memory_table_mapping_root; +#endif + DBUG_ENTER("table_mapping::table_mapping"); /* No "free_element" function for entries passed here, as the entries are @@ -44,10 +50,9 @@ table_mapping::table_mapping() */ (void) my_hash_init(&m_table_ids,&my_charset_bin,TABLE_ID_HASH_SIZE, offsetof(entry,table_id),sizeof(ulonglong), - 0,0,0); + 0,0,0, psi_key); /* We don't preallocate any block, this is consistent with m_free=0 above */ - init_alloc_root(&m_mem_root, "table_mapping", - TABLE_ID_HASH_SIZE*sizeof(entry), 0, MYF(0)); + init_alloc_root(psi_key, &m_mem_root, TABLE_ID_HASH_SIZE*sizeof(entry), 0, MYF(0)); DBUG_VOID_RETURN; } diff --git a/sql/rpl_utility.cc b/sql/rpl_utility.cc index 1e4b59844b8..7c347eba51f 100644 --- a/sql/rpl_utility.cc +++ b/sql/rpl_utility.cc @@ -171,6 +171,7 @@ uint32 table_def::calc_field_size(uint col, uchar *master_data) const return length; } +PSI_memory_key key_memory_table_def_memory; table_def::table_def(unsigned char *types, ulong size, uchar *field_metadata, int metadata_size, @@ -179,7 +180,7 @@ table_def::table_def(unsigned char *types, ulong size, m_field_metadata(0), m_null_bits(0), m_flags(flags), m_memory(NULL) { - m_memory= (uchar *)my_multi_malloc(MYF(MY_WME), + m_memory= (uchar *)my_multi_malloc(key_memory_table_def_memory, MYF(MY_WME), &m_type, size, &m_field_metadata, size * sizeof(uint16), diff --git a/sql/rpl_utility_server.cc b/sql/rpl_utility_server.cc index e58c9cf018e..00d4888bbe3 100644 --- a/sql/rpl_utility_server.cc +++ b/sql/rpl_utility_server.cc @@ -1123,7 +1123,7 @@ err: Deferred_log_events::Deferred_log_events(Relay_log_info *rli) : last_added(NULL) { - my_init_dynamic_array(&array, sizeof(Log_event *), 32, 16, MYF(0)); + my_init_dynamic_array(&array, PSI_INSTRUMENT_ME, sizeof(Log_event *), 32, 16, MYF(0)); } Deferred_log_events::~Deferred_log_events() diff --git a/sql/semisync_master.cc b/sql/semisync_master.cc index b239a9776a7..79634d142eb 100644 --- a/sql/semisync_master.cc +++ b/sql/semisync_master.cc @@ -724,8 +724,8 @@ int Repl_semi_sync_master::report_binlog_update(THD* thd, const char *log_file, if (!(log_info= thd->semisync_info)) { - if(!(log_info= - (Trans_binlog_info*) my_malloc(sizeof(Trans_binlog_info), MYF(0)))) + if(!(log_info= (Trans_binlog_info*)my_malloc(PSI_INSTRUMENT_ME, + sizeof(Trans_binlog_info), MYF(0)))) return 1; thd->semisync_info= log_info; } diff --git a/sql/semisync_master.h b/sql/semisync_master.h index 74f6c24c8ea..9f0acf57a60 100644 --- a/sql/semisync_master.h +++ b/sql/semisync_master.h @@ -231,7 +231,7 @@ private: */ int allocate_block() { - Block *block= (Block *)my_malloc(sizeof(Block), MYF(0)); + Block *block= (Block *)my_malloc(PSI_INSTRUMENT_ME, sizeof(Block), MYF(0)); if (block) { block->next= NULL; diff --git a/sql/session_tracker.cc b/sql/session_tracker.cc index 33ee6141658..e1c2ec37644 100644 --- a/sql/session_tracker.cc +++ b/sql/session_tracker.cc @@ -72,7 +72,8 @@ void Session_sysvars_tracker::vars_list::copy(vars_list* from, THD *thd) bool Session_sysvars_tracker::vars_list::insert(const sys_var *svar) { sysvar_node_st *node; - if (!(node= (sysvar_node_st *) my_malloc(sizeof(sysvar_node_st), + if (!(node= (sysvar_node_st *) my_malloc(PSI_INSTRUMENT_ME, + sizeof(sysvar_node_st), MYF(MY_WME | (mysqld_server_initialized ? MY_THREAD_SPECIFIC : 0))))) @@ -326,7 +327,8 @@ void Session_sysvars_tracker::init(THD *thd) global_system_variables.session_track_system_variables); DBUG_ASSERT(global_system_variables.session_track_system_variables); thd->variables.session_track_system_variables= - my_strdup(global_system_variables.session_track_system_variables, + my_strdup(PSI_INSTRUMENT_ME, + global_system_variables.session_track_system_variables, MYF(MY_WME | MY_THREAD_SPECIFIC)); } @@ -383,11 +385,11 @@ bool Session_sysvars_tracker::update(THD *thd, set_var *var) size_t length= 1; if (var->save_result.string_value.str) - copy= my_memdup(var->save_result.string_value.str, + copy= my_memdup(PSI_INSTRUMENT_ME, var->save_result.string_value.str, (length= var->save_result.string_value.length + 1), MYF(MY_WME | MY_THREAD_SPECIFIC)); else - copy= my_strdup("", MYF(MY_WME | MY_THREAD_SPECIFIC)); + copy= my_strdup(PSI_INSTRUMENT_ME, "", MYF(MY_WME | MY_THREAD_SPECIFIC)); if (!copy) return true; diff --git a/sql/session_tracker.h b/sql/session_tracker.h index b91e588a34e..422ec98944a 100644 --- a/sql/session_tracker.h +++ b/sql/session_tracker.h @@ -143,9 +143,9 @@ class Session_sysvars_tracker: public State_tracker void init() { my_hash_init(&m_registered_sysvars, &my_charset_bin, 0, 0, 0, - (my_hash_get_key) sysvars_get_key, my_free, - HASH_UNIQUE | (mysqld_server_initialized ? - HASH_THREAD_SPECIFIC : 0)); + (my_hash_get_key) sysvars_get_key, my_free, HASH_UNIQUE | + (mysqld_server_initialized ? HASH_THREAD_SPECIFIC : 0), + PSI_INSTRUMENT_ME); } void free_hash() { @@ -401,10 +401,9 @@ class User_variables_tracker: public State_tracker Hash_set<const user_var_entry> m_changed_user_variables; public: User_variables_tracker(): - m_changed_user_variables(&my_charset_bin, 0, 0, - sizeof(const user_var_entry*), 0, 0, - HASH_UNIQUE | (mysqld_server_initialized ? - HASH_THREAD_SPECIFIC : 0)) {} + m_changed_user_variables(PSI_INSTRUMENT_ME, &my_charset_bin, 0, 0, + sizeof(const user_var_entry*), 0, 0, HASH_UNIQUE | + mysqld_server_initialized ? HASH_THREAD_SPECIFIC : 0) {} bool update(THD *thd, set_var *var); bool store(THD *thd, String *buf); void mark_as_changed(THD *thd, const user_var_entry *var) diff --git a/sql/set_var.cc b/sql/set_var.cc index fac409f8ef9..eadbfd4ba7d 100644 --- a/sql/set_var.cc +++ b/sql/set_var.cc @@ -65,7 +65,8 @@ int sys_var_init() DBUG_ASSERT(system_charset_info != NULL); if (my_hash_init(&system_variable_hash, system_charset_info, 700, 0, - 0, (my_hash_get_key) get_sys_var_length, 0, HASH_UNIQUE)) + 0, (my_hash_get_key) get_sys_var_length, 0, HASH_UNIQUE, + PSI_INSTRUMENT_ME)) goto error; if (mysql_add_sys_var_chain(all_sys_vars.first)) @@ -1377,7 +1378,7 @@ resolve_engine_list(THD *thd, const char *str_arg, size_t str_arg_len, if (temp_copy) res= (plugin_ref *)thd->calloc((count+1)*sizeof(*res)); else - res= (plugin_ref *)my_malloc((count+1)*sizeof(*res), MYF(MY_ZEROFILL|MY_WME)); + res= (plugin_ref *)my_malloc(PSI_INSTRUMENT_ME, (count+1)*sizeof(*res), MYF(MY_ZEROFILL|MY_WME)); if (!res) { my_error(ER_OUTOFMEMORY, MYF(0), (int)((count+1)*sizeof(*res))); @@ -1428,7 +1429,7 @@ copy_engine_list(plugin_ref *list) for (p= list, count= 0; *p; ++p, ++count) ; - p= (plugin_ref *)my_malloc((count+1)*sizeof(*p), MYF(0)); + p= (plugin_ref *)my_malloc(PSI_INSTRUMENT_ME, (count+1)*sizeof(*p), MYF(0)); if (!p) { my_error(ER_OUTOFMEMORY, MYF(0), (int)((count+1)*sizeof(*p))); diff --git a/sql/slave.cc b/sql/slave.cc index 87c1cf6cb77..4ef20084678 100644 --- a/sql/slave.cc +++ b/sql/slave.cc @@ -583,7 +583,7 @@ slave_background_kill_request(THD *to_kill) if (to_kill->rgi_slave->killed_for_retry) return; // Already deadlock killed. slave_background_kill_t *p= - (slave_background_kill_t *)my_malloc(sizeof(*p), MYF(MY_WME)); + (slave_background_kill_t *)my_malloc(PSI_INSTRUMENT_ME, sizeof(*p), MYF(MY_WME)); if (p) { p->to_kill= to_kill; @@ -611,7 +611,7 @@ slave_background_gtid_pos_create_request( if (table_entry->state != rpl_slave_state::GTID_POS_AUTO_CREATE) return; - p= (slave_background_gtid_pos_create_t *)my_malloc(sizeof(*p), MYF(MY_WME)); + p= (slave_background_gtid_pos_create_t *)my_malloc(PSI_INSTRUMENT_ME, sizeof(*p), MYF(MY_WME)); if (!p) return; mysql_mutex_lock(&rpl_global_gtid_slave_state->LOCK_slave_state); @@ -1809,7 +1809,8 @@ int init_dynarray_intvar_from_file(DYNAMIC_ARRAY* arr, IO_CACHE* f) (decimal size + space) - 1 + `\n' + '\0' */ size_t max_size= (1 + num_items) * (sizeof(long)*3 + 1) + 1; - buf_act= (char*) my_malloc(max_size, MYF(MY_WME)); + buf_act= (char*) my_malloc(key_memory_Rpl_info_file_buffer, max_size, + MYF(MY_WME)); memcpy(buf_act, buf, read_size); snd_size= my_b_gets(f, buf_act + read_size, max_size - read_size); if (snd_size == 0 || @@ -6035,7 +6036,8 @@ static int queue_binlog_ver_1_event(Master_info *mi, const char *buf, */ if ((uchar)buf[EVENT_TYPE_OFFSET] == LOAD_EVENT) { - if (unlikely(!(tmp_buf=(char*)my_malloc(event_len+1,MYF(MY_WME))))) + if (unlikely(!(tmp_buf=(char*)my_malloc(key_memory_binlog_ver_1_event, + event_len+1,MYF(MY_WME))))) { mi->report(ERROR_LEVEL, ER_SLAVE_FATAL_ERROR, NULL, ER(ER_SLAVE_FATAL_ERROR), "Memory allocation failed"); diff --git a/sql/sp.cc b/sql/sp.cc index 15a5f9b287d..4cfbdde7228 100644 --- a/sql/sp.cc +++ b/sql/sp.cc @@ -2283,7 +2283,7 @@ bool sp_add_used_routine(Query_tables_list *prelocking_ctx, Query_arena *arena, { my_hash_init_opt(&prelocking_ctx->sroutines, system_charset_info, Query_tables_list::START_SROUTINES_HASH_SIZE, - 0, 0, sp_sroutine_key, 0, 0); + 0, 0, sp_sroutine_key, 0, 0, PSI_INSTRUMENT_ME); if (!my_hash_search(&prelocking_ctx->sroutines, key->ptr(), key->length())) { diff --git a/sql/sp_cache.cc b/sql/sp_cache.cc index e4ffbdcb155..04172d56166 100644 --- a/sql/sp_cache.cc +++ b/sql/sp_cache.cc @@ -303,7 +303,8 @@ void sp_cache::init() { my_hash_init(&m_hashtable, system_charset_info, 0, 0, 0, - hash_get_key_for_sp_head, hash_free_sp_head, 0); + hash_get_key_for_sp_head, hash_free_sp_head, 0, + key_memory_sp_cache); } diff --git a/sql/sp_head.cc b/sql/sp_head.cc index 04595a6f32f..da02b0e680a 100644 --- a/sql/sp_head.cc +++ b/sql/sp_head.cc @@ -455,8 +455,8 @@ sp_head *sp_head::create(sp_package *parent, const Sp_handler *handler, enum_sp_aggregate_type agg_type) { MEM_ROOT own_root; - init_sql_alloc(&own_root, "sp_head", MEM_ROOT_BLOCK_SIZE, MEM_ROOT_PREALLOC, - MYF(0)); + init_sql_alloc(key_memory_sp_head_main_root, &own_root, MEM_ROOT_BLOCK_SIZE, + MEM_ROOT_PREALLOC, MYF(0)); sp_head *sp; if (!(sp= new (&own_root) sp_head(&own_root, parent, handler, agg_type))) free_root(&own_root, MYF(0)); @@ -537,11 +537,12 @@ sp_head::sp_head(MEM_ROOT *mem_root_arg, sp_package *parent, m_backpatch_goto.empty(); m_cont_backpatch.empty(); m_lex.empty(); - my_init_dynamic_array(&m_instr, sizeof(sp_instr *), 16, 8, MYF(0)); - my_hash_init(&m_sptabs, system_charset_info, 0, 0, 0, sp_table_key, 0, 0); + my_init_dynamic_array(&m_instr, key_memory_sp_head_main_root, + sizeof(sp_instr *), 16, 8, MYF(0)); + my_hash_init(&m_sptabs, system_charset_info, 0, 0, 0, sp_table_key, 0, 0, + key_memory_sp_head_main_root); my_hash_init(&m_sroutines, system_charset_info, 0, 0, 0, sp_sroutine_key, - 0, 0); - m_security_ctx.init(); + 0, 0, key_memory_sp_head_main_root); DBUG_VOID_RETURN; } @@ -551,7 +552,7 @@ sp_package *sp_package::create(LEX *top_level_lex, const sp_name *name, const Sp_handler *sph) { MEM_ROOT own_root; - init_sql_alloc(&own_root, "sp_package", MEM_ROOT_BLOCK_SIZE, + init_sql_alloc(key_memory_sp_head_main_root, &own_root, MEM_ROOT_BLOCK_SIZE, MEM_ROOT_PREALLOC, MYF(0)); sp_package *sp; if (!(sp= new (&own_root) sp_package(&own_root, top_level_lex, name, sph))) @@ -1038,7 +1039,7 @@ subst_spvars(THD *thd, sp_instr *instr, LEX_STRING *query_str) { DBUG_ENTER("subst_spvars"); - Dynamic_array<Rewritable_query_parameter*> rewritables; + Dynamic_array<Rewritable_query_parameter*> rewritables(PSI_INSTRUMENT_MEM); char *pbuf; StringBuffer<512> qbuf; Copy_query_with_rewrite acc(thd, query_str->str, query_str->length, &qbuf); @@ -1170,7 +1171,7 @@ sp_head::execute(THD *thd, bool merge_da_on_success) opt_trace_disable_if_no_security_context_access(thd); /* init per-instruction memroot */ - init_sql_alloc(&execute_mem_root, "per_instruction_memroot", + init_sql_alloc(key_memory_sp_head_execute_root, &execute_mem_root, MEM_ROOT_BLOCK_SIZE, 0, MYF(0)); DBUG_ASSERT(!(m_flags & IS_INVOKED)); @@ -1815,8 +1816,8 @@ sp_head::execute_trigger(THD *thd, TODO: we should create sp_rcontext once per command and reuse it on subsequent executions of a trigger. */ - init_sql_alloc(&call_mem_root, "execute_trigger", MEM_ROOT_BLOCK_SIZE, 0, - MYF(0)); + init_sql_alloc(key_memory_sp_head_call_root, + &call_mem_root, MEM_ROOT_BLOCK_SIZE, 0, MYF(0)); thd->set_n_backup_active_arena(&call_arena, &backup_arena); Row_definition_list defs; diff --git a/sql/sp_pcontext.cc b/sql/sp_pcontext.cc index 01841bb57b7..848d1f0c655 100644 --- a/sql/sp_pcontext.cc +++ b/sql/sp_pcontext.cc @@ -96,6 +96,9 @@ sp_pcontext::sp_pcontext() : Sql_alloc(), m_max_var_index(0), m_max_cursor_index(0), m_parent(NULL), m_pboundary(0), + m_vars(PSI_INSTRUMENT_MEM), m_case_expr_ids(PSI_INSTRUMENT_MEM), + m_conditions(PSI_INSTRUMENT_MEM), m_cursors(PSI_INSTRUMENT_MEM), + m_handlers(PSI_INSTRUMENT_MEM), m_children(PSI_INSTRUMENT_MEM), m_scope(REGULAR_SCOPE) { init(0, 0, 0); @@ -106,6 +109,9 @@ sp_pcontext::sp_pcontext(sp_pcontext *prev, sp_pcontext::enum_scope scope) : Sql_alloc(), m_max_var_index(0), m_max_cursor_index(0), m_parent(prev), m_pboundary(0), + m_vars(PSI_INSTRUMENT_MEM), m_case_expr_ids(PSI_INSTRUMENT_MEM), + m_conditions(PSI_INSTRUMENT_MEM), m_cursors(PSI_INSTRUMENT_MEM), + m_handlers(PSI_INSTRUMENT_MEM), m_children(PSI_INSTRUMENT_MEM), m_scope(scope) { init(prev->m_var_offset + prev->m_max_var_index, diff --git a/sql/sp_rcontext.cc b/sql/sp_rcontext.cc index 17b4c83b7bc..c4c19dd39f6 100644 --- a/sql/sp_rcontext.cc +++ b/sql/sp_rcontext.cc @@ -74,6 +74,7 @@ sp_rcontext::sp_rcontext(const sp_head *owner, m_return_value_fld(return_value_fld), m_return_value_set(false), m_in_sub_stmt(in_sub_stmt), + m_handlers(PSI_INSTRUMENT_MEM), m_handler_call_stack(PSI_INSTRUMENT_MEM), m_ccount(0) { } diff --git a/sql/sql_acl.cc b/sql/sql_acl.cc index c713f40cdf3..2ff8c5d8bdc 100644 --- a/sql/sql_acl.cc +++ b/sql/sql_acl.cc @@ -654,7 +654,7 @@ bool ROLE_GRANT_PAIR::init(MEM_ROOT *mem, const char *username, #define ROLE_OPENED (1L << 3) static DYNAMIC_ARRAY acl_hosts, acl_users, acl_proxy_users; -static Dynamic_array<ACL_DB> acl_dbs(0U,50U); +static Dynamic_array<ACL_DB> acl_dbs(PSI_INSTRUMENT_MEM, 0U, 50U); typedef Dynamic_array<ACL_DB>::CMP_FUNC acl_dbs_cmp; static HASH acl_roles; /* @@ -2307,9 +2307,9 @@ bool acl_init(bool dont_read_acl_tables) bool return_val; DBUG_ENTER("acl_init"); - acl_cache= new Hash_filo<acl_entry>(ACL_CACHE_SIZE, 0, 0, + acl_cache= new Hash_filo<acl_entry>(key_memory_acl_cache, ACL_CACHE_SIZE, 0, 0, (my_hash_get_key) acl_entry_get_key, - (my_hash_free_key) free, + (my_hash_free_key) my_free, &my_charset_utf8mb3_bin); /* @@ -2384,7 +2384,7 @@ static bool acl_load(THD *thd, const Grant_tables& tables) grant_version++; /* Privileges updated */ const Host_table& host_table= tables.host_table(); - init_sql_alloc(&acl_memroot, "ACL", ACL_ALLOC_BLOCK_SIZE, 0, MYF(0)); + init_sql_alloc(key_memory_acl_mem, &acl_memroot, ACL_ALLOC_BLOCK_SIZE, 0, MYF(0)); if (host_table.table_exists()) // "host" table may not exist (e.g. in MySQL 5.6.7+) { if (host_table.init_read_record(&read_record_info)) @@ -2461,7 +2461,8 @@ static bool acl_load(THD *thd, const Grant_tables& tables) user.sort= get_magic_sort("hu", user.host.hostname, user.user.str); user.hostname_length= safe_strlen(user.host.hostname); - my_init_dynamic_array(&user.role_grants, sizeof(ACL_ROLE *), 0, 8, MYF(0)); + my_init_dynamic_array(&user.role_grants, key_memory_acl_mem, + sizeof(ACL_ROLE *), 0, 8, MYF(0)); user.account_locked= user_table.get_account_locked(); @@ -2479,7 +2480,7 @@ static bool acl_load(THD *thd, const Grant_tables& tables) ACL_ROLE *entry= new (&acl_memroot) ACL_ROLE(&user, &acl_memroot); entry->role_grants = user.role_grants; - my_init_dynamic_array(&entry->parent_grantee, + my_init_dynamic_array(&entry->parent_grantee, key_memory_acl_mem, sizeof(ACL_USER_BASE *), 0, 8, MYF(0)); my_hash_insert(&acl_roles, (uchar *)entry); @@ -2624,7 +2625,7 @@ static bool acl_load(THD *thd, const Grant_tables& tables) DBUG_RETURN(TRUE); MEM_ROOT temp_root; - init_alloc_root(&temp_root, "ACL_tmp", ACL_ALLOC_BLOCK_SIZE, 0, MYF(0)); + init_alloc_root(key_memory_acl_mem, &temp_root, ACL_ALLOC_BLOCK_SIZE, 0, MYF(0)); while (!(read_record_info.read_record())) { char *hostname= safe_str(get_field(&temp_root, roles_mapping_table.host())); @@ -2743,15 +2744,16 @@ bool acl_reload(THD *thd) old_acl_roles_mappings= acl_roles_mappings; old_acl_proxy_users= acl_proxy_users; old_acl_dbs= acl_dbs; - my_init_dynamic_array(&acl_hosts, sizeof(ACL_HOST), 20, 50, MYF(0)); - my_init_dynamic_array(&acl_users, sizeof(ACL_USER), 50, 100, MYF(0)); - acl_dbs.init(50, 100); - my_init_dynamic_array(&acl_proxy_users, sizeof(ACL_PROXY_USER), 50, 100, MYF(0)); + my_init_dynamic_array(&acl_hosts, key_memory_acl_mem, sizeof(ACL_HOST), 20, 50, MYF(0)); + my_init_dynamic_array(&acl_users, key_memory_acl_mem, sizeof(ACL_USER), 50, 100, MYF(0)); + acl_dbs.init(key_memory_acl_mem, 50, 100); + my_init_dynamic_array(&acl_proxy_users, key_memory_acl_mem, sizeof(ACL_PROXY_USER), 50, 100, MYF(0)); my_hash_init2(&acl_roles,50, &my_charset_utf8mb3_bin, 0, 0, 0, (my_hash_get_key) acl_role_get_key, 0, - (void (*)(void *))free_acl_role, 0); + (void (*)(void *))free_acl_role, 0, key_memory_acl_mem); my_hash_init2(&acl_roles_mappings, 50, &my_charset_utf8mb3_bin, 0, 0, 0, - (my_hash_get_key) acl_role_map_get_key, 0, 0, 0); + (my_hash_get_key) acl_role_map_get_key, 0, 0, 0, + key_memory_acl_mem); old_mem= acl_memroot; delete_dynamic(&acl_wild_hosts); my_hash_free(&acl_check_hosts); @@ -3189,7 +3191,7 @@ ACL_USER::ACL_USER(THD *thd, const LEX_USER &combo, sort= get_magic_sort("hu", host.hostname, user.str); password_last_changed= thd->query_start(); password_lifetime= -1; - my_init_dynamic_array(&role_grants, sizeof(ACL_USER *), 0, 8, MYF(0)); + my_init_dynamic_array(&role_grants, PSI_INSTRUMENT_ME, sizeof(ACL_USER *), 0, 8, MYF(0)); } @@ -3274,9 +3276,10 @@ static void acl_insert_role(const char *rolename, privilege_t privileges) mysql_mutex_assert_owner(&acl_cache->lock); entry= new (&acl_memroot) ACL_ROLE(rolename, privileges, &acl_memroot); - my_init_dynamic_array(&entry->parent_grantee, + my_init_dynamic_array(&entry->parent_grantee, key_memory_acl_mem, sizeof(ACL_USER_BASE *), 0, 8, MYF(0)); - my_init_dynamic_array(&entry->role_grants, sizeof(ACL_ROLE *), 0, 8, MYF(0)); + my_init_dynamic_array(&entry->role_grants, key_memory_acl_mem, + sizeof(ACL_ROLE *), 0, 8, MYF(0)); my_hash_insert(&acl_roles, (uchar *)entry); } @@ -3423,7 +3426,8 @@ privilege_t acl_get(const char *host, const char *ip, exit: /* Save entry in cache for quick retrieval */ if (!db_is_pattern && - (entry= (acl_entry*) malloc(sizeof(acl_entry)+key_length))) + (entry= (acl_entry*) my_malloc(key_memory_acl_cache, + sizeof(acl_entry)+key_length, MYF(MY_WME)))) { entry->access=(db_access & host_access); DBUG_ASSERT(key_length < 0xffff); @@ -3447,11 +3451,12 @@ exit: static void init_check_host(void) { DBUG_ENTER("init_check_host"); - (void) my_init_dynamic_array(&acl_wild_hosts,sizeof(struct acl_host_and_ip), + (void) my_init_dynamic_array(&acl_wild_hosts, key_memory_acl_mem, + sizeof(struct acl_host_and_ip), acl_users.elements, 1, MYF(0)); - (void) my_hash_init(&acl_check_hosts,system_charset_info, - acl_users.elements, 0, 0, - (my_hash_get_key) check_get_key, 0, 0); + (void) my_hash_init(&acl_check_hosts,system_charset_info, acl_users.elements, + 0, 0, (my_hash_get_key) check_get_key, 0, 0, + key_memory_acl_mem); if (!allow_all_hosts) { for (uint i=0 ; i < acl_users.elements ; i++) @@ -5097,7 +5102,8 @@ public: void init_hash() { my_hash_init2(&hash_columns, 4, system_charset_info, 0, 0, 0, - (my_hash_get_key) get_key_column, 0, 0, 0); + (my_hash_get_key) get_key_column, 0, 0, 0, + key_memory_acl_memex); } }; @@ -6284,7 +6290,7 @@ static int update_role_db(int merged, int first, privilege_t access, static bool merge_role_db_privileges(ACL_ROLE *grantee, const char *dbname, role_hash_t *rhash) { - Dynamic_array<int> dbs; + Dynamic_array<int> dbs(PSI_INSTRUMENT_MEM); /* Supposedly acl_dbs can be huge, but only a handful of db grants @@ -6503,7 +6509,7 @@ static int update_role_table_columns(GRANT_TABLE *merged, static bool merge_role_table_and_column_privileges(ACL_ROLE *grantee, const char *db, const char *tname, role_hash_t *rhash) { - Dynamic_array<GRANT_TABLE *> grants; + Dynamic_array<GRANT_TABLE *> grants(PSI_INSTRUMENT_MEM); DBUG_ASSERT(MY_TEST(db) == MY_TEST(tname)); // both must be set, or neither /* @@ -6632,7 +6638,7 @@ static bool merge_role_routine_grant_privileges(ACL_ROLE *grantee, DBUG_ASSERT(MY_TEST(db) == MY_TEST(tname)); // both must be set, or neither - Dynamic_array<GRANT_NAME *> grants; + Dynamic_array<GRANT_NAME *> grants(PSI_INSTRUMENT_MEM); /* first, collect routine privileges granted to roles in question */ for (uint i=0 ; i < hash->records ; i++) @@ -6693,7 +6699,7 @@ static int merge_role_privileges(ACL_ROLE *role __attribute__((unused)), grantee->counter= 1; // Mark the grantee as merged. /* if we'll do db/table/routine privileges, create a hash of role names */ - role_hash_t role_hash(role_key); + role_hash_t role_hash(PSI_INSTRUMENT_MEM, role_key); if (data->what != PRIVS_TO_MERGE::GLOBAL) { role_hash.insert(grantee); @@ -7647,16 +7653,21 @@ static bool grant_load(THD *thd, (void) my_hash_init(&column_priv_hash, &my_charset_utf8mb3_bin, 0,0,0, (my_hash_get_key) get_grant_table, - (my_hash_free_key) free_grant_table,0); + (my_hash_free_key) free_grant_table, 0, + key_memory_acl_memex); (void) my_hash_init(&proc_priv_hash, &my_charset_utf8mb3_bin, - 0,0,0, (my_hash_get_key) get_grant_table, 0,0); + 0,0,0, (my_hash_get_key) get_grant_table, 0,0, + key_memory_acl_memex); (void) my_hash_init(&func_priv_hash, &my_charset_utf8mb3_bin, - 0,0,0, (my_hash_get_key) get_grant_table, 0,0); + 0,0,0, (my_hash_get_key) get_grant_table, 0,0, + key_memory_acl_memex); (void) my_hash_init(&package_spec_priv_hash, &my_charset_utf8mb3_bin, - 0,0,0, (my_hash_get_key) get_grant_table, 0,0); + 0,0,0, (my_hash_get_key) get_grant_table, 0,0, + key_memory_acl_memex); (void) my_hash_init(&package_body_priv_hash, &my_charset_utf8mb3_bin, - 0,0,0, (my_hash_get_key) get_grant_table, 0,0); - init_sql_alloc(&grant_memroot, "GRANT", ACL_ALLOC_BLOCK_SIZE, 0, MYF(0)); + 0,0,0, (my_hash_get_key) get_grant_table, 0,0, + key_memory_acl_memex); + init_sql_alloc(key_memory_acl_mem, &grant_memroot, ACL_ALLOC_BLOCK_SIZE, 0, MYF(0)); t_table= tables_priv.table(); c_table= columns_priv.table(); @@ -13180,7 +13191,8 @@ static bool parse_com_change_user_packet(MPVIO_EXT *mpvio, uint packet_length) system_charset_info, user, user_len, thd->charset(), &dummy_errors); - if (!(sctx->user= my_strndup(user_buff, user_len, MYF(MY_WME)))) + if (!(sctx->user= my_strndup(key_memory_MPVIO_EXT_auth_info, user_buff, + user_len, MYF(MY_WME)))) DBUG_RETURN(1); /* Clear variables that are allocated */ @@ -13439,8 +13451,8 @@ static ulong parse_client_handshake_packet(MPVIO_EXT *mpvio, Security_context *sctx= thd->security_ctx; - my_free((char*) sctx->user); - if (!(sctx->user= my_strndup(user, user_len, MYF(MY_WME)))) + my_free(const_cast<char*>(sctx->user)); + if (!(sctx->user= my_strndup(key_memory_MPVIO_EXT_auth_info, user, user_len, MYF(MY_WME)))) return packet_error; /* The error is set by my_strdup(). */ @@ -14249,16 +14261,17 @@ bool acl_authenticate(THD *thd, uint com_change_user_pkt_len) thd->net.net_skip_rest_factor= 2; // skip at most 2*max_packet_size if (mpvio.auth_info.external_user[0]) - sctx->external_user= my_strdup(mpvio.auth_info.external_user, MYF(0)); + sctx->external_user= my_strdup(key_memory_MPVIO_EXT_auth_info, + mpvio.auth_info.external_user, MYF(0)); if (res == CR_OK_HANDSHAKE_COMPLETE) thd->get_stmt_da()->disable_status(); else my_ok(thd); - PSI_CALL_set_thread_user_host - (thd->main_security_ctx.user, (uint)strlen(thd->main_security_ctx.user), - thd->main_security_ctx.host_or_ip, (uint)strlen(thd->main_security_ctx.host_or_ip)); + PSI_CALL_set_thread_account + (thd->main_security_ctx.user, strlen(thd->main_security_ctx.user), + thd->main_security_ctx.host_or_ip, strlen(thd->main_security_ctx.host_or_ip)); /* Ready to handle queries */ DBUG_RETURN(0); diff --git a/sql/sql_array.h b/sql/sql_array.h index 70aeaabc8ec..e0f2485e297 100644 --- a/sql/sql_array.h +++ b/sql/sql_array.h @@ -114,21 +114,21 @@ template <class Elem> class Dynamic_array { DYNAMIC_ARRAY array; public: - Dynamic_array(uint prealloc=16, uint increment=16) + Dynamic_array(PSI_memory_key psi_key, uint prealloc=16, uint increment=16) { - init(prealloc, increment); + init(psi_key, prealloc, increment); } Dynamic_array(MEM_ROOT *root, uint prealloc=16, uint increment=16) { void *init_buffer= alloc_root(root, sizeof(Elem) * prealloc); - my_init_dynamic_array2(&array, sizeof(Elem), init_buffer, + init_dynamic_array2(&array, root->m_psi_key, sizeof(Elem), init_buffer, prealloc, increment, MYF(0)); } - void init(uint prealloc=16, uint increment=16) + void init(PSI_memory_key psi_key, uint prealloc=16, uint increment=16) { - init_dynamic_array2(&array, sizeof(Elem), 0, prealloc, increment, MYF(0)); + init_dynamic_array2(&array, psi_key, sizeof(Elem), 0, prealloc, increment, MYF(0)); } /** diff --git a/sql/sql_audit.cc b/sql/sql_audit.cc index ed175ae4865..2fd92725194 100644 --- a/sql/sql_audit.cc +++ b/sql/sql_audit.cc @@ -88,7 +88,7 @@ static my_bool acquire_plugins(THD *thd, plugin_ref plugin, void *arg) if (unlikely(!thd->audit_class_plugins.buffer)) { /* specify some reasonable initialization defaults */ - my_init_dynamic_array(&thd->audit_class_plugins, + my_init_dynamic_array(&thd->audit_class_plugins, PSI_INSTRUMENT_ME, sizeof(plugin_ref), 16, 16, MYF(0)); } diff --git a/sql/sql_base.cc b/sql/sql_base.cc index 3d49ebc31c8..6a59202609d 100644 --- a/sql/sql_base.cc +++ b/sql/sql_base.cc @@ -566,12 +566,12 @@ bool flush_tables(THD *thd, flush_tables_type flag) write after last time all tables was closed. */ - if (!(tmp_table= (TABLE*) my_malloc(sizeof(*tmp_table), + if (!(tmp_table= (TABLE*) my_malloc(PSI_INSTRUMENT_ME, sizeof(*tmp_table), MYF(MY_WME | MY_THREAD_SPECIFIC)))) DBUG_RETURN(1); - my_init_dynamic_array(&collect_arg.shares, sizeof(TABLE_SHARE*), 100, 100, - MYF(0)); + my_init_dynamic_array(&collect_arg.shares, PSI_INSTRUMENT_ME, + sizeof(TABLE_SHARE*), 100, 100, MYF(0)); collect_arg.flush_type= flag; if (tdc_iterate(thd, (my_hash_walk_action) tc_collect_used_shares, &collect_arg, true)) @@ -2064,7 +2064,8 @@ retry_share: { enum open_frm_error error; /* make a new table */ - if (!(table=(TABLE*) my_malloc(sizeof(*table),MYF(MY_WME)))) + if (!(table=(TABLE*) my_malloc(key_memory_TABLE, sizeof(*table), + MYF(MY_WME)))) goto err_lock; error= open_table_from_share(thd, share, &table_list->alias, @@ -3004,7 +3005,7 @@ static bool auto_repair_table(THD *thd, TABLE_LIST *table_list) thd->clear_error(); - if (!(entry= (TABLE*)my_malloc(sizeof(TABLE), MYF(MY_WME)))) + if (!(entry= (TABLE*)my_malloc(key_memory_TABLE, sizeof(TABLE), MYF(MY_WME)))) return result; if (!(share= tdc_acquire_share(thd, table_list, GTS_TABLE))) diff --git a/sql/sql_binlog.cc b/sql/sql_binlog.cc index 44a885bf0eb..b98792bb43c 100644 --- a/sql/sql_binlog.cc +++ b/sql/sql_binlog.cc @@ -144,7 +144,7 @@ int binlog_defragment(THD *thd) } thd->lex->comment.str= // to be freed by the caller - (char *) my_malloc(thd->lex->comment.length, MYF(MY_WME)); + (char *) my_malloc(PSI_INSTRUMENT_ME, thd->lex->comment.length, MYF(MY_WME)); if (!thd->lex->comment.str) { my_error(ER_OUTOFMEMORY, MYF(ME_FATAL), 1); @@ -242,7 +242,8 @@ void mysql_client_binlog_statement(THD* thd) } decoded_len= my_base64_needed_decoded_length((int)coded_len); - if (!(buf= (char *) my_malloc(decoded_len, MYF(MY_WME)))) + if (!(buf= (char *) my_malloc(key_memory_binlog_statement_buffer, + decoded_len, MYF(MY_WME)))) { my_error(ER_OUTOFMEMORY, MYF(ME_FATAL), 1); goto end; diff --git a/sql/sql_cache.cc b/sql/sql_cache.cc index 5b649b739c6..858a97b66be 100644 --- a/sql/sql_cache.cc +++ b/sql/sql_cache.cc @@ -2728,7 +2728,7 @@ size_t Query_cache::init_cache() DUMP(this); (void) my_hash_init(&queries, &my_charset_bin, def_query_hash_size, 0, 0, - query_cache_query_get_key, 0, 0); + query_cache_query_get_key, 0, 0, key_memory_Query_cache); #ifndef FN_NO_CASE_SENSE /* If lower_case_table_names!=0 then db and table names are already @@ -2739,7 +2739,7 @@ size_t Query_cache::init_cache() and MY_TABLE cases and so again can use binary collation. */ (void) my_hash_init(&tables, &my_charset_bin, def_table_hash_size, 0, 0, - query_cache_table_get_key, 0, 0); + query_cache_table_get_key, 0, 0, key_memory_Query_cache); #else /* On windows, OS/2, MacOS X with HFS+ or any other case insensitive @@ -2753,7 +2753,7 @@ size_t Query_cache::init_cache() lower_case_table_names ? &my_charset_bin : files_charset_info, def_table_hash_size, 0, 0,query_cache_table_get_key, - 0, 0); + 0, 0, PSI_INSTRUMENT_ME); #endif queries_in_cache = 0; diff --git a/sql/sql_class.cc b/sql/sql_class.cc index 2ffb61a98f2..9066d939db6 100644 --- a/sql/sql_class.cc +++ b/sql/sql_class.cc @@ -633,7 +633,7 @@ THD::THD(my_thread_id id, bool is_wsrep_applier) /* statement id */ 0), rli_fake(0), rgi_fake(0), rgi_slave(NULL), protocol_text(this), protocol_binary(this), - m_current_stage_key(0), + m_current_stage_key(0), m_psi(0), in_sub_stmt(0), log_all_errors(0), binlog_unsafe_warning_flags(0), binlog_table_maps(0), @@ -743,8 +743,9 @@ THD::THD(my_thread_id id, bool is_wsrep_applier) the destructor works OK in case of an error. The main_mem_root will be re-initialized in init_for_queries(). */ - init_sql_alloc(&main_mem_root, "THD::main_mem_root", - ALLOC_ROOT_MIN_BLOCK_SIZE, 0, MYF(MY_THREAD_SPECIFIC)); + init_sql_alloc(key_memory_thd_main_mem_root, + &main_mem_root, ALLOC_ROOT_MIN_BLOCK_SIZE, 0, + MYF(MY_THREAD_SPECIFIC)); /* Allocation of user variables for binary logging is always done with main @@ -845,10 +846,12 @@ THD::THD(my_thread_id id, bool is_wsrep_applier) user_connect=(USER_CONN *)0; my_hash_init(&user_vars, system_charset_info, USER_VARS_HASH_SIZE, 0, 0, (my_hash_get_key) get_var_key, - (my_hash_free_key) free_user_var, HASH_THREAD_SPECIFIC); + (my_hash_free_key) free_user_var, HASH_THREAD_SPECIFIC, + key_memory_user_var_entry); my_hash_init(&sequences, system_charset_info, SEQUENCES_HASH_SIZE, 0, 0, (my_hash_get_key) get_sequence_last_key, - (my_hash_free_key) free_sequence_last, HASH_THREAD_SPECIFIC); + (my_hash_free_key) free_sequence_last, HASH_THREAD_SPECIFIC, + PSI_INSTRUMENT_ME); sp_proc_cache= NULL; sp_func_cache= NULL; @@ -857,7 +860,7 @@ THD::THD(my_thread_id id, bool is_wsrep_applier) /* For user vars replication*/ if (opt_bin_log) - my_init_dynamic_array(&user_var_events, + my_init_dynamic_array(&user_var_events, key_memory_user_var_entry, sizeof(BINLOG_USER_VAR_EVENT *), 16, 16, MYF(0)); else bzero((char*) &user_var_events, sizeof(user_var_events)); @@ -885,7 +888,8 @@ THD::THD(my_thread_id id, bool is_wsrep_applier) m_token_array= NULL; if (max_digest_length > 0) { - m_token_array= (unsigned char*) my_malloc(max_digest_length, + m_token_array= (unsigned char*) my_malloc(PSI_INSTRUMENT_ME, + max_digest_length, MYF(MY_WME|MY_THREAD_SPECIFIC)); } @@ -1450,10 +1454,12 @@ void THD::change_user(void) stmt_map.reset(); my_hash_init(&user_vars, system_charset_info, USER_VARS_HASH_SIZE, 0, 0, (my_hash_get_key) get_var_key, - (my_hash_free_key) free_user_var, 0); + (my_hash_free_key) free_user_var, HASH_THREAD_SPECIFIC, + key_memory_user_var_entry); my_hash_init(&sequences, system_charset_info, SEQUENCES_HASH_SIZE, 0, 0, (my_hash_get_key) get_sequence_last_key, - (my_hash_free_key) free_sequence_last, HASH_THREAD_SPECIFIC); + (my_hash_free_key) free_sequence_last, HASH_THREAD_SPECIFIC, + key_memory_user_var_entry); sp_cache_clear(&sp_proc_cache); sp_cache_clear(&sp_func_cache); sp_cache_clear(&sp_package_spec_cache); @@ -1490,7 +1496,8 @@ bool THD::set_db(const LEX_CSTRING *new_db) const char *tmp= NULL; if (new_db->str) { - if (!(tmp= my_strndup(new_db->str, new_db->length, MYF(MY_WME | ME_FATAL)))) + if (!(tmp= my_strndup(key_memory_THD_db, new_db->str, new_db->length, + MYF(MY_WME | ME_FATAL)))) result= 1; } @@ -3931,10 +3938,11 @@ Statement_map::Statement_map() : }; my_hash_init(&st_hash, &my_charset_bin, START_STMT_HASH_SIZE, 0, 0, get_statement_id_as_hash_key, - delete_statement_as_hash_key, MYF(0)); + delete_statement_as_hash_key, MYF(0), + key_memory_prepared_statement_map); my_hash_init(&names_hash, system_charset_info, START_NAME_HASH_SIZE, 0, 0, (my_hash_get_key) get_stmt_name_hash_key, - NULL,MYF(0)); + NULL, MYF(0), key_memory_prepared_statement_map); } @@ -4338,8 +4346,8 @@ void Security_context::skip_grants() bool Security_context::set_user(char *user_arg) { - my_free((char*) user); - user= my_strdup(user_arg, MYF(0)); + my_free(const_cast<char*>(user)); + user= my_strdup(key_memory_MPVIO_EXT_auth_info, user_arg, MYF(0)); return user == 0; } @@ -6601,7 +6609,8 @@ CPP_UNNAMED_NS_START } else { - m_memory= (uchar *) my_malloc(total_length, MYF(MY_WME)); + m_memory= (uchar *) my_malloc(key_memory_Row_data_memory_memory, + total_length, MYF(MY_WME)); m_release_memory_on_destruction= TRUE; } } diff --git a/sql/sql_class.h b/sql/sql_class.h index d756b047ffe..41e6cb52d62 100644 --- a/sql/sql_class.h +++ b/sql/sql_class.h @@ -1929,9 +1929,8 @@ public: m_reopen_array(NULL), m_locked_tables_count(0) { - init_sql_alloc(&m_locked_tables_root, "Locked_tables_list", - MEM_ROOT_BLOCK_SIZE, 0, - MYF(MY_THREAD_SPECIFIC)); + init_sql_alloc(key_memory_locked_table_list, &m_locked_tables_root, + MEM_ROOT_BLOCK_SIZE, 0, MYF(MY_THREAD_SPECIFIC)); } void unlock_locked_tables(THD *thd); void unlock_locked_table(THD *thd, MDL_ticket *mdl_ticket); @@ -2690,9 +2689,8 @@ public: { bzero((char*)this, sizeof(*this)); implicit_xid.null(); - init_sql_alloc(&mem_root, "THD::transactions", - ALLOC_ROOT_MIN_BLOCK_SIZE, 0, - MYF(MY_THREAD_SPECIFIC)); + init_sql_alloc(key_memory_thd_transactions, &mem_root, + ALLOC_ROOT_MIN_BLOCK_SIZE, 0, MYF(MY_THREAD_SPECIFIC)); } } transaction; Global_read_lock global_read_lock; diff --git a/sql/sql_connect.cc b/sql/sql_connect.cc index e2a3c482ae4..7a8a2f7533a 100644 --- a/sql/sql_connect.cc +++ b/sql/sql_connect.cc @@ -81,8 +81,8 @@ int get_or_create_user_conn(THD *thd, const char *user, { /* First connection for user; Create a user connection object */ if (!(uc= ((struct user_conn*) - my_malloc(sizeof(struct user_conn) + temp_len+1, - MYF(MY_WME))))) + my_malloc(key_memory_user_conn, + sizeof(struct user_conn) + temp_len+1, MYF(MY_WME))))) { /* MY_WME ensures an error is set in THD. */ return_val= 1; @@ -324,7 +324,7 @@ void init_max_user_conn(void) #ifndef NO_EMBEDDED_ACCESS_CHECKS my_hash_init(&hash_user_connections, system_charset_info, max_connections, 0, 0, (my_hash_get_key) get_key_conn, - (my_hash_free_key) free_user, 0); + (my_hash_free_key) free_user, 0, key_memory_user_conn); #endif } @@ -485,14 +485,14 @@ void init_global_user_stats(void) { my_hash_init(&global_user_stats, system_charset_info, max_connections, 0, 0, (my_hash_get_key) get_key_user_stats, - (my_hash_free_key) free_user_stats, 0); + (my_hash_free_key) free_user_stats, 0, PSI_INSTRUMENT_ME); } void init_global_client_stats(void) { my_hash_init(&global_client_stats, system_charset_info, max_connections, 0, 0, (my_hash_get_key) get_key_user_stats, - (my_hash_free_key) free_user_stats, 0); + (my_hash_free_key) free_user_stats, 0, PSI_INSTRUMENT_ME); } extern "C" uchar *get_key_table_stats(TABLE_STATS *table_stats, size_t *length, @@ -511,7 +511,7 @@ void init_global_table_stats(void) { my_hash_init(&global_table_stats, system_charset_info, max_connections, 0, 0, (my_hash_get_key) get_key_table_stats, - (my_hash_free_key) free_table_stats, 0); + (my_hash_free_key) free_table_stats, 0, PSI_INSTRUMENT_ME); } extern "C" uchar *get_key_index_stats(INDEX_STATS *index_stats, size_t *length, @@ -530,7 +530,7 @@ void init_global_index_stats(void) { my_hash_init(&global_index_stats, system_charset_info, max_connections, 0, 0, (my_hash_get_key) get_key_index_stats, - (my_hash_free_key) free_index_stats, 0); + (my_hash_free_key) free_index_stats, 0, PSI_INSTRUMENT_ME); } @@ -571,7 +571,7 @@ static bool increment_count_by_name(const char *name, size_t name_length, { /* First connection for this user or client */ if (!(user_stats= ((USER_STATS*) - my_malloc(sizeof(USER_STATS), + my_malloc(PSI_INSTRUMENT_ME, sizeof(USER_STATS), MYF(MY_WME | MY_ZEROFILL))))) return TRUE; // Out of memory @@ -880,7 +880,7 @@ int thd_set_peer_addr(THD *thd, } my_free((void *)thd->main_security_ctx.ip); - if (!(thd->main_security_ctx.ip = my_strdup(ip, MYF(MY_WME)))) + if (!(thd->main_security_ctx.ip = my_strdup(PSI_INSTRUMENT_ME, ip, MYF(MY_WME)))) { /* No error accounting per IP in host_cache, diff --git a/sql/sql_db.cc b/sql/sql_db.cc index ae7f26370fa..b4d96b83dbe 100644 --- a/sql/sql_db.cc +++ b/sql/sql_db.cc @@ -188,7 +188,7 @@ bool my_dboptions_cache_init(void) dboptions_init= 1; error= my_hash_init(&dboptions, table_alias_charset, 32, 0, 0, (my_hash_get_key) dboptions_get_key, - free_dbopt,0); + free_dbopt, 0, key_memory_dboptions_hash); } return error; } @@ -220,7 +220,7 @@ void my_dbopt_cleanup(void) my_hash_free(&dboptions); my_hash_init(&dboptions, table_alias_charset, 32, 0, 0, (my_hash_get_key) dboptions_get_key, - free_dbopt,0); + free_dbopt, 0, key_memory_dboptions_hash); mysql_rwlock_unlock(&LOCK_dboptions); } @@ -290,7 +290,7 @@ static my_bool put_dbopt(const char *dbname, Schema_specification_st *create) /* Options are not in the hash, insert them */ char *tmp_name; char *tmp_comment= NULL; - if (!my_multi_malloc(MYF(MY_WME | MY_ZEROFILL), + if (!my_multi_malloc(key_memory_dboptions_hash, MYF(MY_WME | MY_ZEROFILL), &opt, (uint) sizeof(*opt), &tmp_name, (uint) length+1, &tmp_comment, (uint) DATABASE_COMMENT_MAXLEN+1, NullS)) @@ -1547,8 +1547,8 @@ uint mysql_change_db(THD *thd, const LEX_CSTRING *new_db_name, TODO: fix check_db_name(). */ - new_db_file_name.str= my_strndup(new_db_name->str, new_db_name->length, - MYF(MY_WME)); + new_db_file_name.str= my_strndup(key_memory_THD_db, new_db_name->str, + new_db_name->length, MYF(MY_WME)); new_db_file_name.length= new_db_name->length; if (new_db_file_name.str == NULL) diff --git a/sql/sql_error.cc b/sql/sql_error.cc index 7e6ffb67b94..4045f30a6bd 100644 --- a/sql/sql_error.cc +++ b/sql/sql_error.cc @@ -506,7 +506,7 @@ void Warning_info::init() { /* Initialize sub structures */ DBUG_ASSERT(initialized == 0); - init_sql_alloc(&m_warn_root, "Warning_info", WARN_ALLOC_BLOCK_SIZE, + init_sql_alloc(PSI_INSTRUMENT_ME, &m_warn_root, WARN_ALLOC_BLOCK_SIZE, WARN_ALLOC_PREALLOC_SIZE, MYF(MY_THREAD_SPECIFIC)); initialized= 1; } diff --git a/sql/sql_explain.h b/sql/sql_explain.h index bd8c8a4d499..041f77b6f42 100644 --- a/sql/sql_explain.h +++ b/sql/sql_explain.h @@ -342,7 +342,7 @@ class Explain_union : public Explain_node { public: Explain_union(MEM_ROOT *root, bool is_analyze) : - Explain_node(root), + Explain_node(root), union_members(PSI_INSTRUMENT_MEM), is_recursive_cte(false), fake_select_lex_explain(root, is_analyze) {} diff --git a/sql/sql_handler.cc b/sql/sql_handler.cc index 12119997430..6292631ea7d 100644 --- a/sql/sql_handler.cc +++ b/sql/sql_handler.cc @@ -292,7 +292,8 @@ bool mysql_ha_open(THD *thd, TABLE_LIST *tables, SQL_HANDLER *reopen) if (my_hash_init(&thd->handler_tables_hash, &my_charset_latin1, HANDLER_TABLES_HASH_SIZE, 0, 0, (my_hash_get_key) mysql_ha_hash_get_key, - (my_hash_free_key) mysql_ha_hash_free, 0)) + (my_hash_free_key) mysql_ha_hash_free, 0, + key_memory_THD_handler_tables_hash)) { DBUG_PRINT("exit",("ERROR")); DBUG_RETURN(TRUE); @@ -384,14 +385,14 @@ bool mysql_ha_open(THD *thd, TABLE_LIST *tables, SQL_HANDLER *reopen) /* copy data to sql_handler */ if (!(sql_handler= new SQL_HANDLER(thd))) goto err; - init_alloc_root(&sql_handler->mem_root, "sql_handler", 1024, 0, + init_alloc_root(PSI_INSTRUMENT_ME, &sql_handler->mem_root, 1024, 0, MYF(MY_THREAD_SPECIFIC)); sql_handler->db.length= tables->db.length; sql_handler->table_name.length= tables->table_name.length; sql_handler->handler_name.length= tables->alias.length; - if (!(my_multi_malloc(MY_WME, + if (!(my_multi_malloc(PSI_INSTRUMENT_ME, MYF(MY_WME), &sql_handler->base_data, (uint) sql_handler->db.length + 1, &sql_handler->table_name.str, diff --git a/sql/sql_hset.h b/sql/sql_hset.h index aaecef9f0d4..6af6e1df371 100644 --- a/sql/sql_hset.h +++ b/sql/sql_hset.h @@ -31,19 +31,20 @@ public: Constructs an empty hash. Does not allocate memory, it is done upon the first insert. Thus does not cause or return errors. */ - Hash_set(uchar *(*K)(const T *, size_t *, my_bool), + Hash_set(PSI_memory_key psi_key, uchar *(*K)(const T *, size_t *, my_bool), CHARSET_INFO *cs= &my_charset_bin) { my_hash_clear(&m_hash); m_hash.get_key= (my_hash_get_key)K; m_hash.charset= cs; + m_hash.array.m_psi_key= psi_key; } - Hash_set(CHARSET_INFO *charset, ulong default_array_elements, + Hash_set(PSI_memory_key psi_key, CHARSET_INFO *charset, ulong default_array_elements, size_t key_offset, size_t key_length, my_hash_get_key get_key, void (*free_element)(void*), uint flags) { my_hash_init(&m_hash, charset, default_array_elements, key_offset, - key_length, get_key, free_element, flags); + key_length, get_key, free_element, flags, psi_key); } /** Destroy the hash by freeing the buckets table. Does @@ -65,7 +66,7 @@ public: bool insert(T *value) { my_hash_init_opt(&m_hash, m_hash.charset, START_SIZE, 0, 0, - m_hash.get_key, 0, HASH_UNIQUE); + m_hash.get_key, 0, HASH_UNIQUE, m_hash.array.m_psi_key); return my_hash_insert(&m_hash, reinterpret_cast<const uchar*>(value)); } bool remove(T *value) diff --git a/sql/sql_insert.cc b/sql/sql_insert.cc index 60b60ec1e54..8b1b27c67bf 100644 --- a/sql/sql_insert.cc +++ b/sql/sql_insert.cc @@ -2402,7 +2402,8 @@ bool delayed_get_table(THD *thd, MDL_request *grl_protection_request, di->thd.variables.binlog_annotate_row_events= 0; di->thd.set_db(&table_list->db); - di->thd.set_query(my_strndup(table_list->table_name.str, + di->thd.set_query(my_strndup(PSI_INSTRUMENT_ME, + table_list->table_name.str, table_list->table_name.length, MYF(MY_WME | ME_FATAL)), table_list->table_name.length, system_charset_info); @@ -2731,7 +2732,8 @@ int write_delayed(THD *thd, TABLE *table, enum_duplicates duplic, if (query.str) { char *str; - if (!(str= my_strndup(query.str, query.length, MYF(MY_WME)))) + if (!(str= my_strndup(PSI_INSTRUMENT_ME, query.str, query.length, + MYF(MY_WME)))) goto err; query.str= str; } @@ -2754,7 +2756,8 @@ int write_delayed(THD *thd, TABLE *table, enum_duplicates duplic, ip_len= strlen(thd->security_ctx->ip) + 1; } /* This can't be THREAD_SPECIFIC as it's freed in delayed thread */ - if (!(row->record= (char*) my_malloc(table->s->reclength + + if (!(row->record= (char*) my_malloc(PSI_INSTRUMENT_ME, + table->s->reclength + user_len + host_len + ip_len, MYF(MY_WME)))) goto err; diff --git a/sql/sql_join_cache.cc b/sql/sql_join_cache.cc index 3a509b3d750..9c681061118 100644 --- a/sql/sql_join_cache.cc +++ b/sql/sql_join_cache.cc @@ -937,7 +937,8 @@ int JOIN_CACHE::alloc_buffer() { size_t next_buff_size; - if ((buff= (uchar*) my_malloc(buff_size, MYF(MY_THREAD_SPECIFIC)))) + if ((buff= (uchar*) my_malloc(key_memory_JOIN_CACHE, buff_size, + MYF(MY_THREAD_SPECIFIC)))) break; next_buff_size= buff_size > buff_size_decr ? buff_size-buff_size_decr : 0; @@ -1013,11 +1014,11 @@ bool JOIN_CACHE::shrink_join_buffer_in_ratio(ulonglong n, ulonglong d) int JOIN_CACHE::realloc_buffer() { - int rc; free(); - rc= MY_TEST(!(buff= (uchar*) my_malloc(buff_size, MYF(MY_THREAD_SPECIFIC)))); + buff= (uchar*) my_malloc(key_memory_JOIN_CACHE, buff_size, + MYF(MY_THREAD_SPECIFIC)); reset(TRUE); - return rc; + return buff == NULL; } @@ -2809,12 +2810,12 @@ int JOIN_CACHE_HASHED::init_hash_table() int JOIN_CACHE_HASHED::realloc_buffer() { - int rc; free(); - rc= MY_TEST(!(buff= (uchar*) my_malloc(buff_size, MYF(MY_THREAD_SPECIFIC)))); + buff= (uchar*) my_malloc(key_memory_JOIN_CACHE, buff_size, + MYF(MY_THREAD_SPECIFIC)); init_hash_table(); reset(TRUE); - return rc; + return buff == NULL; } diff --git a/sql/sql_lex.cc b/sql/sql_lex.cc index d448cd0e59e..ae8f0afa18c 100644 --- a/sql/sql_lex.cc +++ b/sql/sql_lex.cc @@ -3826,12 +3826,13 @@ LEX::LEX() default_used(0), is_lex_started(0), limit_rows_examined_cnt(ULONGLONG_MAX) { - init_dynamic_array2(&plugins, sizeof(plugin_ref), plugins_static_buffer, + init_dynamic_array2(&plugins, PSI_INSTRUMENT_ME, + sizeof(plugin_ref), plugins_static_buffer, INITIAL_LEX_PLUGIN_LIST_SIZE, INITIAL_LEX_PLUGIN_LIST_SIZE, 0); reset_query_tables_list(TRUE); mi.init(); - init_dynamic_array2(&delete_gtid_domain, sizeof(uint32), + init_dynamic_array2(&delete_gtid_domain, PSI_INSTRUMENT_ME, sizeof(uint32), gtid_domain_static_buffer, initial_gtid_domain_buffer_size, initial_gtid_domain_buffer_size, 0); @@ -5659,8 +5660,8 @@ bool LEX::set_arena_for_set_stmt(Query_arena *backup) mem_root_for_set_stmt= new MEM_ROOT(); if (unlikely(!(mem_root_for_set_stmt))) DBUG_RETURN(1); - init_sql_alloc(mem_root_for_set_stmt, "set_stmt", - ALLOC_ROOT_SET, ALLOC_ROOT_SET, MYF(MY_THREAD_SPECIFIC)); + init_sql_alloc(PSI_INSTRUMENT_ME, mem_root_for_set_stmt, ALLOC_ROOT_SET, + ALLOC_ROOT_SET, MYF(MY_THREAD_SPECIFIC)); } if (unlikely(!(arena_for_set_stmt= new(mem_root_for_set_stmt) Query_arena_memroot(mem_root_for_set_stmt, diff --git a/sql/sql_lex.h b/sql/sql_lex.h index 84be6e43eaf..fefcdf99e12 100644 --- a/sql/sql_lex.h +++ b/sql/sql_lex.h @@ -510,11 +510,11 @@ struct LEX_MASTER_INFO void init() { bzero(this, sizeof(*this)); - my_init_dynamic_array(&repl_ignore_server_ids, + my_init_dynamic_array(&repl_ignore_server_ids, PSI_INSTRUMENT_ME, sizeof(::server_id), 0, 16, MYF(0)); - my_init_dynamic_array(&repl_do_domain_ids, + my_init_dynamic_array(&repl_do_domain_ids, PSI_INSTRUMENT_ME, sizeof(ulong), 0, 16, MYF(0)); - my_init_dynamic_array(&repl_ignore_domain_ids, + my_init_dynamic_array(&repl_ignore_domain_ids, PSI_INSTRUMENT_ME, sizeof(ulong), 0, 16, MYF(0)); sql_delay= -1; } diff --git a/sql/sql_list.h b/sql/sql_list.h index 9d1c01a484d..91134bcbeb2 100644 --- a/sql/sql_list.h +++ b/sql/sql_list.h @@ -677,7 +677,8 @@ struct ilink struct ilink **prev,*next; static void *operator new(size_t size) throw () { - return (void*)my_malloc((uint)size, MYF(MY_WME | MY_FAE | ME_FATAL)); + return (void*)my_malloc(PSI_INSTRUMENT_ME, + (uint)size, MYF(MY_WME | MY_FAE | ME_FATAL)); } static void operator delete(void* ptr_arg, size_t) { diff --git a/sql/sql_manager.cc b/sql/sql_manager.cc index 2ad8d8a914a..a3d1a7242e4 100644 --- a/sql/sql_manager.cc +++ b/sql/sql_manager.cc @@ -51,7 +51,8 @@ bool mysql_manager_submit(void (*action)()) cb= &(*cb)->next; if (!*cb) { - *cb= (struct handler_cb *)my_malloc(sizeof(struct handler_cb), MYF(MY_WME)); + *cb= (struct handler_cb *)my_malloc(PSI_INSTRUMENT_ME, + sizeof(struct handler_cb), MYF(MY_WME)); if (!*cb) result= TRUE; else diff --git a/sql/sql_parse.cc b/sql/sql_parse.cc index 470b5154c9c..055f2bc736d 100644 --- a/sql/sql_parse.cc +++ b/sql/sql_parse.cc @@ -1010,7 +1010,8 @@ int bootstrap(MYSQL_FILE *file) thd->thread_stack= (char*) &thd; thd->store_globals(); - thd->security_ctx->user= (char*) my_strdup("boot", MYF(MY_WME)); + thd->security_ctx->user= (char*) my_strdup(key_memory_MPVIO_EXT_auth_info, + "boot", MYF(MY_WME)); thd->security_ctx->priv_user[0]= thd->security_ctx->priv_host[0]= thd->security_ctx->priv_role[0]= 0; /* @@ -1464,7 +1465,7 @@ static void wsrep_copy_query(THD *thd) if (thd->wsrep_retry_query) { my_free(thd->wsrep_retry_query); } - thd->wsrep_retry_query = (char *)my_malloc( + thd->wsrep_retry_query = (char *)my_malloc(PSI_INSTRUMENT_ME, thd->wsrep_retry_query_len + 1, MYF(0)); strncpy(thd->wsrep_retry_query, thd->query(), thd->wsrep_retry_query_len); thd->wsrep_retry_query[thd->wsrep_retry_query_len] = '\0'; @@ -1908,7 +1909,7 @@ bool dispatch_command(enum enum_server_command command, THD *thd, thd->m_statement_psi= MYSQL_START_STATEMENT(&thd->m_statement_state, com_statement_info[command].m_key, thd->db.str, thd->db.length, - thd->charset()); + thd->charset(), NULL); THD_STAGE_INFO(thd, stage_init); MYSQL_SET_STATEMENT_TEXT(thd->m_statement_psi, beginning_of_next_stmt, length); @@ -7366,11 +7367,11 @@ bool my_yyoverflow(short **yyss, YYSTYPE **yyvs, size_t *yystacksize) old_info= *yystacksize; *yystacksize= set_zone((int)(*yystacksize)*2,MY_YACC_INIT,MY_YACC_MAX); if (!(state->yacc_yyvs= (uchar*) - my_realloc(state->yacc_yyvs, + my_realloc(key_memory_bison_stack, state->yacc_yyvs, *yystacksize*sizeof(**yyvs), MYF(MY_ALLOW_ZERO_PTR | MY_FREE_ON_ERROR))) || !(state->yacc_yyss= (uchar*) - my_realloc(state->yacc_yyss, + my_realloc(key_memory_bison_stack, state->yacc_yyss, *yystacksize*sizeof(**yyss), MYF(MY_ALLOW_ZERO_PTR | MY_FREE_ON_ERROR)))) return 1; diff --git a/sql/sql_partition.cc b/sql/sql_partition.cc index d9de6e95b89..f722dc54fb4 100644 --- a/sql/sql_partition.cc +++ b/sql/sql_partition.cc @@ -7500,7 +7500,7 @@ void append_row_to_str(String &str, const uchar *row, TABLE *table) rec= row; /* Create a new array of all read fields. */ - fields= (Field**) my_malloc(sizeof(void*) * (num_fields + 1), + fields= (Field**) my_malloc(PSI_INSTRUMENT_ME, sizeof(void*) * (num_fields + 1), MYF(0)); if (!fields) return; diff --git a/sql/sql_plugin.cc b/sql/sql_plugin.cc index bbfbdc3a22e..468dbe9b999 100644 --- a/sql/sql_plugin.cc +++ b/sql/sql_plugin.cc @@ -42,6 +42,12 @@ #include <mysql/plugin_function.h> #include "sql_plugin_compat.h" +static PSI_memory_key key_memory_plugin_mem_root; +static PSI_memory_key key_memory_plugin_int_mem_root; +static PSI_memory_key key_memory_mysql_plugin; +static PSI_memory_key key_memory_mysql_plugin_dl; +static PSI_memory_key key_memory_plugin_bookmark; + #ifdef HAVE_LINK_H #include <link.h> #endif @@ -573,7 +579,7 @@ static my_bool read_mysql_plugin_info(struct st_plugin_dl *plugin_dl, /* no op */; cur= (struct st_maria_plugin*) - my_malloc((i + 1) * sizeof(struct st_maria_plugin), + my_malloc(key_memory_mysql_plugin, (i + 1) * sizeof(struct st_maria_plugin), MYF(MY_ZEROFILL|MY_WME)); if (!cur) { @@ -693,7 +699,7 @@ static my_bool read_maria_plugin_info(struct st_plugin_dl *plugin_dl, /* no op */; cur= (struct st_maria_plugin*) - my_malloc((i + 1) * sizeof(struct st_maria_plugin), + my_malloc(key_memory_mysql_plugin, (i + 1) * sizeof(struct st_maria_plugin), MYF(MY_ZEROFILL|MY_WME)); if (!cur) { @@ -818,7 +824,8 @@ static st_plugin_dl *plugin_dl_add(const LEX_CSTRING *dl, myf MyFlags) if (plugin_dl.nbackups) { size_t bytes= plugin_dl.nbackups * sizeof(plugin_dl.ptr_backup[0]); - plugin_dl.ptr_backup= (st_ptr_backup *)my_malloc(bytes, MYF(0)); + plugin_dl.ptr_backup= (st_ptr_backup *)my_malloc(key_memory_mysql_plugin_dl, + bytes, MYF(0)); if (!plugin_dl.ptr_backup) { restore_ptr_backup(plugin_dl.nbackups, tmp_backup); @@ -830,7 +837,8 @@ static st_plugin_dl *plugin_dl_add(const LEX_CSTRING *dl, myf MyFlags) /* Duplicate and convert dll name */ plugin_dl.dl.length= dl->length * files_charset_info->mbmaxlen + 1; - if (! (plugin_dl.dl.str= (char*) my_malloc(plugin_dl.dl.length, MYF(0)))) + if (! (plugin_dl.dl.str= (char*) my_malloc(key_memory_mysql_plugin_dl, + plugin_dl.dl.length, MYF(0)))) { my_error(ER_OUTOFMEMORY, MyFlags, static_cast<int>(plugin_dl.dl.length)); @@ -977,7 +985,8 @@ static plugin_ref intern_plugin_lock(LEX *lex, plugin_ref rc, memory manager and/or valgrind to track locked references and double unlocks to aid resolving reference counting problems. */ - if (!(plugin= (plugin_ref) my_malloc(sizeof(pi), MYF(MY_WME)))) + if (!(plugin= (plugin_ref) my_malloc(PSI_NOT_INSTRUMENTED, sizeof(pi), + MYF(MY_WME)))) DBUG_RETURN(NULL); *plugin= pi; @@ -1186,7 +1195,8 @@ static enum install_status plugin_add(MEM_ROOT *tmp_root, bool if_not_exists, goto err; if (my_hash_insert(&plugin_hash[plugin->type], (uchar*)tmp_plugin_ptr)) tmp_plugin_ptr->state= PLUGIN_IS_FREED; - init_alloc_root(&tmp_plugin_ptr->mem_root, "plugin", 4096, 4096, MYF(0)); + init_alloc_root(key_memory_plugin_int_mem_root, &tmp_plugin_ptr->mem_root, + 4096, 4096, MYF(0)); if (name->str) DBUG_RETURN(INSTALL_GOOD); // all done @@ -1541,6 +1551,15 @@ static PSI_mutex_info all_plugin_mutexes[]= { &key_LOCK_plugin, "LOCK_plugin", PSI_FLAG_GLOBAL} }; +static PSI_memory_info all_plugin_memory[]= +{ + { &key_memory_plugin_mem_root, "plugin_mem_root", PSI_FLAG_GLOBAL}, + { &key_memory_plugin_int_mem_root, "plugin_int_mem_root", 0}, + { &key_memory_mysql_plugin_dl, "mysql_plugin_dl", 0}, + { &key_memory_mysql_plugin, "mysql_plugin", 0}, + { &key_memory_plugin_bookmark, "plugin_bookmark", PSI_FLAG_GLOBAL} +}; + static void init_plugin_psi_keys(void) { const char* category= "sql"; @@ -1551,7 +1570,12 @@ static void init_plugin_psi_keys(void) count= array_elements(all_plugin_mutexes); PSI_server->register_mutex(category, all_plugin_mutexes, count); + + count= array_elements(all_plugin_memory); + mysql_memory_register(category, all_plugin_memory, count); } +#else +static void init_plugin_psi_keys(void) {} #endif /* HAVE_PSI_INTERFACE */ /* @@ -1578,28 +1602,32 @@ int plugin_init(int *argc, char **argv, int flags) dlopen_count =0; - init_alloc_root(&plugin_mem_root, "plugin", 4096, 4096, MYF(0)); - init_alloc_root(&plugin_vars_mem_root, "plugin_vars", 4096, 4096, MYF(0)); - init_alloc_root(&tmp_root, "plugin_tmp", 4096, 4096, MYF(0)); + init_plugin_psi_keys(); + + init_alloc_root(key_memory_plugin_mem_root, &plugin_mem_root, 4096, 4096, MYF(0)); + init_alloc_root(key_memory_plugin_mem_root, &plugin_vars_mem_root, 4096, 4096, MYF(0)); + init_alloc_root(PSI_NOT_INSTRUMENTED, &tmp_root, 4096, 4096, MYF(0)); if (my_hash_init(&bookmark_hash, &my_charset_bin, 32, 0, 0, - get_bookmark_hash_key, NULL, HASH_UNIQUE)) + get_bookmark_hash_key, NULL, HASH_UNIQUE, + key_memory_plugin_bookmark)) goto err; /* The 80 is from 2016-04-27 when we had 71 default plugins Big enough to avoid many mallocs even in future */ - if (my_init_dynamic_array(&plugin_dl_array, + if (my_init_dynamic_array(&plugin_dl_array, key_memory_mysql_plugin_dl, sizeof(struct st_plugin_dl *), 16, 16, MYF(0)) || - my_init_dynamic_array(&plugin_array, + my_init_dynamic_array(&plugin_array, key_memory_mysql_plugin, sizeof(struct st_plugin_int *), 80, 32, MYF(0))) goto err; for (i= 0; i < MYSQL_MAX_PLUGIN_TYPE_NUM; i++) { if (my_hash_init(&plugin_hash[i], system_charset_info, 32, 0, 0, - get_plugin_hash_key, NULL, HASH_UNIQUE)) + get_plugin_hash_key, NULL, HASH_UNIQUE, + key_memory_plugin_mem_root)) goto err; } @@ -2832,7 +2860,8 @@ static void update_func_str(THD *thd, struct st_mysql_sys_var *var, { char *old= *(char**) tgt; if (value) - *(char**) tgt= my_strdup(value, MYF(0)); + *(char**) tgt= my_strdup(key_memory_global_system_variables, + value, MYF(0)); else *(char**) tgt= 0; my_free(old); @@ -2976,10 +3005,12 @@ static st_bookmark *register_var(const char *plugin, const char *name, if (new_size > global_variables_dynamic_size) { global_system_variables.dynamic_variables_ptr= (char*) - my_realloc(global_system_variables.dynamic_variables_ptr, new_size, + my_realloc(key_memory_global_system_variables, + global_system_variables.dynamic_variables_ptr, new_size, MYF(MY_WME | MY_FAE | MY_ALLOW_ZERO_PTR)); max_system_variables.dynamic_variables_ptr= (char*) - my_realloc(max_system_variables.dynamic_variables_ptr, new_size, + my_realloc(key_memory_global_system_variables, + max_system_variables.dynamic_variables_ptr, new_size, MYF(MY_WME | MY_FAE | MY_ALLOW_ZERO_PTR)); /* Clear the new variable value space. This is required for string @@ -3021,7 +3052,8 @@ void sync_dynamic_session_variables(THD* thd, bool global_lock) uint idx; thd->variables.dynamic_variables_ptr= (char*) - my_realloc(thd->variables.dynamic_variables_ptr, + my_realloc(key_memory_THD_variables, + thd->variables.dynamic_variables_ptr, global_variables_dynamic_size, MYF(MY_WME | MY_FAE | MY_ALLOW_ZERO_PTR)); @@ -3055,7 +3087,7 @@ void sync_dynamic_session_variables(THD* thd, bool global_lock) { char **pp= (char**) (thd->variables.dynamic_variables_ptr + v->offset); if (*pp) - *pp= my_strdup(*pp, MYF(MY_WME|MY_FAE)); + *pp= my_strdup(key_memory_THD_variables, *pp, MYF(MY_WME|MY_FAE)); } } @@ -3912,7 +3944,7 @@ static int construct_options(MEM_ROOT *mem_root, struct st_plugin_int *tmp, (opt->flags & PLUGIN_VAR_MEMALLOC)) { char *def_val= *(char**)var_def_ptr(opt); - *(char**)val= def_val ? my_strdup(def_val, MYF(0)) : NULL; + *(char**)val= def_val ? my_strdup(PSI_INSTRUMENT_ME, def_val, MYF(0)) : NULL; } else memcpy(val, var_def_ptr(opt), var_storage_size(opt->flags)); @@ -4349,9 +4381,7 @@ int thd_setspecific(MYSQL_THD thd, MYSQL_THD_KEY_T key, void *value) void plugin_mutex_init() { -#ifdef HAVE_PSI_INTERFACE init_plugin_psi_keys(); -#endif mysql_mutex_init(key_LOCK_plugin, &LOCK_plugin, MY_MUTEX_INIT_FAST); } diff --git a/sql/sql_prepare.cc b/sql/sql_prepare.cc index dcf445f3cfb..d0f2ca512cc 100644 --- a/sql/sql_prepare.cc +++ b/sql/sql_prepare.cc @@ -3800,10 +3800,9 @@ Prepared_statement::Prepared_statement(THD *thd_arg) read_types(0), m_sql_mode(thd->variables.sql_mode) { - init_sql_alloc(&main_mem_root, "Prepared_statement", - thd_arg->variables.query_alloc_block_size, - thd_arg->variables.query_prealloc_size, - MYF(MY_THREAD_SPECIFIC)); + init_sql_alloc(key_memory_prepared_statement_main_mem_root, + &main_mem_root, thd_arg->variables.query_alloc_block_size, + thd_arg->variables.query_prealloc_size, MYF(MY_THREAD_SPECIFIC)); *last_error= '\0'; } @@ -5388,8 +5387,8 @@ bool Protocol_local::send_result_set_metadata(List<Item> *columns, uint) { DBUG_ASSERT(m_rset == 0 && !alloc_root_inited(&m_rset_root)); - init_sql_alloc(&m_rset_root, "send_result_set_metadata", - MEM_ROOT_BLOCK_SIZE, 0, MYF(MY_THREAD_SPECIFIC)); + init_sql_alloc(PSI_INSTRUMENT_ME, &m_rset_root, MEM_ROOT_BLOCK_SIZE, 0, + MYF(MY_THREAD_SPECIFIC)); if (! (m_rset= new (&m_rset_root) List<Ed_row>)) return TRUE; diff --git a/sql/sql_profile.cc b/sql/sql_profile.cc index cee55761a98..2a47aa846eb 100644 --- a/sql/sql_profile.cc +++ b/sql/sql_profile.cc @@ -200,7 +200,8 @@ void PROF_MEASUREMENT::set_label(const char *status_arg, sizes[1]= (function_arg == NULL) ? 0 : strlen(function_arg) + 1; sizes[2]= (file_arg == NULL) ? 0 : strlen(file_arg) + 1; - allocated_status_memory= (char *) my_malloc(sizes[0] + sizes[1] + sizes[2], MYF(0)); + allocated_status_memory= (char *) my_malloc(key_memory_PROFILE, sizes[0] + + sizes[1] + sizes[2], MYF(0)); DBUG_ASSERT(allocated_status_memory != NULL); cursor= allocated_status_memory; @@ -289,7 +290,7 @@ void QUERY_PROFILE::set_query_source(char *query_source_arg, size_t query_length DBUG_ASSERT(query_source == NULL); /* we don't leak memory */ if (query_source_arg != NULL) - query_source= my_strndup(query_source_arg, length, MYF(0)); + query_source= my_strndup(key_memory_PROFILE, query_source_arg, length, MYF(0)); } void QUERY_PROFILE::new_status(const char *status_arg, diff --git a/sql/sql_profile.h b/sql/sql_profile.h index b0b1642ee02..85018a2598b 100644 --- a/sql/sql_profile.h +++ b/sql/sql_profile.h @@ -54,6 +54,7 @@ int make_profile_table_for_show(THD *thd, ST_SCHEMA_TABLE *schema_table); #include <sys/resource.h> #endif +extern PSI_memory_key key_memory_queue_item; class PROF_MEASUREMENT; class QUERY_PROFILE; @@ -100,7 +101,8 @@ public: { struct queue_item *new_item; - new_item= (struct queue_item *) my_malloc(sizeof(struct queue_item), MYF(0)); + new_item= (struct queue_item *) my_malloc(key_memory_queue_item, + sizeof(struct queue_item), MYF(0)); new_item->payload= payload; diff --git a/sql/sql_repl.cc b/sql/sql_repl.cc index 5bfa29b72c4..73fc01618e3 100644 --- a/sql/sql_repl.cc +++ b/sql/sql_repl.cc @@ -1221,7 +1221,8 @@ check_slave_start_position(binlog_send_info *info, const char **errormsg, if (!delete_list) { if (!(delete_list= (slave_connection_state::entry **) - my_malloc(sizeof(*delete_list) * st->hash.records, MYF(MY_WME)))) + my_malloc(PSI_INSTRUMENT_ME, + sizeof(*delete_list) * st->hash.records, MYF(MY_WME)))) { *errormsg= "Out of memory while checking slave start position"; err= ER_OUT_OF_RESOURCES; @@ -1283,8 +1284,9 @@ gtid_find_binlog_file(slave_connection_state *state, char *out_name, const char *errormsg= NULL; char buf[FN_REFLEN]; - init_alloc_root(&memroot, "gtid_find_binlog_file", - 8192, 0, MYF(MY_THREAD_SPECIFIC)); + init_alloc_root(PSI_INSTRUMENT_ME, &memroot, + 10*(FN_REFLEN+sizeof(binlog_file_entry)), 0, + MYF(MY_THREAD_SPECIFIC)); if (!(list= get_binlog_list(&memroot))) { errormsg= "Out of memory while looking for GTID position in binlog"; @@ -4307,8 +4309,7 @@ bool show_binlogs(THD* thd) Protocol::SEND_NUM_ROWS | Protocol::SEND_EOF)) DBUG_RETURN(TRUE); - init_alloc_root(&mem_root, "binlog_file_list", 8192, 0, - MYF(MY_THREAD_SPECIFIC)); + init_alloc_root(PSI_INSTRUMENT_ME, &mem_root, 8192, 0, MYF(MY_THREAD_SPECIFIC)); retry: /* The current mutex handling here is to ensure we get the current log position diff --git a/sql/sql_select.cc b/sql/sql_select.cc index f48edc8c180..9d96de96ff0 100644 --- a/sql/sql_select.cc +++ b/sql/sql_select.cc @@ -6769,7 +6769,7 @@ update_ref_and_keys(THD *thd, DYNAMIC_ARRAY *keyuse,JOIN_TAB *join_tab, /* set a barrier for the array of SARGABLE_PARAM */ (*sargables)[0].field= 0; - if (my_init_dynamic_array2(keyuse, sizeof(KEYUSE), + if (my_init_dynamic_array2(keyuse, thd->mem_root->m_psi_key, sizeof(KEYUSE), thd->alloc(sizeof(KEYUSE) * 20), 20, 64, MYF(MY_THREAD_SPECIFIC))) DBUG_RETURN(TRUE); @@ -18237,7 +18237,7 @@ TABLE *Create_tmp_table::start(THD *thd, if (param->precomputed_group_by) copy_func_count+= param->sum_func_count; - init_sql_alloc(&own_root, "tmp_table", TABLE_ALLOC_BLOCK_SIZE, 0, + init_sql_alloc(key_memory_TABLE, &own_root, TABLE_ALLOC_BLOCK_SIZE, 0, MYF(MY_THREAD_SPECIFIC)); if (!multi_alloc_root(&own_root, @@ -24009,21 +24009,21 @@ static int remove_dup_with_hash_index(THD *thd, TABLE *table, Field **ptr; DBUG_ENTER("remove_dup_with_hash_index"); - if (unlikely(!my_multi_malloc(MYF(MY_WME), - &key_buffer, - (uint) ((key_length + extra_length) * - (long) file->stats.records), - &field_lengths, - (uint) (field_count*sizeof(*field_lengths)), - NullS))) + if (!my_multi_malloc(key_memory_hash_index_key_buffer, MYF(MY_WME), + &key_buffer, + (uint) ((key_length + extra_length) * + (long) file->stats.records), + &field_lengths, + (uint) (field_count*sizeof(*field_lengths)), + NullS)) DBUG_RETURN(1); for (ptr= first_field, field_length=field_lengths ; *ptr ; ptr++) (*field_length++)= (*ptr)->sort_length(); - if (unlikely(my_hash_init(&hash, &my_charset_bin, - (uint) file->stats.records, 0, - key_length, (my_hash_get_key) 0, 0, 0))) + if (my_hash_init(&hash, &my_charset_bin, (uint) file->stats.records, 0, + key_length, (my_hash_get_key) 0, 0, 0, + key_memory_hash_index_key_buffer)) { my_free(key_buffer); DBUG_RETURN(1); @@ -27834,8 +27834,8 @@ JOIN::reoptimize(Item *added_where, table_map join_tables, reset_query_plan(); if (!keyuse.buffer && - my_init_dynamic_array(&keyuse, sizeof(KEYUSE), 20, 64, - MYF(MY_THREAD_SPECIFIC))) + my_init_dynamic_array(&keyuse, thd->mem_root->m_psi_key, sizeof(KEYUSE), + 20, 64, MYF(MY_THREAD_SPECIFIC))) { delete_dynamic(&added_keyuse); return REOPT_ERROR; diff --git a/sql/sql_select.h b/sql/sql_select.h index 616d4769e2f..3788abce423 100644 --- a/sql/sql_select.h +++ b/sql/sql_select.h @@ -1095,7 +1095,7 @@ protected: keyuse.buffer= NULL; keyuse.malloc_flags= 0; best_positions= 0; /* To detect errors */ - error= my_multi_malloc(MYF(MY_WME), + error= my_multi_malloc(PSI_INSTRUMENT_ME, MYF(MY_WME), &best_positions, sizeof(*best_positions) * (tables + 1), &join_tab_keyuse, diff --git a/sql/sql_servers.cc b/sql/sql_servers.cc index 7913a7d2b9f..654e2ee7aac 100644 --- a/sql/sql_servers.cc +++ b/sql/sql_servers.cc @@ -93,6 +93,8 @@ static uchar *servers_cache_get_key(FOREIGN_SERVER *server, size_t *length, DBUG_RETURN((uchar*) server->server_name); } +static PSI_memory_key key_memory_servers; + #ifdef HAVE_PSI_INTERFACE static PSI_rwlock_key key_rwlock_THR_LOCK_servers; @@ -101,6 +103,11 @@ static PSI_rwlock_info all_servers_cache_rwlocks[]= { &key_rwlock_THR_LOCK_servers, "THR_LOCK_servers", PSI_FLAG_GLOBAL} }; +static PSI_memory_info all_servers_cache_memory[]= +{ + { &key_memory_servers, "servers_cache", PSI_FLAG_GLOBAL} +}; + static void init_servers_cache_psi_keys(void) { const char* category= "sql"; @@ -111,6 +118,9 @@ static void init_servers_cache_psi_keys(void) count= array_elements(all_servers_cache_rwlocks); PSI_server->register_rwlock(category, all_servers_cache_rwlocks, count); + + count= array_elements(all_servers_cache_memory); + mysql_memory_register(category, all_servers_cache_memory, count); } #endif /* HAVE_PSI_INTERFACE */ @@ -149,14 +159,15 @@ bool servers_init(bool dont_read_servers_table) /* initialise our servers cache */ if (my_hash_init(&servers_cache, system_charset_info, 32, 0, 0, - (my_hash_get_key) servers_cache_get_key, 0, 0)) + (my_hash_get_key) servers_cache_get_key, 0, 0, + key_memory_servers)) { return_val= TRUE; /* we failed, out of memory? */ goto end; } /* Initialize the mem root for data */ - init_sql_alloc(&mem, "servers", ACL_ALLOC_BLOCK_SIZE, 0, + init_sql_alloc(key_memory_servers, &mem, ACL_ALLOC_BLOCK_SIZE, 0, MYF(MY_THREAD_SPECIFIC)); if (dont_read_servers_table) @@ -206,7 +217,7 @@ static bool servers_load(THD *thd, TABLE_LIST *tables) my_hash_reset(&servers_cache); free_root(&mem, MYF(0)); - init_sql_alloc(&mem, "servers_load", ACL_ALLOC_BLOCK_SIZE, 0, MYF(0)); + init_sql_alloc(key_memory_servers, &mem, ACL_ALLOC_BLOCK_SIZE, 0, MYF(0)); if (init_read_record(&read_record_info,thd,table=tables[0].table, NULL, NULL, 1,0, FALSE)) diff --git a/sql/sql_show.cc b/sql/sql_show.cc index 040545f8e1b..cc08dadf2b8 100644 --- a/sql/sql_show.cc +++ b/sql/sql_show.cc @@ -571,8 +571,8 @@ static bool skip_ignored_dir_check= TRUE; bool ignore_db_dirs_init() { - return my_init_dynamic_array(&ignore_db_dirs_array, sizeof(LEX_CSTRING *), - 0, 0, MYF(0)); + return my_init_dynamic_array(&ignore_db_dirs_array, key_memory_ignored_db, + sizeof(LEX_STRING *), 0, 0, MYF(0)); } @@ -620,8 +620,8 @@ push_ignored_db_dir(char *path) return true; // No need to normalize, it's only a directory name, not a path. - if (!my_multi_malloc(0, - &new_elt, sizeof(LEX_CSTRING), + if (!my_multi_malloc(key_memory_ignored_db, MYF(0), + &new_elt, sizeof(LEX_STRING), &new_elt_buffer, path_len + 1, NullS)) return true; @@ -701,7 +701,7 @@ void ignore_db_dirs_append(const char *dirname_arg) LEX_STRING *new_entry; size_t len= strlen(dirname_arg); - if (!my_multi_malloc(0, + if (!my_multi_malloc(PSI_INSTRUMENT_ME, MYF(0), &new_entry, sizeof(LEX_STRING), &new_entry_buf, len + 1, NullS)) @@ -723,7 +723,7 @@ void ignore_db_dirs_append(const char *dirname_arg) // Add one for comma and one for \0. size_t newlen= curlen + len + 1 + 1; char *new_db_dirs; - if (!(new_db_dirs= (char*)my_malloc(newlen ,MYF(0)))) + if (!(new_db_dirs= (char*)my_malloc(PSI_INSTRUMENT_ME, newlen, MYF(0)))) { // This is not a critical condition return; @@ -754,7 +754,7 @@ ignore_db_dirs_process_additions() character_set_filesystem : &my_charset_bin, 0, 0, 0, db_dirs_hash_get_key, dispose_db_dir, - HASH_UNIQUE)) + HASH_UNIQUE, key_memory_ignored_db)) return true; /* len starts from 1 because of the terminating zero. */ @@ -776,7 +776,8 @@ ignore_db_dirs_process_additions() len--; /* +1 the terminating zero */ - ptr= opt_ignore_db_dirs= (char *) my_malloc(len + 1, MYF(0)); + ptr= opt_ignore_db_dirs= (char *) my_malloc(key_memory_ignored_db, len + 1, + MYF(0)); if (!ptr) return true; @@ -3362,7 +3363,8 @@ int add_status_vars(SHOW_VAR *list) if (status_vars_inited) mysql_rwlock_wrlock(&LOCK_all_status_vars); if (!all_status_vars.buffer && // array is not allocated yet - do it now - my_init_dynamic_array(&all_status_vars, sizeof(SHOW_VAR), 250, 50, MYF(0))) + my_init_dynamic_array(&all_status_vars, PSI_INSTRUMENT_ME, + sizeof(SHOW_VAR), 250, 50, MYF(0))) { res= 1; goto err; @@ -4890,8 +4892,8 @@ static int fill_schema_table_from_frm(THD *thd, TABLE *table, if (schema_table->i_s_requested_object & OPEN_TRIGGER_ONLY) { - init_sql_alloc(&tbl.mem_root, "fill_schema_table_from_frm", - TABLE_ALLOC_BLOCK_SIZE, 0, MYF(0)); + init_sql_alloc(key_memory_table_triggers_list, + &tbl.mem_root, TABLE_ALLOC_BLOCK_SIZE, 0, MYF(0)); if (!Table_triggers_list::check_n_load(thd, db_name, table_name, &tbl, 1)) { @@ -5045,7 +5047,7 @@ int get_all_tables(THD *thd, TABLE_LIST *tables, COND *cond) ST_SCHEMA_TABLE *schema_table= tables->schema_table; IS_table_read_plan *plan= tables->is_table_read_plan; enum enum_schema_tables schema_table_idx; - Dynamic_array<LEX_CSTRING*> db_names; + Dynamic_array<LEX_CSTRING*> db_names(PSI_INSTRUMENT_MEM); Item *partial_cond= plan->partial_cond; int error= 1; Open_tables_backup open_tables_state_backup; @@ -5114,7 +5116,7 @@ int get_all_tables(THD *thd, TABLE_LIST *tables, COND *cond) goto err; /* Use tmp_mem_root to allocate data for opened tables */ - init_alloc_root(&tmp_mem_root, "get_all_tables", SHOW_ALLOC_BLOCK_SIZE, + init_alloc_root(PSI_INSTRUMENT_ME, &tmp_mem_root, SHOW_ALLOC_BLOCK_SIZE, SHOW_ALLOC_BLOCK_SIZE, MY_THREAD_SPECIFIC); for (size_t i=0; i < db_names.elements(); i++) @@ -5129,7 +5131,7 @@ int get_all_tables(THD *thd, TABLE_LIST *tables, COND *cond) acl_get(sctx->host, sctx->ip, sctx->priv_user, db_name->str, 0)) #endif { - Dynamic_array<LEX_CSTRING*> table_names; + Dynamic_array<LEX_CSTRING*> table_names(PSI_INSTRUMENT_MEM); int res= make_table_name_list(thd, &table_names, lex, &plan->lookup_field_vals, db_name); if (unlikely(res == 2)) /* Not fatal error, continue */ @@ -5245,7 +5247,7 @@ int fill_schema_schemata(THD *thd, TABLE_LIST *tables, COND *cond) */ LOOKUP_FIELD_VALUES lookup_field_vals; - Dynamic_array<LEX_CSTRING*> db_names; + Dynamic_array<LEX_CSTRING*> db_names(PSI_INSTRUMENT_MEM); Schema_specification_st create; TABLE *table= tables->table; #ifndef NO_EMBEDDED_ACCESS_CHECKS @@ -9533,7 +9535,8 @@ int initialize_schema_table(st_plugin_int *plugin) ST_SCHEMA_TABLE *schema_table; DBUG_ENTER("initialize_schema_table"); - if (!(schema_table= (ST_SCHEMA_TABLE *)my_malloc(sizeof(ST_SCHEMA_TABLE), + if (!(schema_table= (ST_SCHEMA_TABLE *)my_malloc(key_memory_ST_SCHEMA_TABLE, + sizeof(ST_SCHEMA_TABLE), MYF(MY_WME | MY_ZEROFILL)))) DBUG_RETURN(1); /* Historical Requirement */ diff --git a/sql/sql_sort.h b/sql/sql_sort.h index 3635bc32974..5b3f5a67d17 100644 --- a/sql/sql_sort.h +++ b/sql/sql_sort.h @@ -183,7 +183,7 @@ public: /// rr_unpack_from_tempfile needs an extra buffer when unpacking. uchar *allocate_addon_buf(uint sz) { - m_addon_buf= (uchar *)my_malloc(sz, MYF(MY_WME | MY_THREAD_SPECIFIC)); + m_addon_buf= (uchar *)my_malloc(PSI_INSTRUMENT_ME, sz, MYF(MY_WME | MY_THREAD_SPECIFIC)); if (m_addon_buf) m_addon_buf_length= sz; return m_addon_buf; diff --git a/sql/sql_statistics.cc b/sql/sql_statistics.cc index a94fb1196b4..55e8e52c052 100644 --- a/sql/sql_statistics.cc +++ b/sql/sql_statistics.cc @@ -1432,7 +1432,7 @@ public: */ bool init(uint n_keyparts) { - if (!(rowid_buf= (uchar*)my_malloc(rowid_size, MYF(0)))) + if (!(rowid_buf= (uchar*)my_malloc(PSI_INSTRUMENT_ME, rowid_size, MYF(0)))) return true; if (open_cached_file(&io_cache, mysql_tmpdir, TEMP_PREFIX, diff --git a/sql/sql_string.cc b/sql/sql_string.cc index 4ddc467794f..2fc6ae0ad7d 100644 --- a/sql/sql_string.cc +++ b/sql/sql_string.cc @@ -41,8 +41,8 @@ bool Binary_string::real_alloc(size_t length) if (Alloced_length < arg_length) { free(); - if (!(Ptr=(char*) my_malloc(arg_length,MYF(MY_WME | - (thread_specific ? + if (!(Ptr=(char*) my_malloc(PSI_INSTRUMENT_ME, + arg_length,MYF(MY_WME | (thread_specific ? MY_THREAD_SPECIFIC : 0))))) return TRUE; DBUG_ASSERT(length < UINT_MAX32); @@ -92,13 +92,13 @@ bool Binary_string::realloc_raw(size_t alloc_length) return TRUE; /* Overflow */ if (alloced) { - if (!(new_ptr= (char*) my_realloc(Ptr,len, + if (!(new_ptr= (char*) my_realloc(PSI_INSTRUMENT_ME, Ptr,len, MYF(MY_WME | (thread_specific ? MY_THREAD_SPECIFIC : 0))))) return TRUE; // Signal error } - else if ((new_ptr= (char*) my_malloc(len, + else if ((new_ptr= (char*) my_malloc(PSI_INSTRUMENT_ME, len, MYF(MY_WME | (thread_specific ? MY_THREAD_SPECIFIC : 0))))) @@ -1236,3 +1236,25 @@ bool String::append_semi_hex(const char *s, uint len, CHARSET_INFO *cs) str_length+= nbytes; return false; } + +// Shrink the buffer, but only if it is allocated on the heap. +void Binary_string::shrink(size_t arg_length) +{ + if (!is_alloced()) + return; + if (ALIGN_SIZE(arg_length + 1) < Alloced_length) + { + char* new_ptr; + if (!(new_ptr = (char*)my_realloc(STRING_PSI_MEMORY_KEY, Ptr, arg_length, + MYF(thread_specific ? MY_THREAD_SPECIFIC : 0)))) + { + Alloced_length = 0; + real_alloc(arg_length); + } + else + { + Ptr = new_ptr; + Alloced_length = (uint32)arg_length; + } + } +} diff --git a/sql/sql_string.h b/sql/sql_string.h index eb69d21eaeb..4eeac0a8a82 100644 --- a/sql/sql_string.h +++ b/sql/sql_string.h @@ -30,6 +30,13 @@ #include "sql_list.h" class String; +#ifdef MYSQL_SERVER +extern PSI_memory_key key_memory_String_value; +#define STRING_PSI_MEMORY_KEY key_memory_String_value +#else +#define STRING_PSI_MEMORY_KEY PSI_NOT_INSTRUMENTED +#endif + typedef struct st_io_cache IO_CACHE; typedef struct st_mem_root MEM_ROOT; @@ -659,28 +666,8 @@ public: return realloc_with_extra(arg_length); } // Shrink the buffer, but only if it is allocated on the heap. - inline void shrink(size_t arg_length) - { - if (!is_alloced()) - return; - if (ALIGN_SIZE(arg_length+1) < Alloced_length) - { - char *new_ptr; - if (unlikely(!(new_ptr=(char*) - my_realloc(Ptr, - arg_length,MYF((thread_specific ? - MY_THREAD_SPECIFIC : 0)))))) - { - Alloced_length= 0; - real_alloc(arg_length); - } - else - { - Ptr= new_ptr; - Alloced_length= (uint32) arg_length; - } - } - } + void shrink(size_t arg_length); + void move(Binary_string &s) { set_alloced(s.Ptr, s.str_length, s.Alloced_length); diff --git a/sql/sql_table.cc b/sql/sql_table.cc index e64fddad4c0..4239fcc8de7 100644 --- a/sql/sql_table.cc +++ b/sql/sql_table.cc @@ -1127,8 +1127,8 @@ static int execute_ddl_log_action(THD *thd, DDL_LOG_ENTRY *ddl_log_entry) ddl_log_entry->tmp_name)); handler_name.str= (char*)ddl_log_entry->handler_name; handler_name.length= strlen(ddl_log_entry->handler_name); - init_sql_alloc(&mem_root, "execute_ddl_log_action", TABLE_ALLOC_BLOCK_SIZE, - 0, MYF(MY_THREAD_SPECIFIC)); + init_sql_alloc(key_memory_gdl, &mem_root, TABLE_ALLOC_BLOCK_SIZE, 0, + MYF(MY_THREAD_SPECIFIC)); if (!strcmp(ddl_log_entry->handler_name, reg_ext)) frm_action= TRUE; else @@ -1162,7 +1162,7 @@ static int execute_ddl_log_action(THD *thd, DDL_LOG_ENTRY *ddl_log_entry) } #ifdef WITH_PARTITION_STORAGE_ENGINE strxmov(to_path, ddl_log_entry->name, par_ext, NullS); - (void) mysql_file_delete(key_file_partition, to_path, MYF(MY_WME)); + (void) mysql_file_delete(key_file_partition_ddl_log, to_path, MYF(MY_WME)); #endif } else @@ -1200,7 +1200,7 @@ static int execute_ddl_log_action(THD *thd, DDL_LOG_ENTRY *ddl_log_entry) #ifdef WITH_PARTITION_STORAGE_ENGINE strxmov(to_path, ddl_log_entry->name, par_ext, NullS); strxmov(from_path, ddl_log_entry->from_name, par_ext, NullS); - (void) mysql_file_rename(key_file_partition, from_path, to_path, MYF(MY_WME)); + (void) mysql_file_rename(key_file_partition_ddl_log, from_path, to_path, MYF(MY_WME)); #endif } else @@ -1297,7 +1297,7 @@ static bool get_free_ddl_log_entry(DDL_LOG_MEMORY_ENTRY **active_entry, if (global_ddl_log.first_free == NULL) { - if (!(used_entry= (DDL_LOG_MEMORY_ENTRY*)my_malloc( + if (!(used_entry= (DDL_LOG_MEMORY_ENTRY*)my_malloc(key_memory_DDL_LOG_MEMORY_ENTRY, sizeof(DDL_LOG_MEMORY_ENTRY), MYF(MY_WME)))) { sql_print_error("Failed to allocate memory for ddl log free list"); diff --git a/sql/sql_test.cc b/sql/sql_test.cc index 07e2d5e084e..c14f15908b1 100644 --- a/sql/sql_test.cc +++ b/sql/sql_test.cc @@ -466,8 +466,10 @@ static void display_table_locks(void) void *saved_base; DYNAMIC_ARRAY saved_table_locks; - (void) my_init_dynamic_array(&saved_table_locks,sizeof(TABLE_LOCK_INFO), - tc_records() + 20, 50, MYF(0)); + (void) my_init_dynamic_array(&saved_table_locks, + key_memory_locked_thread_list, + sizeof(TABLE_LOCK_INFO), tc_records() + 20, 50, + MYF(0)); mysql_mutex_lock(&THR_LOCK_lock); for (list= thr_lock_thread_list; list; list= list_rest(list)) { diff --git a/sql/sql_time.cc b/sql/sql_time.cc index 8a9311ae577..c08e54bed87 100644 --- a/sql/sql_time.cc +++ b/sql/sql_time.cc @@ -830,7 +830,8 @@ DATE_TIME_FORMAT *date_time_format_copy(THD *thd, DATE_TIME_FORMAT *format) if (thd) new_format= (DATE_TIME_FORMAT *) thd->alloc(length); else - new_format= (DATE_TIME_FORMAT *) my_malloc(length, MYF(MY_WME)); + new_format= (DATE_TIME_FORMAT *) my_malloc(key_memory_DATE_TIME_FORMAT, + length, MYF(MY_WME)); if (new_format) { /* Put format string after current pos */ diff --git a/sql/sql_trigger.cc b/sql/sql_trigger.cc index 0ae3d58b11f..d683bdc7055 100644 --- a/sql/sql_trigger.cc +++ b/sql/sql_trigger.cc @@ -1813,8 +1813,8 @@ bool Table_triggers_list::drop_all_triggers(THD *thd, const LEX_CSTRING *db, DBUG_ENTER("Triggers::drop_all_triggers"); table.reset(); - init_sql_alloc(&table.mem_root, "Triggers::drop_all_triggers", 8192, 0, - MYF(0)); + init_sql_alloc(key_memory_Table_trigger_dispatcher, + &table.mem_root, 8192, 0, MYF(0)); if (Table_triggers_list::check_n_load(thd, db, name, &table, 1)) { @@ -2065,8 +2065,8 @@ bool Table_triggers_list::change_table_name(THD *thd, const LEX_CSTRING *db, DBUG_ENTER("Triggers::change_table_name"); table.reset(); - init_sql_alloc(&table.mem_root, "Triggers::change_table_name", 8192, 0, - MYF(0)); + init_sql_alloc(key_memory_Table_trigger_dispatcher, + &table.mem_root, 8192, 0, MYF(0)); /* This method interfaces the mysql server code protected by diff --git a/sql/sql_type.h b/sql/sql_type.h index 588984f08bc..f87e398bd71 100644 --- a/sql/sql_type.h +++ b/sql/sql_type.h @@ -7287,7 +7287,7 @@ private: const Type_handler *handler2) const; public: Type_aggregator(bool is_commutative= false) - :m_is_commutative(is_commutative) + :m_is_commutative(is_commutative), m_array(PSI_INSTRUMENT_MEM) { } bool add(const Type_handler *handler1, const Type_handler *handler2, diff --git a/sql/sql_udf.cc b/sql/sql_udf.cc index 35c799d4a86..38328c91db3 100644 --- a/sql/sql_udf.cc +++ b/sql/sql_udf.cc @@ -110,6 +110,8 @@ extern "C" uchar* get_hash_key(const uchar *buff, size_t *length, return (uchar*) udf->name.str; } +static PSI_memory_key key_memory_udf_mem; + #ifdef HAVE_PSI_INTERFACE static PSI_rwlock_key key_rwlock_THR_LOCK_udf; @@ -118,6 +120,11 @@ static PSI_rwlock_info all_udf_rwlocks[]= { &key_rwlock_THR_LOCK_udf, "THR_LOCK_udf", PSI_FLAG_GLOBAL} }; +static PSI_memory_info all_udf_memory[]= +{ + { &key_memory_udf_mem, "udf_mem", PSI_FLAG_GLOBAL} +}; + static void init_udf_psi_keys(void) { const char* category= "sql"; @@ -128,6 +135,9 @@ static void init_udf_psi_keys(void) count= array_elements(all_udf_rwlocks); PSI_server->register_rwlock(category, all_udf_rwlocks, count); + + count= array_elements(all_udf_memory); + mysql_memory_register(category, all_udf_memory, count); } #endif @@ -154,10 +164,11 @@ void udf_init() mysql_rwlock_init(key_rwlock_THR_LOCK_udf, &THR_LOCK_udf); - init_sql_alloc(&mem, "udf", UDF_ALLOC_BLOCK_SIZE, 0, MYF(0)); + init_sql_alloc(key_memory_udf_mem, &mem, UDF_ALLOC_BLOCK_SIZE, 0, MYF(0)); THD *new_thd = new THD(0); if (!new_thd || - my_hash_init(&udf_hash,system_charset_info,32,0,0,get_hash_key, NULL, 0)) + my_hash_init(&udf_hash,system_charset_info,32,0,0,get_hash_key, NULL, 0, + key_memory_udf_mem)) { sql_print_error("Can't allocate memory for udf structures"); my_hash_free(&udf_hash); diff --git a/sql/sql_window.cc b/sql/sql_window.cc index 7e319c96000..a9a1dccf9f6 100644 --- a/sql/sql_window.cc +++ b/sql/sql_window.cc @@ -778,10 +778,10 @@ public: { //DBUG_ASSERT(info->read_record == rr_from_tempfile); rownum= 0; - io_cache= (IO_CACHE*)my_malloc(sizeof(IO_CACHE), MYF(0)); + io_cache= (IO_CACHE*)my_malloc(PSI_INSTRUMENT_ME, sizeof(IO_CACHE), MYF(0)); init_slave_io_cache(info->io_cache, io_cache); - ref_buffer= (uchar*)my_malloc(ref_length, MYF(0)); + ref_buffer= (uchar*)my_malloc(PSI_INSTRUMENT_ME, ref_length, MYF(0)); ref_buffer_valid= false; } } @@ -2816,7 +2816,7 @@ bool compute_window_func(THD *thd, List_iterator_fast<Group_bound_tracker> iter_part_trackers(partition_trackers); ha_rows rownum= 0; - uchar *rowid_buf= (uchar*) my_malloc(tbl->file->ref_length, MYF(0)); + uchar *rowid_buf= (uchar*) my_malloc(PSI_INSTRUMENT_ME, tbl->file->ref_length, MYF(0)); while (true) { diff --git a/sql/sys_vars.cc b/sql/sys_vars.cc index 0d67c00bdbb..0025d23725f 100644 --- a/sql/sys_vars.cc +++ b/sql/sys_vars.cc @@ -1935,7 +1935,8 @@ Sys_var_gtid_binlog_state::do_check(THD *thd, set_var *var) my_error(ER_INCORRECT_GTID_STATE, MYF(0)); return true; } - if (!(data= (gtid_binlog_state_data *)my_malloc(sizeof(*data), MYF(0)))) + if (!(data= (gtid_binlog_state_data *)my_malloc(PSI_INSTRUMENT_ME, + sizeof(*data), MYF(0)))) { my_free(list); my_error(ER_OUT_OF_RESOURCES, MYF(0)); diff --git a/sql/sys_vars.ic b/sql/sys_vars.ic index f33f469b160..698062d9bed 100644 --- a/sql/sys_vars.ic +++ b/sql/sys_vars.ic @@ -529,7 +529,8 @@ public: size_t len=var->save_result.string_value.length; if (ptr) { - new_val= (char*)my_memdup(ptr, len+1, MYF(MY_WME)); + new_val= (char*)my_memdup(key_memory_Sys_var_charptr_value, + ptr, len+1, MYF(MY_WME)); if (!new_val) return 0; new_val[len]=0; } diff --git a/sql/table.cc b/sql/table.cc index 8f5f5614cd8..7c982584d52 100644 --- a/sql/table.cc +++ b/sql/table.cc @@ -323,7 +323,8 @@ TABLE_SHARE *alloc_table_share(const char *db, const char *table_name, path_length= build_table_filename(path, sizeof(path) - 1, db, table_name, "", 0); - init_sql_alloc(&mem_root, "table_share", TABLE_ALLOC_BLOCK_SIZE, 0, MYF(0)); + init_sql_alloc(key_memory_table_share, &mem_root, TABLE_ALLOC_BLOCK_SIZE, 0, + MYF(0)); if (multi_alloc_root(&mem_root, &share, sizeof(*share), &key_buff, key_length, @@ -349,7 +350,7 @@ TABLE_SHARE *alloc_table_share(const char *db, const char *table_name, table_alias_charset->strnncoll(key, 6, "mysql", 6) == 0) share->not_usable_by_query_cache= 1; - init_sql_alloc(&share->stats_cb.mem_root, "share_stats", + init_sql_alloc(PSI_INSTRUMENT_ME, &share->stats_cb.mem_root, TABLE_ALLOC_BLOCK_SIZE, 0, MYF(0)); memcpy((char*) &share->mem_root, (char*) &mem_root, sizeof(mem_root)); @@ -411,8 +412,9 @@ void init_tmp_table_share(THD *thd, TABLE_SHARE *share, const char *key, This can't be MY_THREAD_SPECIFIC for slaves as they are freed during cleanup() from Relay_log_info::close_temporary_tables() */ - init_sql_alloc(&share->mem_root, "tmp_table_share", TABLE_ALLOC_BLOCK_SIZE, - 0, MYF(thd->slave_thread ? 0 : MY_THREAD_SPECIFIC)); + init_sql_alloc(key_memory_table_share, &share->mem_root, + TABLE_ALLOC_BLOCK_SIZE, 0, + MYF(thd->slave_thread ? 0 : MY_THREAD_SPECIFIC)); share->table_category= TABLE_CATEGORY_TEMPORARY; share->tmp_table= INTERNAL_TMP_TABLE; share->db.str= (char*) key; @@ -676,7 +678,8 @@ enum open_frm_error open_table_def(THD *thd, TABLE_SHARE *share, uint flags) frmlen= uint4korr(head+10); set_if_smaller(frmlen, FRM_MAX_SIZE); // safety - if (!(buf= (uchar*)my_malloc(frmlen, MYF(MY_THREAD_SPECIFIC|MY_WME)))) + if (!(buf= (uchar*)my_malloc(PSI_INSTRUMENT_ME, frmlen, + MYF(MY_THREAD_SPECIFIC|MY_WME)))) goto err; memcpy(buf, head, sizeof(head)); @@ -2195,10 +2198,10 @@ int TABLE_SHARE::init_from_binary_frm_image(THD *thd, bool write, use_hash= share->fields >= MAX_FIELDS_BEFORE_HASH; if (use_hash) - use_hash= !my_hash_init(&share->name_hash, - system_charset_info, - share->fields,0,0, - (my_hash_get_key) get_field_name,0,0); + use_hash= !my_hash_init(&share->name_hash, system_charset_info, + share->fields, 0, 0, + (my_hash_get_key) get_field_name, 0, 0, + PSI_INSTRUMENT_ME); if (share->mysql_version >= 50700 && share->mysql_version < 100000 && vcol_screen_length) @@ -3756,8 +3759,8 @@ enum open_frm_error open_table_from_share(THD *thd, TABLE_SHARE *share, error= OPEN_FRM_NEEDS_REBUILD; goto err; } - init_sql_alloc(&outparam->mem_root, "table", TABLE_ALLOC_BLOCK_SIZE, 0, - MYF(0)); + init_sql_alloc(key_memory_TABLE, &outparam->mem_root, TABLE_ALLOC_BLOCK_SIZE, + 0, MYF(0)); /* We have to store the original alias in mem_root as constraints and virtual diff --git a/sql/table.h b/sql/table.h index 416490a80a9..0a91df9c04c 100644 --- a/sql/table.h +++ b/sql/table.h @@ -1075,8 +1075,8 @@ private: public: Blob_mem_storage() :truncated_value(false) { - init_alloc_root(&storage, "Blob_mem_storage", MAX_FIELD_VARCHARLENGTH, 0, - MYF(0)); + init_alloc_root(key_memory_blob_mem_storage, + &storage, MAX_FIELD_VARCHARLENGTH, 0, MYF(0)); } ~ Blob_mem_storage() { diff --git a/sql/table_cache.cc b/sql/table_cache.cc index 8e5c3a8471d..5578bd59966 100644 --- a/sql/table_cache.cc +++ b/sql/table_cache.cc @@ -1257,10 +1257,9 @@ int tdc_iterate(THD *thd, my_hash_walk_action action, void *argument, if (no_dups) { - init_alloc_root(&no_dups_argument.root, "no_dups", 4096, 4096, - MYF(alloc_flags)); + init_alloc_root(PSI_INSTRUMENT_ME, &no_dups_argument.root, 4096, 4096, MYF(alloc_flags)); my_hash_init(&no_dups_argument.hash, &my_charset_bin, tdc_records(), 0, 0, - eliminate_duplicates_get_key, 0, hash_flags); + eliminate_duplicates_get_key, 0, hash_flags, PSI_INSTRUMENT_ME); no_dups_argument.action= action; no_dups_argument.argument= argument; action= (my_hash_walk_action) eliminate_duplicates; diff --git a/sql/temporary_tables.cc b/sql/temporary_tables.cc index 2e0f0a4918e..c675b11741a 100644 --- a/sql/temporary_tables.cc +++ b/sql/temporary_tables.cc @@ -955,7 +955,8 @@ TMP_TABLE_SHARE *THD::create_temporary_table(LEX_CUSTRING *frm, /* Create the table definition key for the temporary table. */ key_length= create_tmp_table_def_key(key_cache, db, table_name); - if (!(share= (TMP_TABLE_SHARE *) my_malloc(sizeof(TMP_TABLE_SHARE) + + if (!(share= (TMP_TABLE_SHARE *) my_malloc(key_memory_table_share, + sizeof(TMP_TABLE_SHARE) + strlen(path) + 1 + key_length, MYF(MY_WME)))) { @@ -1002,7 +1003,8 @@ TMP_TABLE_SHARE *THD::create_temporary_table(LEX_CUSTRING *frm, if (!temporary_tables) { if ((temporary_tables= - (All_tmp_tables_list *) my_malloc(sizeof(All_tmp_tables_list), + (All_tmp_tables_list *) my_malloc(key_memory_table_share, + sizeof(All_tmp_tables_list), MYF(MY_WME)))) { temporary_tables->empty(); @@ -1107,7 +1109,8 @@ TABLE *THD::open_temporary_table(TMP_TABLE_SHARE *share, DBUG_ENTER("THD::open_temporary_table"); - if (!(table= (TABLE *) my_malloc(sizeof(TABLE), MYF(MY_WME)))) + if (!(table= (TABLE *) my_malloc(key_memory_TABLE, sizeof(TABLE), + MYF(MY_WME)))) { DBUG_RETURN(NULL); /* Out of memory */ } diff --git a/sql/thr_malloc.cc b/sql/thr_malloc.cc index d43e7c4c9b5..89ad359befa 100644 --- a/sql/thr_malloc.cc +++ b/sql/thr_malloc.cc @@ -58,11 +58,10 @@ extern "C" { } } -void init_sql_alloc(MEM_ROOT *mem_root, - const char *area_name __attribute__((unused)), - uint block_size, uint pre_alloc, myf my_flags) +void init_sql_alloc(PSI_memory_key key, MEM_ROOT *mem_root, uint block_size, + uint pre_alloc, myf my_flags) { - init_alloc_root(mem_root, area_name, block_size, pre_alloc, my_flags); + init_alloc_root(key, mem_root, block_size, pre_alloc, my_flags); mem_root->error_handler=sql_alloc_error_handler; } diff --git a/sql/thr_malloc.h b/sql/thr_malloc.h index a6ab5477d41..cc56666bcc9 100644 --- a/sql/thr_malloc.h +++ b/sql/thr_malloc.h @@ -18,8 +18,8 @@ typedef struct st_mem_root MEM_ROOT; -void init_sql_alloc(MEM_ROOT *root, const char *area_name, uint block_size, - uint pre_alloc_size, myf my_flags); +void init_sql_alloc(PSI_memory_key key, MEM_ROOT *root, uint block_size, uint + pre_alloc_size, myf my_flags); char *sql_strmake_with_convert(THD *thd, const char *str, size_t arg_length, CHARSET_INFO *from_cs, size_t max_res_length, diff --git a/sql/threadpool_generic.cc b/sql/threadpool_generic.cc index e11a0613425..e8e3497eae4 100644 --- a/sql/threadpool_generic.cc +++ b/sql/threadpool_generic.cc @@ -1532,7 +1532,8 @@ int TP_pool_generic::init() DBUG_ENTER("TP_pool_generic::TP_pool_generic"); threadpool_max_size= MY_MAX(threadpool_size, 128); all_groups= (thread_group_t *) - my_malloc(sizeof(thread_group_t) * threadpool_max_size, MYF(MY_WME|MY_ZEROFILL)); + my_malloc(PSI_INSTRUMENT_ME, + sizeof(thread_group_t) * threadpool_max_size, MYF(MY_WME|MY_ZEROFILL)); if (!all_groups) { threadpool_max_size= 0; diff --git a/sql/tztime.cc b/sql/tztime.cc index fbac2923a84..a38bb2b0fc8 100644 --- a/sql/tztime.cc +++ b/sql/tztime.cc @@ -1543,6 +1543,8 @@ tz_init_table_list(TABLE_LIST *tz_tabs) } } +static PSI_memory_key key_memory_tz_storage; + #ifdef HAVE_PSI_INTERFACE static PSI_mutex_key key_tz_LOCK; @@ -1551,6 +1553,11 @@ static PSI_mutex_info all_tz_mutexes[]= { & key_tz_LOCK, "tz_LOCK", PSI_FLAG_GLOBAL} }; +static PSI_memory_info all_tz_memory[]= +{ + { &key_memory_tz_storage, "tz_storage", PSI_FLAG_GLOBAL} +}; + static void init_tz_psi_keys(void) { const char* category= "sql"; @@ -1561,6 +1568,9 @@ static void init_tz_psi_keys(void) count= array_elements(all_tz_mutexes); PSI_server->register_mutex(category, all_tz_mutexes, count); + + count= array_elements(all_tz_memory); + mysql_memory_register(category, all_tz_memory, count); } #endif /* HAVE_PSI_INTERFACE */ @@ -1616,19 +1626,21 @@ my_tz_init(THD *org_thd, const char *default_tzname, my_bool bootstrap) /* Init all memory structures that require explicit destruction */ if (my_hash_init(&tz_names, &my_charset_latin1, 20, - 0, 0, (my_hash_get_key) my_tz_names_get_key, 0, 0)) + 0, 0, (my_hash_get_key) my_tz_names_get_key, 0, 0, + key_memory_tz_storage)) { sql_print_error("Fatal error: OOM while initializing time zones"); goto end; } if (my_hash_init(&offset_tzs, &my_charset_latin1, 26, 0, 0, - (my_hash_get_key)my_offset_tzs_get_key, 0, 0)) + (my_hash_get_key)my_offset_tzs_get_key, 0, 0, + key_memory_tz_storage)) { sql_print_error("Fatal error: OOM while initializing time zones"); my_hash_free(&tz_names); goto end; } - init_sql_alloc(&tz_storage, "timezone_storage", 32 * 1024, 0, MYF(0)); + init_sql_alloc(key_memory_tz_storage, &tz_storage, 32 * 1024, 0, MYF(0)); mysql_mutex_init(key_tz_LOCK, &tz_LOCK, MY_MUTEX_INIT_FAST); tz_inited= 1; @@ -2568,8 +2580,8 @@ scan_tz_dir(char * name_end, uint symlink_recursion_level, uint verbose) } else if (MY_S_ISREG(cur_dir->dir_entry[i].mystat->st_mode)) { - init_alloc_root(&tz_storage, "timezone_storage", 32768, 0, - MYF(MY_THREAD_SPECIFIC)); + init_alloc_root(PSI_INSTRUMENT_ME, &tz_storage, + 32768, 0, MYF(MY_THREAD_SPECIFIC)); if (!tz_load(fullname, &tz_info, &tz_storage)) print_tz_as_sql(root_name_end + 1, &tz_info); else @@ -2758,7 +2770,7 @@ main(int argc, char **argv) First argument is timezonefile. The second is timezonename if opt_leap is not given */ - init_alloc_root(&tz_storage, "timezone_storage", 32768, 0, MYF(0)); + init_alloc_root(PSI_INSTRUMENT_ME, &tz_storage, 32768, 0, MYF(0)); if (tz_load(argv[0], &tz_info, &tz_storage)) { diff --git a/sql/uniques.cc b/sql/uniques.cc index db9891158b0..6b486e48444 100644 --- a/sql/uniques.cc +++ b/sql/uniques.cc @@ -93,8 +93,8 @@ Unique::Unique(qsort_cmp2 comp_func, void * comp_func_fixed_arg, init_tree(&tree, (max_in_memory_size / 16), 0, size, comp_func, NULL, comp_func_fixed_arg, MYF(MY_THREAD_SPECIFIC)); /* If the following fail's the next add will also fail */ - my_init_dynamic_array(&file_ptrs, sizeof(Merge_chunk), 16, 16, - MYF(MY_THREAD_SPECIFIC)); + my_init_dynamic_array(&file_ptrs, PSI_INSTRUMENT_ME, sizeof(Merge_chunk), 16, + 16, MYF(MY_THREAD_SPECIFIC)); /* If you change the following, change it in get_max_elements function, too. */ @@ -662,7 +662,8 @@ bool Unique::walk(TABLE *table, tree_walk_action action, void *walk_action_arg) is needed when a piece of merge buffer is re-read, see merge_walk() */ size_t buff_sz= MY_MAX(MERGEBUFF2+1, max_in_memory_size/full_size+1) * full_size; - if (!(merge_buffer = (uchar *)my_malloc(buff_sz, MYF(MY_WME)))) + if (!(merge_buffer = (uchar *)my_malloc(key_memory_Unique_merge_buffer, + buff_sz, MYF(MY_THREAD_SPECIFIC|MY_WME)))) return 1; if (buff_sz < full_size * (file_ptrs.elements + 1UL)) res= merge(table, merge_buffer, buff_sz, @@ -782,7 +783,8 @@ bool Unique::get(TABLE *table) { /* Whole tree is in memory; Don't use disk if you don't need to */ if ((sort.record_pointers= (uchar*) - my_malloc(size * tree.elements_in_tree, MYF(MY_THREAD_SPECIFIC)))) + my_malloc(key_memory_Filesort_info_record_pointers, + size * tree.elements_in_tree, MYF(MY_THREAD_SPECIFIC)))) { uchar *save_record_pointers= sort.record_pointers; tree_walk_action action= min_dupl_count ? @@ -801,7 +803,7 @@ bool Unique::get(TABLE *table) if (flush()) DBUG_RETURN(1); size_t buff_sz= (max_in_memory_size / full_size + 1) * full_size; - if (!(sort_buffer= (uchar*) my_malloc(buff_sz, + if (!(sort_buffer= (uchar*) my_malloc(key_memory_Unique_sort_buffer, buff_sz, MYF(MY_THREAD_SPECIFIC|MY_WME)))) DBUG_RETURN(1); diff --git a/sql/unireg.cc b/sql/unireg.cc index e4a43d3ace5..2aa46131efb 100644 --- a/sql/unireg.cc +++ b/sql/unireg.cc @@ -425,8 +425,8 @@ LEX_CUSTRING build_frm_image(THD *thd, const LEX_CSTRING &table, DBUG_RETURN(frm); } - frm_ptr= (uchar*) my_malloc(frm.length, MYF(MY_WME | MY_ZEROFILL | - MY_THREAD_SPECIFIC)); + frm_ptr= (uchar*) my_malloc(PSI_INSTRUMENT_ME, frm.length, + MYF(MY_WME | MY_ZEROFILL | MY_THREAD_SPECIFIC)); if (!frm_ptr) DBUG_RETURN(frm); diff --git a/sql/wsrep_binlog.cc b/sql/wsrep_binlog.cc index a81503a50da..f555480d2e0 100644 --- a/sql/wsrep_binlog.cc +++ b/sql/wsrep_binlog.cc @@ -64,7 +64,7 @@ int wsrep_write_cache_buf(IO_CACHE *cache, uchar **buf, size_t *buf_len) wsrep_max_ws_size, total_length); goto error; } - uchar* tmp= (uchar *)my_realloc(*buf, total_length, + uchar* tmp= (uchar *)my_realloc(PSI_INSTRUMENT_ME, *buf, total_length, MYF(MY_ALLOW_ZERO_PTR)); if (!tmp) { diff --git a/sql/wsrep_mysqld.cc b/sql/wsrep_mysqld.cc index ff01473e816..e170037956b 100644 --- a/sql/wsrep_mysqld.cc +++ b/sql/wsrep_mysqld.cc @@ -1270,7 +1270,7 @@ static bool wsrep_prepare_key_for_isolation(const char* db, wsrep_key_arr_t* ka) { wsrep_key_t* tmp; - tmp= (wsrep_key_t*)my_realloc(ka->keys, + tmp= (wsrep_key_t*)my_realloc(PSI_INSTRUMENT_ME, ka->keys, (ka->keys_len + 1) * sizeof(wsrep_key_t), MYF(MY_ALLOW_ZERO_PTR)); if (!tmp) @@ -1280,7 +1280,7 @@ static bool wsrep_prepare_key_for_isolation(const char* db, } ka->keys= tmp; if (!(ka->keys[ka->keys_len].key_parts= (wsrep_buf_t*) - my_malloc(sizeof(wsrep_buf_t)*2, MYF(0)))) + my_malloc(PSI_INSTRUMENT_ME, sizeof(wsrep_buf_t)*2, MYF(0)))) { WSREP_ERROR("Can't allocate memory for key_parts"); return false; diff --git a/sql/wsrep_sst.cc b/sql/wsrep_sst.cc index d478ea486cd..0bb8a9eb675 100644 --- a/sql/wsrep_sst.cc +++ b/sql/wsrep_sst.cc @@ -245,7 +245,7 @@ static bool sst_auth_real_set (const char* value) if (value) { - v= my_strdup(value, MYF(0)); + v= my_strdup(PSI_INSTRUMENT_ME, value, MYF(0)); } else // its NULL { @@ -263,7 +263,7 @@ static bool sst_auth_real_set (const char* value) if (strlen(sst_auth_real)) { if (wsrep_sst_auth) { my_free((void*) wsrep_sst_auth); } - wsrep_sst_auth= my_strdup(WSREP_SST_AUTH_MASK, MYF(0)); + wsrep_sst_auth= my_strdup(PSI_INSTRUMENT_ME, WSREP_SST_AUTH_MASK, MYF(0)); } return 0; } @@ -414,7 +414,7 @@ static char* generate_name_value(const char* name, const char* value) size_t name_len= strlen(name); size_t value_len= strlen(value); char* buf= - (char*) my_malloc((name_len + value_len + 5) * sizeof(char), MYF(0)); + (char*) my_malloc(PSI_INSTRUMENT_ME, (name_len + value_len + 5), MYF(0)); if (buf) { char* ref= buf; @@ -449,11 +449,11 @@ static int generate_binlog_opt_val(char** ret) *ret= strcmp(opt_bin_logname, "0") ? generate_name_value(WSREP_SST_OPT_BINLOG, opt_bin_logname) : - my_strdup("", MYF(0)); + my_strdup(PSI_INSTRUMENT_ME, "", MYF(0)); } else { - *ret= my_strdup("", MYF(0)); + *ret= my_strdup(PSI_INSTRUMENT_ME, "", MYF(0)); } if (!*ret) return -ENOMEM; return 0; @@ -468,11 +468,11 @@ static int generate_binlog_index_opt_val(char** ret) *ret= strcmp(opt_binlog_index_name, "0") ? generate_name_value(WSREP_SST_OPT_BINLOG_INDEX, opt_binlog_index_name) : - my_strdup("", MYF(0)); + my_strdup(PSI_INSTRUMENT_ME, "", MYF(0)); } else { - *ret= my_strdup("", MYF(0)); + *ret= my_strdup(PSI_INSTRUMENT_ME, "", MYF(0)); } if (!*ret) return -ENOMEM; return 0; diff --git a/sql/wsrep_var.cc b/sql/wsrep_var.cc index 950e4aae34d..28dbe4096f7 100644 --- a/sql/wsrep_var.cc +++ b/sql/wsrep_var.cc @@ -30,17 +30,17 @@ ulong wsrep_reject_queries; int wsrep_init_vars() { - wsrep_provider = my_strdup(WSREP_NONE, MYF(MY_WME)); - wsrep_provider_options= my_strdup("", MYF(MY_WME)); - wsrep_cluster_address = my_strdup("", MYF(MY_WME)); - wsrep_cluster_name = my_strdup(WSREP_CLUSTER_NAME, MYF(MY_WME)); - wsrep_node_name = my_strdup("", MYF(MY_WME)); - wsrep_node_address = my_strdup("", MYF(MY_WME)); - wsrep_node_incoming_address= my_strdup(WSREP_NODE_INCOMING_AUTO, MYF(MY_WME)); + wsrep_provider = my_strdup(PSI_INSTRUMENT_ME, WSREP_NONE, MYF(MY_WME)); + wsrep_provider_options= my_strdup(PSI_INSTRUMENT_ME, "", MYF(MY_WME)); + wsrep_cluster_address = my_strdup(PSI_INSTRUMENT_ME, "", MYF(MY_WME)); + wsrep_cluster_name = my_strdup(PSI_INSTRUMENT_ME, WSREP_CLUSTER_NAME, MYF(MY_WME)); + wsrep_node_name = my_strdup(PSI_INSTRUMENT_ME, "", MYF(MY_WME)); + wsrep_node_address = my_strdup(PSI_INSTRUMENT_ME, "", MYF(MY_WME)); + wsrep_node_incoming_address= my_strdup(PSI_INSTRUMENT_ME, WSREP_NODE_INCOMING_AUTO, MYF(MY_WME)); if (wsrep_gtid_mode) - wsrep_start_position = my_strdup(WSREP_START_POSITION_ZERO_GTID, MYF(MY_WME)); + wsrep_start_position = my_strdup(PSI_INSTRUMENT_ME, WSREP_START_POSITION_ZERO_GTID, MYF(MY_WME)); else - wsrep_start_position = my_strdup(WSREP_START_POSITION_ZERO, MYF(MY_WME)); + wsrep_start_position = my_strdup(PSI_INSTRUMENT_ME, WSREP_START_POSITION_ZERO, MYF(MY_WME)); return 0; } @@ -50,7 +50,7 @@ static int get_provider_option_value(const char* opts, { int ret= 1; ulong opt_value_tmp; - char *opt_value_str, *s, *opts_copy= my_strdup(opts, MYF(MY_WME)); + char *opt_value_str, *s, *opts_copy= my_strdup(PSI_INSTRUMENT_ME, opts, MYF(MY_WME)); if ((opt_value_str= strstr(opts_copy, opt_name)) == NULL) goto end; @@ -436,7 +436,7 @@ void wsrep_provider_init (const char* value) } if (wsrep_provider) my_free((void *)wsrep_provider); - wsrep_provider= my_strdup(value, MYF(0)); + wsrep_provider= my_strdup(PSI_INSTRUMENT_MEM, value, MYF(0)); } bool wsrep_provider_options_check(sys_var *self, THD* thd, set_var* var) @@ -466,7 +466,7 @@ void wsrep_provider_options_init(const char* value) { if (wsrep_provider_options && wsrep_provider_options != value) my_free((void *)wsrep_provider_options); - wsrep_provider_options= (value) ? my_strdup(value, MYF(0)) : NULL; + wsrep_provider_options= value ? my_strdup(PSI_INSTRUMENT_MEM, value, MYF(0)) : NULL; } bool wsrep_reject_queries_update(sys_var *self, THD* thd, enum_var_type type) @@ -578,8 +578,8 @@ void wsrep_cluster_address_init (const char* value) (wsrep_cluster_address) ? wsrep_cluster_address : "null", (value) ? value : "null"); - my_free((void*) wsrep_cluster_address); - wsrep_cluster_address= my_strdup(value ? value : "", MYF(0)); + my_free(const_cast<char*>(wsrep_cluster_address)); + wsrep_cluster_address= my_strdup(PSI_INSTRUMENT_MEM, safe_str(value), MYF(0)); } /* wsrep_cluster_name cannot be NULL or an empty string. */ @@ -652,7 +652,7 @@ void wsrep_node_address_init (const char* value) if (wsrep_node_address && strcmp(wsrep_node_address, value)) my_free ((void*)wsrep_node_address); - wsrep_node_address= (value) ? my_strdup(value, MYF(0)) : NULL; + wsrep_node_address= value ? my_strdup(PSI_INSTRUMENT_MEM, value, MYF(0)) : NULL; } static void wsrep_slave_count_change_update () |