Commit 8edef482 authored by Monty's avatar Monty

Changed some malloc() calls to my_malloc()

- hostnames in hostname_cache added
- Some Galera (WSREP) allocations
- Table caches
parent c4a5bd1e
...@@ -151,7 +151,7 @@ bool hostname_cache_init() ...@@ -151,7 +151,7 @@ bool hostname_cache_init()
if (!(hostname_cache= new Hash_filo<Host_entry>(key_memory_host_cache_hostname, if (!(hostname_cache= new Hash_filo<Host_entry>(key_memory_host_cache_hostname,
host_cache_size, key_offset, HOST_ENTRY_KEY_SIZE, host_cache_size, key_offset, HOST_ENTRY_KEY_SIZE,
NULL, (my_hash_free_key) free, &my_charset_bin))) NULL, (my_hash_free_key) my_free, &my_charset_bin)))
return 1; return 1;
hostname_cache->clear(); hostname_cache->clear();
...@@ -204,7 +204,8 @@ static void add_hostname_impl(const char *ip_key, const char *hostname, ...@@ -204,7 +204,8 @@ static void add_hostname_impl(const char *ip_key, const char *hostname,
if (likely(entry == NULL)) if (likely(entry == NULL))
{ {
entry= (Host_entry *) malloc(sizeof (Host_entry)); entry= (Host_entry *) my_malloc(key_memory_host_cache_hostname,
sizeof (Host_entry), 0);
if (entry == NULL) if (entry == NULL)
return; return;
......
...@@ -9304,8 +9304,8 @@ PSI_memory_key key_memory_thd_transactions; ...@@ -9304,8 +9304,8 @@ PSI_memory_key key_memory_thd_transactions;
PSI_memory_key key_memory_user_conn; PSI_memory_key key_memory_user_conn;
PSI_memory_key key_memory_user_var_entry; PSI_memory_key key_memory_user_var_entry;
PSI_memory_key key_memory_user_var_entry_value; PSI_memory_key key_memory_user_var_entry_value;
PSI_memory_key key_memory_String_value; PSI_memory_key key_memory_String_value;
PSI_memory_key key_memory_WSREP;
#ifdef HAVE_PSI_INTERFACE #ifdef HAVE_PSI_INTERFACE
...@@ -9593,6 +9593,7 @@ static PSI_memory_info all_server_memory[]= ...@@ -9593,6 +9593,7 @@ static PSI_memory_info all_server_memory[]=
// { &key_memory_get_all_tables, "get_all_tables", 0}, // { &key_memory_get_all_tables, "get_all_tables", 0},
// { &key_memory_fill_schema_schemata, "fill_schema_schemata", 0}, // { &key_memory_fill_schema_schemata, "fill_schema_schemata", 0},
{ &key_memory_native_functions, "native_functions", PSI_FLAG_GLOBAL}, { &key_memory_native_functions, "native_functions", PSI_FLAG_GLOBAL},
{ &key_memory_WSREP, "wsrep", 0 }
}; };
/** /**
......
...@@ -537,6 +537,7 @@ extern PSI_memory_key key_memory_get_all_tables; ...@@ -537,6 +537,7 @@ extern PSI_memory_key key_memory_get_all_tables;
extern PSI_memory_key key_memory_fill_schema_schemata; extern PSI_memory_key key_memory_fill_schema_schemata;
extern PSI_memory_key key_memory_native_functions; extern PSI_memory_key key_memory_native_functions;
extern PSI_memory_key key_memory_JSON; extern PSI_memory_key key_memory_JSON;
extern PSI_memory_key key_memory_WSREP;
/* /*
MAINTAINER: Please keep this list in order, to limit merge collisions. MAINTAINER: Please keep this list in order, to limit merge collisions.
......
...@@ -57,6 +57,7 @@ ...@@ -57,6 +57,7 @@
ulong tdc_size; /**< Table definition cache threshold for LRU eviction. */ ulong tdc_size; /**< Table definition cache threshold for LRU eviction. */
ulong tc_size; /**< Table cache threshold for LRU eviction. */ ulong tc_size; /**< Table cache threshold for LRU eviction. */
uint32 tc_instances; uint32 tc_instances;
static size_t tc_allocated_size;
static std::atomic<uint32_t> tc_active_instances(1); static std::atomic<uint32_t> tc_active_instances(1);
static std::atomic<bool> tc_contention_warning_reported; static std::atomic<bool> tc_contention_warning_reported;
...@@ -148,8 +149,20 @@ struct Table_cache_instance ...@@ -148,8 +149,20 @@ struct Table_cache_instance
} }
static void *operator new[](size_t size) static void *operator new[](size_t size)
{ return aligned_malloc(size, CPU_LEVEL1_DCACHE_LINESIZE); } {
void *res= aligned_malloc(size, CPU_LEVEL1_DCACHE_LINESIZE);
if (res)
{
tc_allocated_size= size;
update_malloc_size(size, 0);
}
return res;
}
static void operator delete[](void *ptr) { aligned_free(ptr); } static void operator delete[](void *ptr) { aligned_free(ptr); }
static void mark_memory_freed()
{
update_malloc_size(-(longlong) tc_allocated_size, 0);
}
/** /**
Lock table cache mutex and check contention. Lock table cache mutex and check contention.
...@@ -654,7 +667,12 @@ void tdc_deinit(void) ...@@ -654,7 +667,12 @@ void tdc_deinit(void)
tdc_inited= false; tdc_inited= false;
lf_hash_destroy(&tdc_hash); lf_hash_destroy(&tdc_hash);
mysql_mutex_destroy(&LOCK_unused_shares); mysql_mutex_destroy(&LOCK_unused_shares);
delete [] tc; if (tc)
{
tc->mark_memory_freed();
delete [] tc;
tc= 0;
}
} }
DBUG_VOID_RETURN; DBUG_VOID_RETURN;
} }
......
...@@ -198,7 +198,7 @@ void wsrep_dump_rbr_buf(THD *thd, const void* rbr_buf, size_t buf_len) ...@@ -198,7 +198,7 @@ void wsrep_dump_rbr_buf(THD *thd, const void* rbr_buf, size_t buf_len)
to alloc and pass as an argument to snprintf. to alloc and pass as an argument to snprintf.
*/ */
char *filename= (char *)malloc(len+1); char *filename= (char *) my_malloc(key_memory_WSREP, len+1, 0);
int len1= snprintf(filename, len+1, "%s/GRA_%lld_%lld.log", int len1= snprintf(filename, len+1, "%s/GRA_%lld_%lld.log",
wsrep_data_home_dir, (longlong) thd->thread_id, wsrep_data_home_dir, (longlong) thd->thread_id,
(long long)wsrep_thd_trx_seqno(thd)); (long long)wsrep_thd_trx_seqno(thd));
...@@ -206,7 +206,7 @@ void wsrep_dump_rbr_buf(THD *thd, const void* rbr_buf, size_t buf_len) ...@@ -206,7 +206,7 @@ void wsrep_dump_rbr_buf(THD *thd, const void* rbr_buf, size_t buf_len)
if (len > len1) if (len > len1)
{ {
WSREP_ERROR("RBR dump path truncated: %d, skipping dump.", len); WSREP_ERROR("RBR dump path truncated: %d, skipping dump.", len);
free(filename); my_free(filename);
return; return;
} }
...@@ -225,7 +225,7 @@ void wsrep_dump_rbr_buf(THD *thd, const void* rbr_buf, size_t buf_len) ...@@ -225,7 +225,7 @@ void wsrep_dump_rbr_buf(THD *thd, const void* rbr_buf, size_t buf_len)
WSREP_ERROR("Failed to open file '%s': %d (%s)", WSREP_ERROR("Failed to open file '%s': %d (%s)",
filename, errno, strerror(errno)); filename, errno, strerror(errno));
} }
free(filename); my_free(filename);
} }
/* Dump replication buffer along with header to a file. */ /* Dump replication buffer along with header to a file. */
...@@ -248,7 +248,7 @@ void wsrep_dump_rbr_buf_with_header(THD *thd, const void *rbr_buf, ...@@ -248,7 +248,7 @@ void wsrep_dump_rbr_buf_with_header(THD *thd, const void *rbr_buf,
to alloc and pass as an argument to snprintf. to alloc and pass as an argument to snprintf.
*/ */
char *filename; char *filename;
if (len < 0 || !(filename= (char*)malloc(len+1))) if (len < 0 || !(filename= (char*) my_malloc(key_memory_WSREP, len+1, 0)))
{ {
WSREP_ERROR("snprintf error: %d, skipping dump.", len); WSREP_ERROR("snprintf error: %d, skipping dump.", len);
DBUG_VOID_RETURN; DBUG_VOID_RETURN;
...@@ -261,7 +261,7 @@ void wsrep_dump_rbr_buf_with_header(THD *thd, const void *rbr_buf, ...@@ -261,7 +261,7 @@ void wsrep_dump_rbr_buf_with_header(THD *thd, const void *rbr_buf,
if (len > len1) if (len > len1)
{ {
WSREP_ERROR("RBR dump path truncated: %d, skipping dump.", len); WSREP_ERROR("RBR dump path truncated: %d, skipping dump.", len);
free(filename); my_free(filename);
DBUG_VOID_RETURN; DBUG_VOID_RETURN;
} }
...@@ -301,7 +301,7 @@ void wsrep_dump_rbr_buf_with_header(THD *thd, const void *rbr_buf, ...@@ -301,7 +301,7 @@ void wsrep_dump_rbr_buf_with_header(THD *thd, const void *rbr_buf,
end_io_cache(&cache); end_io_cache(&cache);
cleanup1: cleanup1:
free(filename); my_free(filename);
mysql_file_close(file, MYF(MY_WME)); mysql_file_close(file, MYF(MY_WME));
if (!thd->wsrep_applier) delete ev; if (!thd->wsrep_applier) delete ev;
......
...@@ -847,6 +847,7 @@ void wsrep_deinit_server() ...@@ -847,6 +847,7 @@ void wsrep_deinit_server()
{ {
wsrep_deinit_schema(); wsrep_deinit_schema();
Wsrep_server_state::destroy(); Wsrep_server_state::destroy();
wsrep_free_status_vars();
} }
int wsrep_init() int wsrep_init()
......
...@@ -1656,9 +1656,9 @@ static int sst_flush_tables(THD* thd) ...@@ -1656,9 +1656,9 @@ static int sst_flush_tables(THD* thd)
const char base_name[]= "tables_flushed"; const char base_name[]= "tables_flushed";
ssize_t const full_len= strlen(mysql_real_data_home) + strlen(base_name)+2; ssize_t const full_len= strlen(mysql_real_data_home) + strlen(base_name)+2;
char *real_name= (char*) malloc(full_len); char *real_name= (char*) my_malloc(key_memory_WSREP, full_len, 0);
sprintf(real_name, "%s/%s", mysql_real_data_home, base_name); sprintf(real_name, "%s/%s", mysql_real_data_home, base_name);
char *tmp_name= (char*) malloc(full_len + 4); char *tmp_name= (char*) my_malloc(key_memory_WSREP, full_len + 4, 0);
sprintf(tmp_name, "%s.tmp", real_name); sprintf(tmp_name, "%s.tmp", real_name);
FILE* file= fopen(tmp_name, "w+"); FILE* file= fopen(tmp_name, "w+");
...@@ -1686,8 +1686,8 @@ static int sst_flush_tables(THD* thd) ...@@ -1686,8 +1686,8 @@ static int sst_flush_tables(THD* thd)
tmp_name, real_name, err,strerror(err)); tmp_name, real_name, err,strerror(err));
} }
} }
free(real_name); my_free(real_name);
free(tmp_name); my_free(tmp_name);
if (err) if (err)
ha_disable_internal_writes(false); ha_disable_internal_writes(false);
} }
......
...@@ -96,14 +96,16 @@ namespace wsp ...@@ -96,14 +96,16 @@ namespace wsp
bool bool
env::ctor_common(char** e) env::ctor_common(char** e)
{ {
env_= static_cast<char**>(malloc((len_ + 1) * sizeof(char*))); env_= static_cast<char**>(my_malloc(key_memory_WSREP,
(len_ + 1) * sizeof(char*),
0));
if (env_) if (env_)
{ {
for (size_t i(0); i < len_; ++i) for (size_t i(0); i < len_; ++i)
{ {
assert(e[i]); // caller should make sure about len_ assert(e[i]); // caller should make sure about len_
env_[i]= strdup(e[i]); env_[i]= my_strdup(key_memory_WSREP, e[i], MYF(0));
if (!env_[i]) if (!env_[i])
{ {
errno_= errno; errno_= errno;
...@@ -129,8 +131,8 @@ env::dtor() ...@@ -129,8 +131,8 @@ env::dtor()
if (env_) if (env_)
{ {
/* don't need to go beyond the first NULL */ /* don't need to go beyond the first NULL */
for (size_t i(0); env_[i] != NULL; ++i) { free(env_[i]); } for (size_t i(0); env_[i] != NULL; ++i) { my_free(env_[i]); }
free(env_); my_free(env_);
env_= NULL; env_= NULL;
} }
len_= 0; len_= 0;
...@@ -157,12 +159,13 @@ env::~env() { dtor(); } ...@@ -157,12 +159,13 @@ env::~env() { dtor(); }
int int
env::append(const char* val) env::append(const char* val)
{ {
char** tmp= static_cast<char**>(realloc(env_, (len_ + 2)*sizeof(char*))); char** tmp= static_cast<char**>(my_realloc(key_memory_WSREP,
env_, (len_ + 2)*sizeof(char*),
0));
if (tmp) if (tmp)
{ {
env_= tmp; env_= tmp;
env_[len_]= strdup(val); env_[len_]= my_strdup(key_memory_WSREP, val, 0);
if (env_[len_]) if (env_[len_])
{ {
......
...@@ -1057,8 +1057,10 @@ static void export_wsrep_status_to_mysql(THD* thd) ...@@ -1057,8 +1057,10 @@ static void export_wsrep_status_to_mysql(THD* thd)
#if DYNAMIC #if DYNAMIC
if (wsrep_status_len != mysql_status_len) { if (wsrep_status_len != mysql_status_len) {
void* tmp= realloc (mysql_status_vars, void* tmp= my_realloc(key_memory_WSREP,
(wsrep_status_len + 1) * sizeof(SHOW_VAR)); mysql_status_vars,
(wsrep_status_len + 1) * sizeof(SHOW_VAR),
MYF(MY_ALLOW_ZERO_PTR));
if (!tmp) { if (!tmp) {
sql_print_error ("Out of memory for wsrep status variables." sql_print_error ("Out of memory for wsrep status variables."
...@@ -1110,6 +1112,15 @@ void wsrep_free_status (THD* thd) ...@@ -1110,6 +1112,15 @@ void wsrep_free_status (THD* thd)
thd->wsrep_status_vars.clear(); thd->wsrep_status_vars.clear();
} }
void wsrep_free_status_vars()
{
#if DYNAMIC
my_free(mysql_status_vars);
mysql_status_vars= NULL;
mysql_status_len= 0;
#endif
}
bool wsrep_gtid_domain_id_update(sys_var* self, THD *thd, enum_var_type) bool wsrep_gtid_domain_id_update(sys_var* self, THD *thd, enum_var_type)
{ {
WSREP_DEBUG("wsrep_gtid_domain_id_update: %llu", WSREP_DEBUG("wsrep_gtid_domain_id_update: %llu",
......
...@@ -37,6 +37,7 @@ class THD; ...@@ -37,6 +37,7 @@ class THD;
int wsrep_init_vars(); int wsrep_init_vars();
void wsrep_set_wsrep_on(THD *thd); void wsrep_set_wsrep_on(THD *thd);
void wsrep_free_status_vars();
#define CHECK_ARGS (sys_var *self, THD* thd, set_var *var) #define CHECK_ARGS (sys_var *self, THD* thd, set_var *var)
#define UPDATE_ARGS (sys_var *self, THD* thd, enum_var_type type) #define UPDATE_ARGS (sys_var *self, THD* thd, enum_var_type type)
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment