Skip to content

Commit c4a5bd1

Browse files
committed
Added Myisam, Aria and InnoDB buffer pool to @@memory_used status variable
This makes it easier to see how much memory MariaDB server has allocated. (For all memory allocations that goes through mysys)
1 parent e3b36b8 commit c4a5bd1

File tree

4 files changed

+19
-10
lines changed

4 files changed

+19
-10
lines changed

include/my_sys.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -160,6 +160,7 @@ extern my_thread_id (*sf_malloc_dbug_id)(void);
160160

161161
typedef void (*MALLOC_SIZE_CB) (long long size, my_bool is_thread_specific);
162162
extern void set_malloc_size_cb(MALLOC_SIZE_CB func);
163+
extern MALLOC_SIZE_CB update_malloc_size;
163164

164165
/* defines when allocating data */
165166
extern void *my_malloc(PSI_memory_key key, size_t size, myf MyFlags);

mysys/my_largepage.c

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -398,6 +398,7 @@ uchar *my_large_malloc(size_t *size, myf my_flags)
398398
if (ptr != NULL)
399399
{
400400
MEM_MAKE_DEFINED(ptr, *size);
401+
update_malloc_size(*size, 0);
401402
}
402403

403404
DBUG_RETURN(ptr);
@@ -430,31 +431,36 @@ void my_large_free(void *ptr, size_t size)
430431
{
431432
my_error(EE_BADMEMORYRELEASE, MYF(ME_ERROR_LOG_ONLY), ptr, size, errno);
432433
}
433-
# if !__has_feature(memory_sanitizer)
434+
#if !__has_feature(memory_sanitizer)
434435
else
435436
{
436437
MEM_MAKE_ADDRESSABLE(ptr, size);
437438
}
438-
# endif
439+
#endif
440+
update_malloc_size(- (longlong) size, 0);
439441
#elif defined(_WIN32)
440442
/*
441443
When RELEASE memory, the size parameter must be 0.
442444
Do not use MEM_RELEASE with MEM_DECOMMIT.
443445
*/
444-
if (ptr && !VirtualFree(ptr, 0, MEM_RELEASE))
446+
if (ptr)
445447
{
446-
my_error(EE_BADMEMORYRELEASE, MYF(ME_ERROR_LOG_ONLY), ptr, size,
447-
GetLastError());
448+
if (!VirtualFree(ptr, 0, MEM_RELEASE))
449+
{
450+
my_error(EE_BADMEMORYRELEASE, MYF(ME_ERROR_LOG_ONLY), ptr, size,
451+
GetLastError());
452+
}
453+
update_malloc_size(- (longlong) size, 0);
448454
}
449-
# if !__has_feature(memory_sanitizer)
455+
#if !__has_feature(memory_sanitizer)
450456
else
451457
{
452458
MEM_MAKE_ADDRESSABLE(ptr, size);
453459
}
454-
# endif
460+
#endif /* memory_sanitizer */
455461
#else
456462
my_free_lock(ptr);
457-
#endif
463+
#endif /* HAVE_MMMAP */
458464

459465
DBUG_VOID_RETURN;
460466
}

mysys/my_lockmem.c

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ struct st_mem_list
3232

3333
LIST *mem_list;
3434

35-
uchar *my_malloc_lock(uint size,myf MyFlags)
35+
uchar *my_malloc_lock(size_t size, myf MyFlags)
3636
{
3737
int success;
3838
uint pagesize=sysconf(_SC_PAGESIZE);
@@ -70,6 +70,7 @@ uchar *my_malloc_lock(uint size,myf MyFlags)
7070
mysql_mutex_lock(&THR_LOCK_malloc);
7171
mem_list=list_add(mem_list,&element->list);
7272
mysql_mutex_unlock(&THR_LOCK_malloc);
73+
update_malloc_size((longlong) size, 0);
7374
}
7475
DBUG_RETURN(ptr);
7576
}
@@ -88,6 +89,7 @@ void my_free_lock(uchar *ptr)
8889
{ /* Found locked mem */
8990
(void) munlock((uchar*) ptr,element->size);
9091
mem_list=list_delete(mem_list,list);
92+
update_malloc_size(- (longlong) element->size, 0);
9193
break;
9294
}
9395
}

mysys/my_malloc.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ static void dummy(long long size __attribute__((unused)),
4848
my_bool is_thread_specific __attribute__((unused)))
4949
{}
5050

51-
static MALLOC_SIZE_CB update_malloc_size= dummy;
51+
MALLOC_SIZE_CB update_malloc_size= dummy;
5252

5353
void set_malloc_size_cb(MALLOC_SIZE_CB func)
5454
{

0 commit comments

Comments
 (0)