diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-13 13:39:13 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-13 13:39:13 +0000 |
commit | 86fbb58c3ac0865482819c10a3e81f2eea001c36 (patch) | |
tree | 28c9e526ea739c6f9b89e36115e1e2698bddf981 /mysys | |
parent | Releasing progress-linux version 1:10.11.6-2~progress7.99u1. (diff) | |
download | mariadb-86fbb58c3ac0865482819c10a3e81f2eea001c36.tar.xz mariadb-86fbb58c3ac0865482819c10a3e81f2eea001c36.zip |
Merging upstream version 1:10.11.7.
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to '')
-rw-r--r-- | mysys/my_alloc.c | 54 | ||||
-rw-r--r-- | mysys/safemalloc.c | 12 | ||||
-rw-r--r-- | mysys/thr_alarm.c | 1 | ||||
-rw-r--r-- | mysys/thr_lock.c | 3 | ||||
-rw-r--r-- | mysys/thr_mutex.c | 1 | ||||
-rw-r--r-- | mysys/thr_timer.c | 1 |
6 files changed, 40 insertions, 32 deletions
diff --git a/mysys/my_alloc.c b/mysys/my_alloc.c index eff5a031..22ec265e 100644 --- a/mysys/my_alloc.c +++ b/mysys/my_alloc.c @@ -28,21 +28,16 @@ #undef EXTRA_DEBUG #define EXTRA_DEBUG -#ifndef DBUG_OFF -/* Put a protected barrier after every element when using multi_alloc_root() */ -#define ALLOC_BARRIER -#endif +#define ROOT_FLAG_THREAD_SPECIFIC 1 +#define ROOT_FLAG_MPROTECT 2 +#define ROOT_FLAG_READ_ONLY 4 /* data packed in MEM_ROOT -> min_malloc */ /* Don't allocate too small blocks */ #define ROOT_MIN_BLOCK_SIZE 256 -/* bits in MEM_ROOT->flags */ -#define ROOT_FLAG_THREAD_SPECIFIC 1 -#define ROOT_FLAG_MPROTECT 2 - -#define MALLOC_FLAG(R) MYF((R)->flags & ROOT_FLAG_THREAD_SPECIFIC ? 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) @@ -69,8 +64,7 @@ static void *root_alloc(MEM_ROOT *root, size_t size, size_t *alloced_size, #endif /* HAVE_MMAP */ return my_malloc(root->psi_key, size, - my_flags | MYF(root->flags & ROOT_FLAG_THREAD_SPECIFIC ? - MY_THREAD_SPECIFIC : 0)); + my_flags | MALLOC_FLAG(root)); } static void root_free(MEM_ROOT *root, void *ptr, size_t size) @@ -172,9 +166,6 @@ void init_alloc_root(PSI_memory_key key, MEM_ROOT *mem_root, size_t block_size, mem_root->block_num= 4; /* We shift this with >>2 */ mem_root->first_block_usage= 0; mem_root->psi_key= key; -#ifdef PROTECT_STATEMENT_MEMROOT - mem_root->read_only= 0; -#endif #if !(defined(HAVE_valgrind) && defined(EXTRA_DEBUG)) if (pre_alloc_size) @@ -281,10 +272,7 @@ void *alloc_root(MEM_ROOT *mem_root, size_t length) DBUG_ENTER("alloc_root"); DBUG_PRINT("enter",("root: %p", mem_root)); DBUG_ASSERT(alloc_root_inited(mem_root)); - -#ifdef PROTECT_STATEMENT_MEMROOT - DBUG_ASSERT(mem_root->read_only == 0); -#endif + DBUG_ASSERT((mem_root->flags & ROOT_FLAG_READ_ONLY) == 0); DBUG_EXECUTE_IF("simulate_out_of_memory", { @@ -300,9 +288,7 @@ void *alloc_root(MEM_ROOT *mem_root, size_t length) length+= ALIGN_SIZE(sizeof(USED_MEM)); if (!(next = (USED_MEM*) my_malloc(mem_root->psi_key, length, MYF(MY_WME | ME_FATAL | - (mem_root->flags & - ROOT_FLAG_THREAD_SPECIFIC ? - MY_THREAD_SPECIFIC : 0))))) + MALLOC_FLAG(mem_root))))) { if (mem_root->error_handler) (*mem_root->error_handler)(); @@ -410,7 +396,7 @@ void *multi_alloc_root(MEM_ROOT *root, ...) { length= va_arg(args, uint); tot_length+= ALIGN_SIZE(length); -#ifdef ALLOC_BARRIER +#ifndef DBUG_OFF tot_length+= ALIGN_SIZE(1); #endif } @@ -426,7 +412,7 @@ void *multi_alloc_root(MEM_ROOT *root, ...) *ptr= res; length= va_arg(args, uint); res+= ALIGN_SIZE(length); -#ifdef ALLOC_BARRIER +#ifndef DBUG_OFF TRASH_FREE(res, ALIGN_SIZE(1)); res+= ALIGN_SIZE(1); #endif @@ -560,6 +546,28 @@ void set_prealloc_root(MEM_ROOT *root, char *ptr) } } +/* + Move allocated objects from one root to another. + + Notes: + We do not increase 'to->block_num' here as the variable isused to + increase block sizes in case of many allocations. This is special + case where this is not needed to take into account +*/ + +void move_root(MEM_ROOT *to, MEM_ROOT *from) +{ + USED_MEM *block, *next; + for (block= from->used; block ; block= next) + { + next= block->next; + block->next= to->used; + to->used= block; + } + from->used= 0; +} + + /* Remember last MEM_ROOT block. diff --git a/mysys/safemalloc.c b/mysys/safemalloc.c index edfe3b18..2fc34a92 100644 --- a/mysys/safemalloc.c +++ b/mysys/safemalloc.c @@ -70,7 +70,7 @@ struct st_irem uint32 marker; /* Underrun marker value */ }; -static int sf_malloc_count= 0; /* Number of allocated chunks */ +static uint sf_malloc_count= 0; /* Number of allocated chunks */ static void *sf_min_adress= (void*) (intptr)~0ULL, *sf_max_adress= 0; @@ -362,7 +362,7 @@ int sf_sanity() { struct st_irem *irem; int flag= 0; - int count= 0; + uint count= 0; pthread_mutex_lock(&sf_mutex); count= sf_malloc_count; @@ -387,6 +387,7 @@ void sf_report_leaked_memory(my_thread_id id) { size_t total= 0; struct st_irem *irem; + uint first= 0, chunks= 0; sf_sanity(); @@ -398,15 +399,18 @@ void sf_report_leaked_memory(my_thread_id id) { my_thread_id tid = irem->thread_id && irem->flags & MY_THREAD_SPECIFIC ? irem->thread_id : 0; + if (!first++) + fprintf(stderr, "Memory report from safemalloc\n"); fprintf(stderr, "Warning: %4lu bytes lost at %p, allocated by T@%llu at ", (ulong) irem->datasize, (char*) (irem + 1), tid); print_stack(irem->frame); total+= irem->datasize; + chunks++; } } if (total) - fprintf(stderr, "Memory lost: %lu bytes in %d chunks\n", - (ulong) total, sf_malloc_count); + fprintf(stderr, "Memory lost: %lu bytes in %u chunks of %u total chunks\n", + (ulong) total, chunks, sf_malloc_count); return; } diff --git a/mysys/thr_alarm.c b/mysys/thr_alarm.c index b98775e1..4e2db203 100644 --- a/mysys/thr_alarm.c +++ b/mysys/thr_alarm.c @@ -786,7 +786,6 @@ int main(int argc __attribute__((unused)),char **argv __attribute__((unused))) mysql_mutex_unlock(&LOCK_thread_count); DBUG_PRINT("info",("signal thread created")); - thr_setconcurrency(3); pthread_attr_setscope(&thr_attr,PTHREAD_SCOPE_PROCESS); printf("Main thread: %s\n",my_thread_name()); for (i=0 ; i < 2 ; i++) diff --git a/mysys/thr_lock.c b/mysys/thr_lock.c index c1ec0623..214ff01b 100644 --- a/mysys/thr_lock.c +++ b/mysys/thr_lock.c @@ -1784,9 +1784,6 @@ int main(int argc __attribute__((unused)),char **argv __attribute__((unused))) exit(1); } #endif -#ifdef HAVE_THR_SETCONCURRENCY - (void) thr_setconcurrency(2); -#endif for (i=0 ; i < array_elements(lock_counts) ; i++) { param[i]= i; diff --git a/mysys/thr_mutex.c b/mysys/thr_mutex.c index aca1c1f7..8714a7a6 100644 --- a/mysys/thr_mutex.c +++ b/mysys/thr_mutex.c @@ -667,6 +667,7 @@ void safe_mutex_free_deadlock_data(safe_mutex_t *mp) my_hash_free(mp->used_mutex); my_hash_free(mp->locked_mutex); my_free(mp->locked_mutex); + mp->locked_mutex= 0; mp->create_flags|= MYF_NO_DEADLOCK_DETECTION; } } diff --git a/mysys/thr_timer.c b/mysys/thr_timer.c index f87c1f75..d3627fea 100644 --- a/mysys/thr_timer.c +++ b/mysys/thr_timer.c @@ -533,7 +533,6 @@ static void run_test() mysql_mutex_init(0, &LOCK_thread_count, MY_MUTEX_INIT_FAST); mysql_cond_init(0, &COND_thread_count, NULL); - thr_setconcurrency(3); pthread_attr_init(&thr_attr); pthread_attr_setscope(&thr_attr,PTHREAD_SCOPE_PROCESS); printf("Main thread: %s\n",my_thread_name()); |