28 #include "mem0pool.ic"
95 #define MEM_AREA_FREE 1
98 #define MEM_AREA_MIN_SIZE (2 * MEM_AREA_EXTRA_SIZE)
118 #ifdef UNIV_PFS_MUTEX
120 UNIV_INTERN mysql_pfs_key_t mem_pool_mutex_key;
127 UNIV_INTERN ulint mem_n_threads_inside = 0;
140 mutex_enter(&(pool->
mutex));
155 mutex_exit(&(pool->
mutex));
193 #if TRUE != MEM_AREA_FREE
194 # error "TRUE != MEM_AREA_FREE"
208 #if TRUE != MEM_AREA_FREE
209 # error "TRUE != MEM_AREA_FREE"
234 mutex_create(mem_pool_mutex_key, &pool->
mutex, SYNC_MEM_POOL);
238 for (i = 0; i < 64; i++) {
292 mem_pool_fill_free_list(
303 if (UNIV_UNLIKELY(i >= 63)) {
317 " InnoDB: Error: mem pool free list %lu"
319 "InnoDB: though the list is empty!\n",
325 ret = mem_pool_fill_free_list(i + 1, pool);
380 if (UNIV_LIKELY(srv_use_sys_malloc)) {
381 return(malloc(*psize));
387 mutex_enter(&(pool->
mutex));
388 mem_n_threads_inside++;
390 ut_a(mem_n_threads_inside == 1);
395 ret = mem_pool_fill_free_list(n, pool);
401 mem_n_threads_inside--;
402 mutex_exit(&(pool->
mutex));
412 "InnoDB: Error: Removing element from mem pool"
413 " free list %lu though the\n"
414 "InnoDB: element is not marked free!\n",
425 "InnoDB: Probably a race condition"
426 " because now the area is marked free!\n");
434 "InnoDB: Error: Removing element from mem pool"
436 "InnoDB: though the list length is 0!\n",
451 mem_n_threads_inside--;
452 mutex_exit(&(pool->
mutex));
477 if (((((byte*) area) - pool->
buf) % (2 * size)) == 0) {
483 if ((((byte*) buddy) - pool->
buf) + size > pool->
size) {
518 if (UNIV_LIKELY(srv_use_sys_malloc)) {
527 if ((byte*) ptr < pool->
buf || (byte*) ptr >= pool->
buf + pool->
size) {
537 "InnoDB: Error: Freeing element to mem pool"
538 " free list though the\n"
539 "InnoDB: element is marked free!\n");
550 "InnoDB: Error: Mem area size is 0. Possibly a"
551 " memory overrun of the\n"
552 "InnoDB: previous allocated area!\n");
558 #ifdef UNIV_LIGHT_MEM_DEBUG
559 if (((byte*) area) + size < pool->
buf + pool->
size) {
565 if (UNIV_UNLIKELY(!next_size || !
ut_is_2pow(next_size))) {
567 "InnoDB: Error: Memory area size %lu,"
568 " next area size %lu not a power of 2!\n"
569 "InnoDB: Possibly a memory overrun of"
570 " the buffer being freed here.\n",
571 (ulong) size, (ulong) next_size);
583 mem_n_threads_inside++;
585 ut_a(mem_n_threads_inside == 1);
592 if ((byte*) buddy < (byte*) area) {
609 mem_n_threads_inside--;
625 mem_n_threads_inside--;
649 for (i = 0; i < 64; i++) {
689 fprintf(outfile,
"INFO OF A MEMORY POOL\n");
691 mutex_enter(&(pool->
mutex));
693 for (i = 0; i < 64; i++) {
697 "Free list length %lu for"
698 " blocks of size %lu\n",
704 fprintf(outfile,
"Pool size %lu, reserved %lu.\n", (ulong) pool->
size,
706 mutex_exit(&(pool->
mutex));
720 mutex_enter(&(pool->
mutex));
724 mutex_exit(&(pool->
mutex));