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 /mysys/my_alloc.c | |
parent | 2ac3121af2767186c489054db5d4871d04b8eef4 (diff) | |
download | mariadb-git-7c58e97bf6f80a251046c5b3e7bce826fe058bd6.tar.gz |
perfschema memory related instrumentation changes
Diffstat (limited to 'mysys/my_alloc.c')
-rw-r--r-- | mysys/my_alloc.c | 42 |
1 files changed, 14 insertions, 28 deletions
diff --git a/mysys/my_alloc.c b/mysys/my_alloc.c index 79e4ba9d563..3120ee50a59 100644 --- a/mysys/my_alloc.c +++ b/mysys/my_alloc.c @@ -54,35 +54,32 @@ Because of this, we store in MY_THREAD_SPECIFIC as bit 1 in block_size */ -void init_alloc_root(MEM_ROOT *mem_root, const char *name, size_t block_size, +void init_alloc_root(PSI_memory_key key, MEM_ROOT *mem_root, size_t block_size, size_t pre_alloc_size __attribute__((unused)), myf my_flags) { DBUG_ENTER("init_alloc_root"); - DBUG_PRINT("enter",("root: %p name: %s prealloc: %zu", mem_root, - name, pre_alloc_size)); + DBUG_PRINT("enter",("root: %p prealloc: %zu", mem_root, pre_alloc_size)); mem_root->free= mem_root->used= mem_root->pre_alloc= 0; mem_root->min_malloc= 32; mem_root->block_size= (block_size - ALLOC_ROOT_MIN_BLOCK_SIZE) & ~1; - if (MY_TEST(my_flags & MY_THREAD_SPECIFIC)) + if (my_flags & MY_THREAD_SPECIFIC) mem_root->block_size|= 1; mem_root->error_handler= 0; mem_root->block_num= 4; /* We shift this with >>2 */ mem_root->first_block_usage= 0; - mem_root->total_alloc= 0; - mem_root->name= name; + mem_root->m_psi_key= key; #if !(defined(HAVE_valgrind) && defined(EXTRA_DEBUG)) if (pre_alloc_size) { + size_t size= pre_alloc_size + ALIGN_SIZE(sizeof(USED_MEM)); if ((mem_root->free= mem_root->pre_alloc= - (USED_MEM*) my_malloc(pre_alloc_size + ALIGN_SIZE(sizeof(USED_MEM)), - MYF(my_flags)))) + (USED_MEM*) my_malloc(key, size, MYF(my_flags)))) { - mem_root->free->size= pre_alloc_size+ALIGN_SIZE(sizeof(USED_MEM)); - mem_root->total_alloc= pre_alloc_size+ALIGN_SIZE(sizeof(USED_MEM)); + mem_root->free->size= size; mem_root->free->left= pre_alloc_size; mem_root->free->next= 0; TRASH_MEM(mem_root->free); @@ -141,19 +138,17 @@ void reset_root_defaults(MEM_ROOT *mem_root, size_t block_size, { /* remove block from the list and free it */ *prev= mem->next; - mem_root->total_alloc-= mem->size; my_free(mem); } else prev= &mem->next; } /* Allocate new prealloc block and add it to the end of free list */ - if ((mem= (USED_MEM *) my_malloc(size, + if ((mem= (USED_MEM *) my_malloc(mem_root->m_psi_key, size, MYF(MALLOC_FLAG(mem_root-> block_size))))) { mem->size= size; - mem_root->total_alloc+= size; mem->left= pre_alloc_size; mem->next= *prev; *prev= mem_root->pre_alloc= mem; @@ -178,7 +173,7 @@ void *alloc_root(MEM_ROOT *mem_root, size_t length) #if defined(HAVE_valgrind) && defined(EXTRA_DEBUG) reg1 USED_MEM *next; DBUG_ENTER("alloc_root"); - DBUG_PRINT("enter",("root: %p name: %s", mem_root, mem_root->name)); + DBUG_PRINT("enter",("root: %p name: %s", mem_root, root_name(mem_root))); DBUG_ASSERT(alloc_root_inited(mem_root)); @@ -203,10 +198,8 @@ void *alloc_root(MEM_ROOT *mem_root, size_t length) next->left= 0; next->size= length; mem_root->used= next; - mem_root->total_alloc+= length; - DBUG_PRINT("exit",("ptr: %p", (((char*) next)+ - ALIGN_SIZE(sizeof(USED_MEM))))); - DBUG_RETURN((uchar*) (((char*) next)+ALIGN_SIZE(sizeof(USED_MEM)))); + DBUG_PRINT("exit",("ptr: %p", (((char*)next)+ALIGN_SIZE(sizeof(USED_MEM))))); + DBUG_RETURN((((uchar*) next)+ALIGN_SIZE(sizeof(USED_MEM)))); #else size_t get_size, block_size; uchar* point; @@ -214,7 +207,7 @@ void *alloc_root(MEM_ROOT *mem_root, size_t length) reg2 USED_MEM **prev; size_t original_length = length; DBUG_ENTER("alloc_root"); - DBUG_PRINT("enter",("root: %p name: %s", mem_root, mem_root->name)); + DBUG_PRINT("enter",("root: %p name: %s", mem_root, root_name(mem_root))); DBUG_ASSERT(alloc_root_inited(mem_root)); DBUG_EXECUTE_IF("simulate_out_of_memory", @@ -247,7 +240,7 @@ void *alloc_root(MEM_ROOT *mem_root, size_t length) get_size= length+ALIGN_SIZE(sizeof(USED_MEM)); get_size= MY_MAX(get_size, block_size); - if (!(next = (USED_MEM*) my_malloc(get_size, + if (!(next = (USED_MEM*) my_malloc(mem_root->m_psi_key, get_size, MYF(MY_WME | ME_FATAL | MALLOC_FLAG(mem_root-> block_size))))) @@ -257,7 +250,6 @@ void *alloc_root(MEM_ROOT *mem_root, size_t length) DBUG_RETURN((void*) 0); /* purecov: inspected */ } mem_root->block_num++; - mem_root->total_alloc+= get_size; next->next= *prev; next->size= get_size; next->left= get_size-ALIGN_SIZE(sizeof(USED_MEM)); @@ -394,7 +386,7 @@ void free_root(MEM_ROOT *root, myf MyFlags) { reg1 USED_MEM *next,*old; DBUG_ENTER("free_root"); - DBUG_PRINT("enter",("root: %p name: %s flags: %u", root, root->name, + DBUG_PRINT("enter",("root: %p name: %s flags: %u", root, root_name(root), (uint) MyFlags)); #if !(defined(HAVE_valgrind) && defined(EXTRA_DEBUG)) @@ -415,19 +407,13 @@ void free_root(MEM_ROOT *root, myf MyFlags) { old=next; next= next->next ; if (old != root->pre_alloc) - { - root->total_alloc-= old->size; my_free(old); - } } for (next=root->free ; next ;) { old=next; next= next->next; if (old != root->pre_alloc) - { - root->total_alloc-= old->size; my_free(old); - } } root->used=root->free=0; if (root->pre_alloc) |