Commit 74048efb authored by Kristian Nielsen's avatar Kristian Nielsen

MDEV-30889: max_global_memory_used status variable

Implement a new status variable max_global_memory_used, which gives the peak
value of global_memory_used.

When mallinfo2() shows a lot of memory being free in the malloc
implementation, this can be used to understand if this is because that
memory was at one point allocated to the server during a peak load situation
and later freed; or if it is caused by internal fragmentation in the malloc
implementation.
Signed-off-by: default avatarKristian Nielsen <knielsen@knielsen-hq.org>
parent 7318fa18
......@@ -3784,6 +3784,8 @@ static void my_malloc_size_cb_func(long long size, my_bool is_thread_specific)
DBUG_PRINT("info", ("global thd memory_used: %lld size: %lld",
(longlong) thd->status_var.global_memory_used, size));
thd->status_var.global_memory_used+= size;
set_if_bigger(thd->status_var.max_global_memory_used,
thd->status_var.global_memory_used);
}
else
update_global_memory_status(size);
......@@ -3852,6 +3854,7 @@ static int init_early_variables()
set_current_thd(0);
set_malloc_size_cb(my_malloc_size_cb_func);
global_status_var.global_memory_used= 0;
global_status_var.max_global_memory_used= 0;
init_alloc_root(PSI_NOT_INSTRUMENTED, &startup_root, 1024, 0, MYF(0));
init_alloc_root(PSI_NOT_INSTRUMENTED, &read_only_root, 1024, 0,
MYF(MY_ROOT_USE_MPROTECT));
......
......@@ -795,6 +795,7 @@ THD::THD(my_thread_id id, bool is_wsrep_applier)
status_var.local_memory_used= sizeof(THD);
status_var.max_local_memory_used= status_var.local_memory_used;
status_var.global_memory_used= 0;
status_var.max_global_memory_used= 0;
variables.pseudo_thread_id= thread_id;
variables.max_mem_used= global_system_variables.max_mem_used;
main_da.init();
......@@ -1921,7 +1922,10 @@ void add_to_status(STATUS_VAR *to_var, STATUS_VAR *from_var)
update_global_memory_status(from_var->global_memory_used);
}
else
{
to_var->global_memory_used+= from_var->global_memory_used;
set_if_bigger(to_var->max_global_memory_used, to_var->global_memory_used);
}
}
/*
......
......@@ -1061,6 +1061,7 @@ typedef struct system_status_var
volatile int64 local_memory_used;
/* Memory allocated for global usage */
volatile int64 global_memory_used;
volatile int64 max_global_memory_used;
} STATUS_VAR;
/*
......@@ -1113,6 +1114,9 @@ static inline void update_global_memory_status(int64 size)
// workaround for gcc 4.2.4-1ubuntu4 -fPIE (from DEB_BUILD_HARDENING=1)
int64 volatile * volatile ptr= &global_status_var.global_memory_used;
my_atomic_add64_explicit(ptr, size, MY_MEMORY_ORDER_RELAXED);
// This is slightly approximate, as we are not using atomic set_if_bigger().
set_if_bigger(global_status_var.max_global_memory_used,
global_status_var.global_memory_used);
}
......
......@@ -626,7 +626,7 @@ Open streams: %10lu\n",
MEM_MAKE_DEFINED(&info, sizeof info);
#endif
#if defined(HAVE_MALLINFO) || defined(HAVE_MALLINFO2)
char llbuff[10][22];
char llbuff[11][22];
printf("\nMemory status:\n\
Non-mmapped space allocated from system: %s\n\
Number of free chunks: %lu\n\
......@@ -640,6 +640,7 @@ Total free space: %s\n\
Top-most, releasable space: %s\n\
Estimated memory (with thread stack): %s\n\
Global memory allocated by server: %s\n\
Peak global memory allocated by server: %s\n\
Memory allocated by threads: %s\n",
llstr(info.arena, llbuff[0]),
(ulong) info.ordblks,
......@@ -654,7 +655,8 @@ Memory allocated by threads: %s\n",
llstr((count + thread_cache.size()) * my_thread_stack_size +
info.hblkhd + info.arena, llbuff[7]),
llstr(tmp.global_memory_used, llbuff[8]),
llstr(tmp.local_memory_used, llbuff[9]));
llstr(tmp.max_global_memory_used, llbuff[9]),
llstr(tmp.local_memory_used, llbuff[10]));
#elif defined(HAVE_MALLOC_ZONE)
malloc_statistics_t info;
......@@ -665,11 +667,13 @@ Memory allocated by threads: %s\n",
Total allocated space: %s\n\
Total free space: %s\n\
Global memory allocated by server: %s\n\
Peak global memory allocated by server: %s\n\
Memory allocated by threads: %s\n",
llstr(info.size_allocated, llbuff[0]),
llstr((info.size_allocated - info.size_in_use), llbuff[1]),
llstr(tmp.global_memory_used, llbuff[2]),
llstr(tmp.local_memory_used, llbuff[3]));
llstr(tmp.max_global_memory_used, llbuff[3]),
llstr(tmp.local_memory_used, llbuff[4]));
#endif
#ifdef HAVE_EVENT_SCHEDULER
......
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