Commit d1ca8fbb authored by Sergei Golubchik's avatar Sergei Golubchik

Backport MEM_ROOT::flags from 10.7

parent 7317aade
...@@ -49,7 +49,8 @@ typedef struct st_mem_root ...@@ -49,7 +49,8 @@ typedef struct st_mem_root
first free block in queue test counter (if it exceed first free block in queue test counter (if it exceed
MAX_BLOCK_USAGE_BEFORE_DROP block will be dropped in 'used' list) MAX_BLOCK_USAGE_BEFORE_DROP block will be dropped in 'used' list)
*/ */
unsigned int first_block_usage; unsigned short first_block_usage;
unsigned short flags;
#ifdef PROTECT_STATEMENT_MEMROOT #ifdef PROTECT_STATEMENT_MEMROOT
int read_only; int read_only;
......
...@@ -23,9 +23,11 @@ ...@@ -23,9 +23,11 @@
#undef EXTRA_DEBUG #undef EXTRA_DEBUG
#define EXTRA_DEBUG #define EXTRA_DEBUG
#define ROOT_FLAG_THREAD_SPECIFIC 1
/* data packed in MEM_ROOT -> min_malloc */ /* data packed in MEM_ROOT -> min_malloc */
#define MALLOC_FLAG(A) ((A & 1) ? MY_THREAD_SPECIFIC : 0) #define MALLOC_FLAG(root) (((root)->flags & ROOT_FLAG_THREAD_SPECIFIC) ? MY_THREAD_SPECIFIC : 0)
#define TRASH_MEM(X) TRASH_FREE(((char*)(X) + ((X)->size-(X)->left)), (X)->left) #define TRASH_MEM(X) TRASH_FREE(((char*)(X) + ((X)->size-(X)->left)), (X)->left)
...@@ -50,9 +52,6 @@ ...@@ -50,9 +52,6 @@
Although error can happen during execution of this function if Although error can happen during execution of this function if
pre_alloc_size is non-0 it won't be reported. Instead it will be pre_alloc_size is non-0 it won't be reported. Instead it will be
reported as error in first alloc_root() on this memory root. reported as error in first alloc_root() on this memory root.
We don't want to change the structure size for MEM_ROOT.
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(MEM_ROOT *mem_root, const char *name, size_t block_size,
...@@ -65,9 +64,10 @@ void init_alloc_root(MEM_ROOT *mem_root, const char *name, size_t block_size, ...@@ -65,9 +64,10 @@ void init_alloc_root(MEM_ROOT *mem_root, const char *name, size_t block_size,
mem_root->free= mem_root->used= mem_root->pre_alloc= 0; mem_root->free= mem_root->used= mem_root->pre_alloc= 0;
mem_root->min_malloc= 32; mem_root->min_malloc= 32;
mem_root->block_size= (block_size - ALLOC_ROOT_MIN_BLOCK_SIZE) & ~1; mem_root->block_size= block_size - ALLOC_ROOT_MIN_BLOCK_SIZE;
if (MY_TEST(my_flags & MY_THREAD_SPECIFIC)) mem_root->flags= 0;
mem_root->block_size|= 1; if (my_flags & MY_THREAD_SPECIFIC)
mem_root->flags|= ROOT_FLAG_THREAD_SPECIFIC;
mem_root->error_handler= 0; mem_root->error_handler= 0;
mem_root->block_num= 4; /* We shift this with >>2 */ mem_root->block_num= 4; /* We shift this with >>2 */
...@@ -119,8 +119,7 @@ void reset_root_defaults(MEM_ROOT *mem_root, size_t block_size, ...@@ -119,8 +119,7 @@ void reset_root_defaults(MEM_ROOT *mem_root, size_t block_size,
DBUG_ENTER("reset_root_defaults"); DBUG_ENTER("reset_root_defaults");
DBUG_ASSERT(alloc_root_inited(mem_root)); DBUG_ASSERT(alloc_root_inited(mem_root));
mem_root->block_size= (((block_size - ALLOC_ROOT_MIN_BLOCK_SIZE) & ~1) | mem_root->block_size= block_size - ALLOC_ROOT_MIN_BLOCK_SIZE;
(mem_root->block_size & 1));
#if !(defined(HAVE_valgrind) && defined(EXTRA_DEBUG)) #if !(defined(HAVE_valgrind) && defined(EXTRA_DEBUG))
if (pre_alloc_size) if (pre_alloc_size)
{ {
...@@ -153,8 +152,7 @@ void reset_root_defaults(MEM_ROOT *mem_root, size_t block_size, ...@@ -153,8 +152,7 @@ void reset_root_defaults(MEM_ROOT *mem_root, size_t block_size,
} }
/* Allocate new prealloc block and add it to the end of free list */ /* 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(size,
MYF(MALLOC_FLAG(mem_root-> MYF(MALLOC_FLAG(mem_root)))))
block_size)))))
{ {
mem->size= size; mem->size= size;
mem_root->total_alloc+= size; mem_root->total_alloc+= size;
...@@ -197,7 +195,7 @@ void *alloc_root(MEM_ROOT *mem_root, size_t length) ...@@ -197,7 +195,7 @@ void *alloc_root(MEM_ROOT *mem_root, size_t length)
length+=ALIGN_SIZE(sizeof(USED_MEM)); length+=ALIGN_SIZE(sizeof(USED_MEM));
if (!(next = (USED_MEM*) my_malloc(length, if (!(next = (USED_MEM*) my_malloc(length,
MYF(MY_WME | ME_FATAL | MYF(MY_WME | ME_FATAL |
MALLOC_FLAG(mem_root->block_size))))) MALLOC_FLAG(mem_root)))))
{ {
if (mem_root->error_handler) if (mem_root->error_handler)
(*mem_root->error_handler)(); (*mem_root->error_handler)();
...@@ -251,14 +249,13 @@ void *alloc_root(MEM_ROOT *mem_root, size_t length) ...@@ -251,14 +249,13 @@ void *alloc_root(MEM_ROOT *mem_root, size_t length)
} }
if (! next) if (! next)
{ /* Time to alloc new block */ { /* Time to alloc new block */
block_size= (mem_root->block_size & ~1) * (mem_root->block_num >> 2); block_size= mem_root->block_size * (mem_root->block_num >> 2);
get_size= length+ALIGN_SIZE(sizeof(USED_MEM)); get_size= length+ALIGN_SIZE(sizeof(USED_MEM));
get_size= MY_MAX(get_size, block_size); get_size= MY_MAX(get_size, block_size);
if (!(next = (USED_MEM*) my_malloc(get_size, if (!(next = (USED_MEM*) my_malloc(get_size,
MYF(MY_WME | ME_FATAL | MYF(MY_WME | ME_FATAL |
MALLOC_FLAG(mem_root-> MALLOC_FLAG(mem_root)))))
block_size)))))
{ {
if (mem_root->error_handler) if (mem_root->error_handler)
(*mem_root->error_handler)(); (*mem_root->error_handler)();
......
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