/********************************************************************//**
Creates the buffer pool.
@return DB_SUCCESS if success, DB_ERROR if not enough memory or error */
UNIV_INTERN
ulint
buf_pool_init(
/*==========*/
ulint total_size, /*!< in: size of the total pool in bytes */
ulint n_instances) /*!< in: number of instances */
{
ulint i;
//n_instances 一般为1
const ulint size = total_size / n_instances;
ut_ad(n_instances > 0);
ut_ad(n_instances <= MAX_BUFFER_POOLS); //#define MAX_BUFFER_POOLS (1 << MAX_BUFFER_POOLS_BITS) 1<<6
ut_ad(n_instances == srv_buf_pool_instances);
/* We create an extra buffer pool instance, this instance is used
for flushing the flush lists, to keep track of n_flush for all
the buffer pools and also used as a waiting object during flushing. */
//UNIV_INTERN buf_pool_t* buf_pool_ptr; 通过heap heap = mem_heap_create_func(n, MEM_HEAP_DYNAMIC, file_name, line); 实现 详见
buf_pool_ptr = mem_zalloc(n_instances * sizeof *buf_pool_ptr);
for (i = 0; i < n_instances; i++) {
buf_pool_t* ptr = &buf_pool_ptr[i];
if (buf_pool_init_instance(ptr, size, i) != DB_SUCCESS) { //详见
/* Free all the instances created so far. */
buf_pool_free(i);
return(DB_ERROR);
}
}
buf_pool_set_sizes();
buf_LRU_old_ratio_update(100 * 3/ 8, FALSE);
btr_search_sys_create(buf_pool_get_curr_size() / sizeof(void*) / 64);
return(DB_SUCCESS);
}