mem_block_t *mem_heap_create_block_func( mem_heap_t *heap, /*!< in: memory heap or NULL if first block should be created */ ulint n, /*!< in: number of bytes needed for user data */ #ifdef UNIV_DEBUG const char *file_name, /*!< in: file name where created */ ulint line, /*!< in: line where created */ #endif /* UNIV_DEBUG */ ulint type) /*!< in: type of heap: MEM_HEAP_DYNAMIC or MEM_HEAP_BUFFER */ { len = MEM_BLOCK_HEADER_SIZE + MEM_SPACE_NEEDED(n); if (type == MEM_HEAP_DYNAMIC || len < UNIV_PAGE_SIZE / 2) { block = static_cast<mem_block_t *>(ut_malloc_nokey(len)); } else { block = 从buffer_pool 中取 len = ((ulint)srv_page_size); if ((type & MEM_HEAP_BTR_SEARCH) && heap) { /* We cannot allocate the block from the buffer pool, but must get the free block from the heap header free block field */ buf_block = static_cast<buf_block_t *>(heap->free_block); heap->free_block = NULL; } else { buf_block = buf_block_alloc(NULL); }
void mem_heap_block_free(mem_heap_t *heap, /*!< in: heap */ mem_block_t *block){ UT_LIST_REMOVE(heap->base, block); heap->total_size -= block->len; block->magic_n = MEM_FREED_BLOCK_MAGIC_N; if (type == MEM_HEAP_DYNAMIC || len < UNIV_PAGE_SIZE / 2) { ut_allocator<byte>(PSI_NOT_INSTRUMENTED) \ .deallocate(reinterpret_cast<byte *>(block)); // 实际上就是把整个ut_new_pfx_t内存块给释放掉, 清掉了trace 字段 } else { /* Make memory available again for buffer pool, as we set parts of block to "free" state in heap allocator. */ UNIV_MEM_ALLOC(block, UNIV_PAGE_SIZE); buf_block_free(buf_block); ///** Frees a buffer block which does not contain a file page. */ //buf_LRU_block_free_non_file_page(block); } }