Commit 0ee879ff authored by Monty's avatar Monty

Improve performance for calculating memory allocation

Extend interface for 'show variables' with current scope
parent 67b24a23
......@@ -182,6 +182,11 @@ enum enum_mysql_show_type
#define SHOW_LONG SHOW_ULONG
#define SHOW_LONGLONG SHOW_ULONGLONG
enum enum_var_type
{
SHOW_OPT_DEFAULT= 0, SHOW_OPT_SESSION, SHOW_OPT_GLOBAL
};
struct st_mysql_show_var {
const char *name;
char *value;
......@@ -189,7 +194,7 @@ struct st_mysql_show_var {
};
#define SHOW_VAR_FUNC_BUFF_SIZE (256 * sizeof(void*))
typedef int (*mysql_show_var_func)(MYSQL_THD, struct st_mysql_show_var*, char *);
typedef int (*mysql_show_var_func)(MYSQL_THD, struct st_mysql_show_var*, char *, enum enum_var_type);
/*
......
......@@ -212,12 +212,16 @@ enum enum_mysql_show_type
SHOW_SINT, SHOW_SLONG, SHOW_SLONGLONG, SHOW_SIMPLE_FUNC,
SHOW_always_last
};
enum enum_var_type
{
SHOW_OPT_DEFAULT= 0, SHOW_OPT_SESSION, SHOW_OPT_GLOBAL
};
struct st_mysql_show_var {
const char *name;
char *value;
enum enum_mysql_show_type type;
};
typedef int (*mysql_show_var_func)(void*, struct st_mysql_show_var*, char *);
typedef int (*mysql_show_var_func)(void*, struct st_mysql_show_var*, char *, enum enum_var_type);
struct st_mysql_sys_var;
struct st_mysql_value;
typedef int (*mysql_var_check_func)(void* thd,
......
......@@ -212,12 +212,16 @@ enum enum_mysql_show_type
SHOW_SINT, SHOW_SLONG, SHOW_SLONGLONG, SHOW_SIMPLE_FUNC,
SHOW_always_last
};
enum enum_var_type
{
SHOW_OPT_DEFAULT= 0, SHOW_OPT_SESSION, SHOW_OPT_GLOBAL
};
struct st_mysql_show_var {
const char *name;
char *value;
enum enum_mysql_show_type type;
};
typedef int (*mysql_show_var_func)(void*, struct st_mysql_show_var*, char *);
typedef int (*mysql_show_var_func)(void*, struct st_mysql_show_var*, char *, enum enum_var_type);
struct st_mysql_sys_var;
struct st_mysql_value;
typedef int (*mysql_var_check_func)(void* thd,
......
......@@ -212,12 +212,16 @@ enum enum_mysql_show_type
SHOW_SINT, SHOW_SLONG, SHOW_SLONGLONG, SHOW_SIMPLE_FUNC,
SHOW_always_last
};
enum enum_var_type
{
SHOW_OPT_DEFAULT= 0, SHOW_OPT_SESSION, SHOW_OPT_GLOBAL
};
struct st_mysql_show_var {
const char *name;
char *value;
enum enum_mysql_show_type type;
};
typedef int (*mysql_show_var_func)(void*, struct st_mysql_show_var*, char *);
typedef int (*mysql_show_var_func)(void*, struct st_mysql_show_var*, char *, enum enum_var_type);
struct st_mysql_sys_var;
struct st_mysql_value;
typedef int (*mysql_var_check_func)(void* thd,
......
......@@ -212,12 +212,16 @@ enum enum_mysql_show_type
SHOW_SINT, SHOW_SLONG, SHOW_SLONGLONG, SHOW_SIMPLE_FUNC,
SHOW_always_last
};
enum enum_var_type
{
SHOW_OPT_DEFAULT= 0, SHOW_OPT_SESSION, SHOW_OPT_GLOBAL
};
struct st_mysql_show_var {
const char *name;
char *value;
enum enum_mysql_show_type type;
};
typedef int (*mysql_show_var_func)(void*, struct st_mysql_show_var*, char *);
typedef int (*mysql_show_var_func)(void*, struct st_mysql_show_var*, char *, enum enum_var_type);
struct st_mysql_sys_var;
struct st_mysql_value;
typedef int (*mysql_var_check_func)(void* thd,
......
This diff is collapsed.
......@@ -54,6 +54,12 @@ typedef Bitmap<((MAX_INDEXES+7)/8*8)> key_map; /* Used for finding keys */
#define TEST_SIGINT 1024 /**< Allow sigint on threads */
#define TEST_SYNCHRONIZATION 2048 /**< get server to do sleep in
some places */
/* Keep things compatible */
#define OPT_DEFAULT SHOW_OPT_DEFAULT
#define OPT_SESSION SHOW_OPT_SESSION
#define OPT_GLOBAL SHOW_OPT_GLOBAL
/* Function prototypes */
void kill_mysql(void);
void close_connection(THD *thd, uint sql_errno= 0);
......
......@@ -67,6 +67,7 @@
#include "wsrep_mysqld.h"
#include "wsrep_thd.h"
#include "sql_connect.h"
#include "my_atomic.h"
/*
The following is used to initialise Table_ident with a internal
......@@ -934,7 +935,7 @@ THD::THD(bool is_wsrep_applier)
*/
THD *old_THR_THD= current_thd;
set_current_thd(this);
status_var.memory_used= 0;
status_var.local_memory_used= status_var.global_memory_used= 0;
main_da.init();
/*
......@@ -1703,11 +1704,12 @@ THD::~THD()
main_da.free_memory();
if (tdc_hash_pins)
lf_hash_put_pins(tdc_hash_pins);
if (status_var.memory_used != 0)
/* Ensure everything is freed */
if (status_var.local_memory_used != 0)
{
DBUG_PRINT("error", ("memory_used: %lld", status_var.memory_used));
DBUG_PRINT("error", ("memory_used: %lld", status_var.local_memory_used));
SAFEMALLOC_REPORT_MEMORY(my_thread_dbug_id());
DBUG_ASSERT(status_var.memory_used == 0); // Ensure everything is freed
DBUG_ASSERT(status_var.local_memory_used == 0);
}
set_current_thd(orig_thd);
......@@ -1747,6 +1749,16 @@ void add_to_status(STATUS_VAR *to_var, STATUS_VAR *from_var)
to_var->binlog_bytes_written+= from_var->binlog_bytes_written;
to_var->cpu_time+= from_var->cpu_time;
to_var->busy_time+= from_var->busy_time;
to_var->local_memory_used+= from_var->local_memory_used;
/*
Update global_memory_used. We have to do this with atomic_add as the
global value can change outside of LOCK_status.
*/
// workaround for gcc 4.2.4-1ubuntu4 -fPIE (from DEB_BUILD_HARDENING=1)
int64 volatile * volatile ptr= &to_var->global_memory_used;
my_atomic_add64_explicit(ptr, from_var->global_memory_used,
MY_MEMORY_ORDER_RELAXED);
}
/*
......@@ -1784,6 +1796,11 @@ void add_diff_to_status(STATUS_VAR *to_var, STATUS_VAR *from_var,
dec_var->binlog_bytes_written;
to_var->cpu_time+= from_var->cpu_time - dec_var->cpu_time;
to_var->busy_time+= from_var->busy_time - dec_var->busy_time;
/*
We don't need to accumulate memory_used as these are not reset or used by
the calling functions. See execute_show_status().
*/
}
#define SECONDS_TO_WAIT_FOR_KILL 2
......
......@@ -760,7 +760,10 @@ typedef struct system_status_var
double last_query_cost;
double cpu_time, busy_time;
/* Don't initialize */
volatile int64 memory_used; /* This shouldn't be accumulated */
/* Memory used for thread local storage */
volatile int64 local_memory_used;
/* Memory allocated for global usage */
volatile int64 global_memory_used;
} STATUS_VAR;
/*
......@@ -770,7 +773,7 @@ typedef struct system_status_var
*/
#define last_system_status_var questions
#define last_cleared_system_status_var memory_used
#define last_cleared_system_status_var local_memory_used
/*
Global status variables
......
......@@ -347,11 +347,6 @@ enum enum_parsing_place
};
enum enum_var_type
{
OPT_DEFAULT= 0, OPT_SESSION, OPT_GLOBAL
};
class sys_var;
enum enum_yes_no_unknown
......
......@@ -2822,7 +2822,7 @@ int fill_schema_processlist(THD* thd, TABLE_LIST* tables, COND* cond)
thread in this thread. However it's better that we notice it eventually
than hide it.
*/
table->field[12]->store((longlong) (tmp->status_var.memory_used +
table->field[12]->store((longlong) (tmp->status_var.local_memory_used +
sizeof(THD)),
FALSE);
table->field[12]->set_notnull();
......@@ -3117,8 +3117,8 @@ static bool show_status_array(THD *thd, const char *wild,
*/
for (var=variables; var->type == SHOW_FUNC ||
var->type == SHOW_SIMPLE_FUNC; var= &tmp)
((mysql_show_var_func)(var->value))(thd, &tmp, buff);
((mysql_show_var_func)(var->value))(thd, &tmp, buff, scope);
SHOW_TYPE show_type=var->type;
if (show_type == SHOW_ARRAY)
{
......
......@@ -67,4 +67,5 @@ extern void tp_set_threadpool_stall_limit(uint val);
/* Activate threadpool scheduler */
extern void tp_scheduler(void);
extern int show_threadpool_idle_threads(THD *thd, SHOW_VAR *var, char *buff);
extern int show_threadpool_idle_threads(THD *thd, SHOW_VAR *var, char *buff,
enum enum_var_type scope);
......@@ -112,7 +112,8 @@ extern const char* wsrep_provider_name;
extern const char* wsrep_provider_version;
extern const char* wsrep_provider_vendor;
int wsrep_show_status(THD *thd, SHOW_VAR *var, char *buff);
int wsrep_show_status(THD *thd, SHOW_VAR *var, char *buff,
enum enum_var_type scope);
int wsrep_init();
void wsrep_deinit(bool free_options);
void wsrep_recover();
......
......@@ -38,12 +38,13 @@ static volatile int32 wsrep_bf_aborts_counter(0);
#define WSREP_ATOMIC_ADD_LONG my_atomic_add32
#endif
int wsrep_show_bf_aborts (THD *thd, SHOW_VAR *var, char *buff)
int wsrep_show_bf_aborts (THD *thd, SHOW_VAR *var, char *buff,
enum enum_var_type scope)
{
wsrep_local_bf_aborts = WSREP_ATOMIC_LOAD_LONG(&wsrep_bf_aborts_counter);
var->type = SHOW_LONGLONG;
var->value = (char*)&wsrep_local_bf_aborts;
return 0;
wsrep_local_bf_aborts = WSREP_ATOMIC_LOAD_LONG(&wsrep_bf_aborts_counter);
var->type = SHOW_LONGLONG;
var->value = (char*)&wsrep_local_bf_aborts;
return 0;
}
/* must have (&thd->LOCK_wsrep_thd) */
......
......@@ -22,7 +22,8 @@
#include "sql_class.h"
int wsrep_show_bf_aborts (THD *thd, SHOW_VAR *var, char *buff);
int wsrep_show_bf_aborts (THD *thd, SHOW_VAR *var, char *buff,
enum enum_var_type scope);
void wsrep_client_rollback(THD *thd);
void wsrep_replay_transaction(THD *thd);
void wsrep_create_appliers(long threads);
......
......@@ -15,7 +15,6 @@
#include "wsrep_var.h"
#include <sql_plugin.h>
#include <mysqld.h>
#include <sql_class.h>
#include <set_var.h>
......@@ -535,7 +534,8 @@ static int show_var_cmp(const void *var1, const void *var2)
return strcasecmp(((SHOW_VAR*)var1)->name, ((SHOW_VAR*)var2)->name);
}
int wsrep_show_status (THD *thd, SHOW_VAR *var, char *buff)
int wsrep_show_status (THD *thd, SHOW_VAR *var, char *buff,
enum enum_var_type scope)
{
uint i, maxi= SHOW_VAR_FUNC_BUFF_SIZE / sizeof(*var) - 1;
SHOW_VAR *v= (SHOW_VAR *)buff;
......
......@@ -27,6 +27,9 @@
// MySQL variables funcs
#include "sql_priv.h"
#include <sql_plugin.h>
#include <mysql/plugin.h>
class sys_var;
class set_var;
class THD;
......
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