Commit b00b32c7 authored by Vadim Tkachenko's avatar Vadim Tkachenko

sync with extensions rev18

parent eb591867
...@@ -3689,7 +3689,7 @@ btr_blob_free( ...@@ -3689,7 +3689,7 @@ btr_blob_free(
mtr_commit(mtr); mtr_commit(mtr);
buf_pool_mutex_enter(); //buf_pool_mutex_enter();
mutex_enter(&block->mutex); mutex_enter(&block->mutex);
/* Only free the block if it is still allocated to /* Only free the block if it is still allocated to
...@@ -3702,7 +3702,11 @@ btr_blob_free( ...@@ -3702,7 +3702,11 @@ btr_blob_free(
if (buf_LRU_free_block(&block->page, all, NULL) if (buf_LRU_free_block(&block->page, all, NULL)
!= BUF_LRU_FREED != BUF_LRU_FREED
&& all && block->page.zip.data) { && all && block->page.zip.data
/* Now, buf_LRU_free_block() may release mutex temporarily */
&& buf_block_get_state(block) == BUF_BLOCK_FILE_PAGE
&& buf_block_get_space(block) == space
&& buf_block_get_page_no(block) == page_no) {
/* Attempt to deallocate the uncompressed page /* Attempt to deallocate the uncompressed page
if the whole block cannot be deallocted. */ if the whole block cannot be deallocted. */
...@@ -3710,7 +3714,7 @@ btr_blob_free( ...@@ -3710,7 +3714,7 @@ btr_blob_free(
} }
} }
buf_pool_mutex_exit(); //buf_pool_mutex_exit();
mutex_exit(&block->mutex); mutex_exit(&block->mutex);
} }
......
...@@ -814,9 +814,11 @@ btr_search_guess_on_hash( ...@@ -814,9 +814,11 @@ btr_search_guess_on_hash(
ulint page_no = page_get_page_no(page); ulint page_no = page_get_page_no(page);
ulint space_id = page_get_space_id(page); ulint space_id = page_get_space_id(page);
buf_pool_mutex_enter(); //buf_pool_mutex_enter();
mutex_enter(&page_hash_mutex);
block = (buf_block_t*) buf_page_hash_get(space_id, page_no); block = (buf_block_t*) buf_page_hash_get(space_id, page_no);
buf_pool_mutex_exit(); //buf_pool_mutex_exit();
mutex_exit(&page_hash_mutex);
} }
if (UNIV_UNLIKELY(!block) if (UNIV_UNLIKELY(!block)
...@@ -1699,7 +1701,8 @@ btr_search_validate(void) ...@@ -1699,7 +1701,8 @@ btr_search_validate(void)
rec_offs_init(offsets_); rec_offs_init(offsets_);
rw_lock_x_lock(&btr_search_latch); rw_lock_x_lock(&btr_search_latch);
buf_pool_mutex_enter(); //buf_pool_mutex_enter();
mutex_enter(&page_hash_mutex);
cell_count = hash_get_n_cells(btr_search_sys->hash_index); cell_count = hash_get_n_cells(btr_search_sys->hash_index);
...@@ -1707,11 +1710,13 @@ btr_search_validate(void) ...@@ -1707,11 +1710,13 @@ btr_search_validate(void)
/* We release btr_search_latch every once in a while to /* We release btr_search_latch every once in a while to
give other queries a chance to run. */ give other queries a chance to run. */
if ((i != 0) && ((i % chunk_size) == 0)) { if ((i != 0) && ((i % chunk_size) == 0)) {
buf_pool_mutex_exit(); //buf_pool_mutex_exit();
mutex_exit(&page_hash_mutex);
rw_lock_x_unlock(&btr_search_latch); rw_lock_x_unlock(&btr_search_latch);
os_thread_yield(); os_thread_yield();
rw_lock_x_lock(&btr_search_latch); rw_lock_x_lock(&btr_search_latch);
buf_pool_mutex_enter(); //buf_pool_mutex_enter();
mutex_enter(&page_hash_mutex);
} }
node = hash_get_nth_cell(btr_search_sys->hash_index, i)->node; node = hash_get_nth_cell(btr_search_sys->hash_index, i)->node;
...@@ -1804,11 +1809,13 @@ btr_search_validate(void) ...@@ -1804,11 +1809,13 @@ btr_search_validate(void)
/* We release btr_search_latch every once in a while to /* We release btr_search_latch every once in a while to
give other queries a chance to run. */ give other queries a chance to run. */
if (i != 0) { if (i != 0) {
buf_pool_mutex_exit(); //buf_pool_mutex_exit();
mutex_exit(&page_hash_mutex);
rw_lock_x_unlock(&btr_search_latch); rw_lock_x_unlock(&btr_search_latch);
os_thread_yield(); os_thread_yield();
rw_lock_x_lock(&btr_search_latch); rw_lock_x_lock(&btr_search_latch);
buf_pool_mutex_enter(); //buf_pool_mutex_enter();
mutex_enter(&page_hash_mutex);
} }
if (!ha_validate(btr_search_sys->hash_index, i, end_index)) { if (!ha_validate(btr_search_sys->hash_index, i, end_index)) {
...@@ -1816,7 +1823,8 @@ btr_search_validate(void) ...@@ -1816,7 +1823,8 @@ btr_search_validate(void)
} }
} }
buf_pool_mutex_exit(); //buf_pool_mutex_exit();
mutex_exit(&page_hash_mutex);
rw_lock_x_unlock(&btr_search_latch); rw_lock_x_unlock(&btr_search_latch);
if (UNIV_LIKELY_NULL(heap)) { if (UNIV_LIKELY_NULL(heap)) {
mem_heap_free(heap); mem_heap_free(heap);
......
...@@ -115,7 +115,8 @@ buf_buddy_alloc_zip( ...@@ -115,7 +115,8 @@ buf_buddy_alloc_zip(
{ {
buf_page_t* bpage; buf_page_t* bpage;
ut_ad(buf_pool_mutex_own()); //ut_ad(buf_pool_mutex_own());
ut_ad(mutex_own(&zip_free_mutex));
ut_a(i < BUF_BUDDY_SIZES); ut_a(i < BUF_BUDDY_SIZES);
#if defined UNIV_DEBUG && !defined UNIV_DEBUG_VALGRIND #if defined UNIV_DEBUG && !defined UNIV_DEBUG_VALGRIND
...@@ -167,10 +168,12 @@ buf_buddy_block_free( ...@@ -167,10 +168,12 @@ buf_buddy_block_free(
buf_page_t* bpage; buf_page_t* bpage;
buf_block_t* block; buf_block_t* block;
ut_ad(buf_pool_mutex_own()); //ut_ad(buf_pool_mutex_own());
ut_ad(!mutex_own(&buf_pool_zip_mutex)); ut_ad(!mutex_own(&buf_pool_zip_mutex));
ut_a(!ut_align_offset(buf, UNIV_PAGE_SIZE)); ut_a(!ut_align_offset(buf, UNIV_PAGE_SIZE));
mutex_enter(&zip_hash_mutex);
HASH_SEARCH(hash, buf_pool->zip_hash, fold, buf_page_t*, bpage, HASH_SEARCH(hash, buf_pool->zip_hash, fold, buf_page_t*, bpage,
((buf_block_t*) bpage)->frame == buf); ((buf_block_t*) bpage)->frame == buf);
ut_a(bpage); ut_a(bpage);
...@@ -180,6 +183,8 @@ buf_buddy_block_free( ...@@ -180,6 +183,8 @@ buf_buddy_block_free(
ut_d(bpage->in_zip_hash = FALSE); ut_d(bpage->in_zip_hash = FALSE);
HASH_DELETE(buf_page_t, hash, buf_pool->zip_hash, fold, bpage); HASH_DELETE(buf_page_t, hash, buf_pool->zip_hash, fold, bpage);
mutex_exit(&zip_hash_mutex);
ut_d(memset(buf, 0, UNIV_PAGE_SIZE)); ut_d(memset(buf, 0, UNIV_PAGE_SIZE));
UNIV_MEM_INVALID(buf, UNIV_PAGE_SIZE); UNIV_MEM_INVALID(buf, UNIV_PAGE_SIZE);
...@@ -201,7 +206,7 @@ buf_buddy_block_register( ...@@ -201,7 +206,7 @@ buf_buddy_block_register(
buf_block_t* block) /* in: buffer frame to allocate */ buf_block_t* block) /* in: buffer frame to allocate */
{ {
const ulint fold = BUF_POOL_ZIP_FOLD(block); const ulint fold = BUF_POOL_ZIP_FOLD(block);
ut_ad(buf_pool_mutex_own()); //ut_ad(buf_pool_mutex_own());
ut_ad(!mutex_own(&buf_pool_zip_mutex)); ut_ad(!mutex_own(&buf_pool_zip_mutex));
buf_block_set_state(block, BUF_BLOCK_MEMORY); buf_block_set_state(block, BUF_BLOCK_MEMORY);
...@@ -212,7 +217,10 @@ buf_buddy_block_register( ...@@ -212,7 +217,10 @@ buf_buddy_block_register(
ut_ad(!block->page.in_page_hash); ut_ad(!block->page.in_page_hash);
ut_ad(!block->page.in_zip_hash); ut_ad(!block->page.in_zip_hash);
ut_d(block->page.in_zip_hash = TRUE); ut_d(block->page.in_zip_hash = TRUE);
mutex_enter(&zip_hash_mutex);
HASH_INSERT(buf_page_t, hash, buf_pool->zip_hash, fold, &block->page); HASH_INSERT(buf_page_t, hash, buf_pool->zip_hash, fold, &block->page);
mutex_exit(&zip_hash_mutex);
ut_d(buf_buddy_n_frames++); ut_d(buf_buddy_n_frames++);
} }
...@@ -273,17 +281,20 @@ buf_buddy_alloc_low( ...@@ -273,17 +281,20 @@ buf_buddy_alloc_low(
{ {
buf_block_t* block; buf_block_t* block;
ut_ad(buf_pool_mutex_own()); //ut_ad(buf_pool_mutex_own());
ut_ad(!mutex_own(&buf_pool_zip_mutex)); ut_ad(!mutex_own(&buf_pool_zip_mutex));
if (i < BUF_BUDDY_SIZES) { if (i < BUF_BUDDY_SIZES) {
/* Try to allocate from the buddy system. */ /* Try to allocate from the buddy system. */
mutex_enter(&zip_free_mutex);
block = buf_buddy_alloc_zip(i); block = buf_buddy_alloc_zip(i);
if (block) { if (block) {
goto func_exit; goto func_exit;
} }
mutex_exit(&zip_free_mutex);
} }
/* Try allocating from the buf_pool->free list. */ /* Try allocating from the buf_pool->free list. */
...@@ -300,18 +311,21 @@ buf_buddy_alloc_low( ...@@ -300,18 +311,21 @@ buf_buddy_alloc_low(
} }
/* Try replacing an uncompressed page in the buffer pool. */ /* Try replacing an uncompressed page in the buffer pool. */
buf_pool_mutex_exit(); //buf_pool_mutex_exit();
block = buf_LRU_get_free_block(0); block = buf_LRU_get_free_block(0);
*lru = TRUE; *lru = TRUE;
buf_pool_mutex_enter(); //buf_pool_mutex_enter();
alloc_big: alloc_big:
buf_buddy_block_register(block); buf_buddy_block_register(block);
mutex_enter(&zip_free_mutex);
block = buf_buddy_alloc_from(block->frame, i, BUF_BUDDY_SIZES); block = buf_buddy_alloc_from(block->frame, i, BUF_BUDDY_SIZES);
func_exit: func_exit:
buf_buddy_stat[i].used++; buf_buddy_stat[i].used++;
mutex_exit(&zip_free_mutex);
return(block); return(block);
} }
...@@ -327,7 +341,7 @@ buf_buddy_relocate_block( ...@@ -327,7 +341,7 @@ buf_buddy_relocate_block(
{ {
buf_page_t* b; buf_page_t* b;
ut_ad(buf_pool_mutex_own()); //ut_ad(buf_pool_mutex_own());
switch (buf_page_get_state(bpage)) { switch (buf_page_get_state(bpage)) {
case BUF_BLOCK_ZIP_FREE: case BUF_BLOCK_ZIP_FREE:
...@@ -345,9 +359,20 @@ buf_buddy_relocate_block( ...@@ -345,9 +359,20 @@ buf_buddy_relocate_block(
break; break;
} }
/* optimistic */
if (!buf_page_can_relocate(bpage)) {
return(FALSE);
}
mutex_enter(&LRU_list_mutex);
mutex_enter(&flush_list_mutex);
mutex_enter(&page_hash_mutex);
mutex_enter(&buf_pool_zip_mutex); mutex_enter(&buf_pool_zip_mutex);
if (!buf_page_can_relocate(bpage)) { if (!buf_page_can_relocate(bpage)) {
mutex_exit(&LRU_list_mutex);
mutex_exit(&flush_list_mutex);
mutex_exit(&page_hash_mutex);
mutex_exit(&buf_pool_zip_mutex); mutex_exit(&buf_pool_zip_mutex);
return(FALSE); return(FALSE);
} }
...@@ -355,6 +380,9 @@ buf_buddy_relocate_block( ...@@ -355,6 +380,9 @@ buf_buddy_relocate_block(
buf_relocate(bpage, dpage); buf_relocate(bpage, dpage);
ut_d(bpage->state = BUF_BLOCK_ZIP_FREE); ut_d(bpage->state = BUF_BLOCK_ZIP_FREE);
mutex_exit(&LRU_list_mutex);
mutex_exit(&page_hash_mutex);
/* relocate buf_pool->zip_clean */ /* relocate buf_pool->zip_clean */
b = UT_LIST_GET_PREV(list, dpage); b = UT_LIST_GET_PREV(list, dpage);
UT_LIST_REMOVE(list, buf_pool->zip_clean, dpage); UT_LIST_REMOVE(list, buf_pool->zip_clean, dpage);
...@@ -365,6 +393,7 @@ buf_buddy_relocate_block( ...@@ -365,6 +393,7 @@ buf_buddy_relocate_block(
UT_LIST_ADD_FIRST(list, buf_pool->zip_clean, dpage); UT_LIST_ADD_FIRST(list, buf_pool->zip_clean, dpage);
} }
mutex_exit(&flush_list_mutex);
mutex_exit(&buf_pool_zip_mutex); mutex_exit(&buf_pool_zip_mutex);
return(TRUE); return(TRUE);
} }
...@@ -384,7 +413,8 @@ buf_buddy_relocate( ...@@ -384,7 +413,8 @@ buf_buddy_relocate(
const ulint size = BUF_BUDDY_LOW << i; const ulint size = BUF_BUDDY_LOW << i;
ullint usec = ut_time_us(NULL); ullint usec = ut_time_us(NULL);
ut_ad(buf_pool_mutex_own()); //ut_ad(buf_pool_mutex_own());
ut_ad(mutex_own(&zip_free_mutex));
ut_ad(!mutex_own(&buf_pool_zip_mutex)); ut_ad(!mutex_own(&buf_pool_zip_mutex));
ut_ad(!ut_align_offset(src, size)); ut_ad(!ut_align_offset(src, size));
ut_ad(!ut_align_offset(dst, size)); ut_ad(!ut_align_offset(dst, size));
...@@ -403,9 +433,12 @@ buf_buddy_relocate( ...@@ -403,9 +433,12 @@ buf_buddy_relocate(
actually is a properly initialized buf_page_t object. */ actually is a properly initialized buf_page_t object. */
if (size >= PAGE_ZIP_MIN_SIZE) { if (size >= PAGE_ZIP_MIN_SIZE) {
mutex_exit(&zip_free_mutex);
/* This is a compressed page. */ /* This is a compressed page. */
mutex_t* mutex; mutex_t* mutex;
mutex_enter(&page_hash_mutex);
/* The src block may be split into smaller blocks, /* The src block may be split into smaller blocks,
some of which may be free. Thus, the some of which may be free. Thus, the
mach_read_from_4() calls below may attempt to read mach_read_from_4() calls below may attempt to read
...@@ -426,6 +459,8 @@ buf_buddy_relocate( ...@@ -426,6 +459,8 @@ buf_buddy_relocate(
added to buf_pool->page_hash yet. Obviously, added to buf_pool->page_hash yet. Obviously,
it cannot be relocated. */ it cannot be relocated. */
mutex_exit(&page_hash_mutex);
mutex_enter(&zip_free_mutex);
return(FALSE); return(FALSE);
} }
...@@ -435,6 +470,8 @@ buf_buddy_relocate( ...@@ -435,6 +470,8 @@ buf_buddy_relocate(
For the sake of simplicity, give up. */ For the sake of simplicity, give up. */
ut_ad(page_zip_get_size(&bpage->zip) < size); ut_ad(page_zip_get_size(&bpage->zip) < size);
mutex_exit(&page_hash_mutex);
mutex_enter(&zip_free_mutex);
return(FALSE); return(FALSE);
} }
...@@ -445,6 +482,7 @@ buf_buddy_relocate( ...@@ -445,6 +482,7 @@ buf_buddy_relocate(
mutex = buf_page_get_mutex(bpage); mutex = buf_page_get_mutex(bpage);
mutex_enter(mutex); mutex_enter(mutex);
mutex_exit(&page_hash_mutex);
if (buf_page_can_relocate(bpage)) { if (buf_page_can_relocate(bpage)) {
/* Relocate the compressed page. */ /* Relocate the compressed page. */
...@@ -461,17 +499,23 @@ buf_buddy_relocate( ...@@ -461,17 +499,23 @@ buf_buddy_relocate(
buddy_stat->relocated_usec buddy_stat->relocated_usec
+= ut_time_us(NULL) - usec; += ut_time_us(NULL) - usec;
} }
mutex_enter(&zip_free_mutex);
return(TRUE); return(TRUE);
} }
mutex_exit(mutex); mutex_exit(mutex);
mutex_enter(&zip_free_mutex);
} else if (i == buf_buddy_get_slot(sizeof(buf_page_t))) { } else if (i == buf_buddy_get_slot(sizeof(buf_page_t))) {
/* This must be a buf_page_t object. */ /* This must be a buf_page_t object. */
UNIV_MEM_ASSERT_RW(src, size); UNIV_MEM_ASSERT_RW(src, size);
mutex_exit(&zip_free_mutex);
if (buf_buddy_relocate_block(src, dst)) { if (buf_buddy_relocate_block(src, dst)) {
goto success; goto success;
} }
mutex_enter(&zip_free_mutex);
} }
return(FALSE); return(FALSE);
...@@ -490,7 +534,8 @@ buf_buddy_free_low( ...@@ -490,7 +534,8 @@ buf_buddy_free_low(
buf_page_t* bpage; buf_page_t* bpage;
buf_page_t* buddy; buf_page_t* buddy;
ut_ad(buf_pool_mutex_own()); //ut_ad(buf_pool_mutex_own());
ut_ad(mutex_own(&zip_free_mutex));
ut_ad(!mutex_own(&buf_pool_zip_mutex)); ut_ad(!mutex_own(&buf_pool_zip_mutex));
ut_ad(i <= BUF_BUDDY_SIZES); ut_ad(i <= BUF_BUDDY_SIZES);
ut_ad(buf_buddy_stat[i].used > 0); ut_ad(buf_buddy_stat[i].used > 0);
......
...@@ -236,6 +236,12 @@ UNIV_INTERN buf_pool_t* buf_pool = NULL; ...@@ -236,6 +236,12 @@ UNIV_INTERN buf_pool_t* buf_pool = NULL;
/* mutex protecting the buffer pool struct and control blocks, except the /* mutex protecting the buffer pool struct and control blocks, except the
read-write lock in them */ read-write lock in them */
UNIV_INTERN mutex_t buf_pool_mutex; UNIV_INTERN mutex_t buf_pool_mutex;
UNIV_INTERN mutex_t LRU_list_mutex;
UNIV_INTERN mutex_t flush_list_mutex;
UNIV_INTERN mutex_t page_hash_mutex;
UNIV_INTERN mutex_t free_list_mutex;
UNIV_INTERN mutex_t zip_free_mutex;
UNIV_INTERN mutex_t zip_hash_mutex;
/* mutex protecting the control blocks of compressed-only pages /* mutex protecting the control blocks of compressed-only pages
(of type buf_page_t, not buf_block_t) */ (of type buf_page_t, not buf_block_t) */
UNIV_INTERN mutex_t buf_pool_zip_mutex; UNIV_INTERN mutex_t buf_pool_zip_mutex;
...@@ -741,8 +747,10 @@ buf_chunk_init( ...@@ -741,8 +747,10 @@ buf_chunk_init(
memset(block->frame, '\0', UNIV_PAGE_SIZE); memset(block->frame, '\0', UNIV_PAGE_SIZE);
#endif #endif
/* Add the block to the free list */ /* Add the block to the free list */
mutex_enter(&free_list_mutex);
UT_LIST_ADD_LAST(list, buf_pool->free, (&block->page)); UT_LIST_ADD_LAST(list, buf_pool->free, (&block->page));
ut_d(block->page.in_free_list = TRUE); ut_d(block->page.in_free_list = TRUE);
mutex_exit(&free_list_mutex);
block++; block++;
frame += UNIV_PAGE_SIZE; frame += UNIV_PAGE_SIZE;
...@@ -768,7 +776,7 @@ buf_chunk_contains_zip( ...@@ -768,7 +776,7 @@ buf_chunk_contains_zip(
ulint i; ulint i;
ut_ad(buf_pool); ut_ad(buf_pool);
ut_ad(buf_pool_mutex_own()); //ut_ad(buf_pool_mutex_own());
block = chunk->blocks; block = chunk->blocks;
...@@ -822,7 +830,7 @@ buf_chunk_not_freed( ...@@ -822,7 +830,7 @@ buf_chunk_not_freed(
ulint i; ulint i;
ut_ad(buf_pool); ut_ad(buf_pool);
ut_ad(buf_pool_mutex_own()); //ut_ad(buf_pool_mutex_own()); /*optimistic...*/
block = chunk->blocks; block = chunk->blocks;
...@@ -855,7 +863,7 @@ buf_chunk_all_free( ...@@ -855,7 +863,7 @@ buf_chunk_all_free(
ulint i; ulint i;
ut_ad(buf_pool); ut_ad(buf_pool);
ut_ad(buf_pool_mutex_own()); ut_ad(buf_pool_mutex_own()); /* but we need all mutex here */
block = chunk->blocks; block = chunk->blocks;
...@@ -881,7 +889,7 @@ buf_chunk_free( ...@@ -881,7 +889,7 @@ buf_chunk_free(
buf_block_t* block; buf_block_t* block;
const buf_block_t* block_end; const buf_block_t* block_end;
ut_ad(buf_pool_mutex_own()); ut_ad(buf_pool_mutex_own()); /* but we need all mutex here */
block_end = chunk->blocks + chunk->size; block_end = chunk->blocks + chunk->size;
...@@ -893,8 +901,10 @@ buf_chunk_free( ...@@ -893,8 +901,10 @@ buf_chunk_free(
ut_ad(!block->in_unzip_LRU_list); ut_ad(!block->in_unzip_LRU_list);
ut_ad(!block->page.in_flush_list); ut_ad(!block->page.in_flush_list);
/* Remove the block from the free list. */ /* Remove the block from the free list. */
mutex_enter(&free_list_mutex);
ut_ad(block->page.in_free_list); ut_ad(block->page.in_free_list);
UT_LIST_REMOVE(list, buf_pool->free, (&block->page)); UT_LIST_REMOVE(list, buf_pool->free, (&block->page));
mutex_exit(&free_list_mutex);
/* Free the latches. */ /* Free the latches. */
mutex_free(&block->mutex); mutex_free(&block->mutex);
...@@ -925,8 +935,18 @@ buf_pool_init(void) ...@@ -925,8 +935,18 @@ buf_pool_init(void)
/* 1. Initialize general fields /* 1. Initialize general fields
------------------------------- */ ------------------------------- */
mutex_create(&buf_pool_mutex, SYNC_BUF_POOL); mutex_create(&buf_pool_mutex, SYNC_BUF_POOL);
mutex_create(&LRU_list_mutex, SYNC_NO_ORDER_CHECK);
mutex_create(&flush_list_mutex, SYNC_NO_ORDER_CHECK);
mutex_create(&page_hash_mutex, SYNC_NO_ORDER_CHECK);
mutex_create(&free_list_mutex, SYNC_NO_ORDER_CHECK);
mutex_create(&zip_free_mutex, SYNC_NO_ORDER_CHECK);
mutex_create(&zip_hash_mutex, SYNC_NO_ORDER_CHECK);
mutex_create(&buf_pool_zip_mutex, SYNC_BUF_BLOCK); mutex_create(&buf_pool_zip_mutex, SYNC_BUF_BLOCK);
mutex_enter(&LRU_list_mutex);
mutex_enter(&flush_list_mutex);
mutex_enter(&page_hash_mutex);
buf_pool_mutex_enter(); buf_pool_mutex_enter();
buf_pool->n_chunks = 1; buf_pool->n_chunks = 1;
...@@ -963,6 +983,9 @@ buf_pool_init(void) ...@@ -963,6 +983,9 @@ buf_pool_init(void)
--------------------------- */ --------------------------- */
/* All fields are initialized by mem_zalloc(). */ /* All fields are initialized by mem_zalloc(). */
mutex_exit(&LRU_list_mutex);
mutex_exit(&flush_list_mutex);
mutex_exit(&page_hash_mutex);
buf_pool_mutex_exit(); buf_pool_mutex_exit();
btr_search_sys_create(buf_pool->curr_size btr_search_sys_create(buf_pool->curr_size
...@@ -1013,7 +1036,9 @@ buf_relocate( ...@@ -1013,7 +1036,9 @@ buf_relocate(
buf_page_t* b; buf_page_t* b;
ulint fold; ulint fold;
ut_ad(buf_pool_mutex_own()); //ut_ad(buf_pool_mutex_own());
ut_ad(mutex_own(&LRU_list_mutex));
ut_ad(mutex_own(&page_hash_mutex));
ut_ad(mutex_own(buf_page_get_mutex(bpage))); ut_ad(mutex_own(buf_page_get_mutex(bpage)));
ut_a(buf_page_get_io_fix(bpage) == BUF_IO_NONE); ut_a(buf_page_get_io_fix(bpage) == BUF_IO_NONE);
ut_a(bpage->buf_fix_count == 0); ut_a(bpage->buf_fix_count == 0);
...@@ -1038,7 +1063,7 @@ buf_relocate( ...@@ -1038,7 +1063,7 @@ buf_relocate(
memcpy(dpage, bpage, sizeof *dpage); memcpy(dpage, bpage, sizeof *dpage);
ut_d(bpage->in_LRU_list = FALSE); bpage->in_LRU_list = FALSE;
ut_d(bpage->in_page_hash = FALSE); ut_d(bpage->in_page_hash = FALSE);
/* relocate buf_pool->LRU */ /* relocate buf_pool->LRU */
...@@ -1094,7 +1119,8 @@ buf_pool_shrink( ...@@ -1094,7 +1119,8 @@ buf_pool_shrink(
try_again: try_again:
btr_search_disable(); /* Empty the adaptive hash index again */ btr_search_disable(); /* Empty the adaptive hash index again */
buf_pool_mutex_enter(); //buf_pool_mutex_enter();
mutex_enter(&LRU_list_mutex);
shrink_again: shrink_again:
if (buf_pool->n_chunks <= 1) { if (buf_pool->n_chunks <= 1) {
...@@ -1173,7 +1199,8 @@ buf_pool_shrink( ...@@ -1173,7 +1199,8 @@ buf_pool_shrink(
mutex_exit(&block->mutex); mutex_exit(&block->mutex);
} }
buf_pool_mutex_exit(); //buf_pool_mutex_exit();
mutex_exit(&LRU_list_mutex);
/* Request for a flush of the chunk if it helps. /* Request for a flush of the chunk if it helps.
Do not flush if there are non-free blocks, since Do not flush if there are non-free blocks, since
...@@ -1222,7 +1249,8 @@ buf_pool_shrink( ...@@ -1222,7 +1249,8 @@ buf_pool_shrink(
func_done: func_done:
srv_buf_pool_old_size = srv_buf_pool_size; srv_buf_pool_old_size = srv_buf_pool_size;
func_exit: func_exit:
buf_pool_mutex_exit(); //buf_pool_mutex_exit();
mutex_exit(&LRU_list_mutex);
btr_search_enable(); btr_search_enable();
} }
...@@ -1240,7 +1268,11 @@ buf_pool_page_hash_rebuild(void) ...@@ -1240,7 +1268,11 @@ buf_pool_page_hash_rebuild(void)
hash_table_t* zip_hash; hash_table_t* zip_hash;
buf_page_t* b; buf_page_t* b;
buf_pool_mutex_enter(); //buf_pool_mutex_enter();
mutex_enter(&LRU_list_mutex);
mutex_enter(&flush_list_mutex);
mutex_enter(&page_hash_mutex);
/* Free, create, and populate the hash table. */ /* Free, create, and populate the hash table. */
hash_table_free(buf_pool->page_hash); hash_table_free(buf_pool->page_hash);
...@@ -1320,7 +1352,10 @@ buf_pool_page_hash_rebuild(void) ...@@ -1320,7 +1352,10 @@ buf_pool_page_hash_rebuild(void)
} }
} }
buf_pool_mutex_exit(); //buf_pool_mutex_exit();
mutex_exit(&LRU_list_mutex);
mutex_exit(&flush_list_mutex);
mutex_exit(&page_hash_mutex);
} }
/************************************************************************ /************************************************************************
...@@ -1330,17 +1365,20 @@ void ...@@ -1330,17 +1365,20 @@ void
buf_pool_resize(void) buf_pool_resize(void)
/*=================*/ /*=================*/
{ {
buf_pool_mutex_enter(); //buf_pool_mutex_enter();
mutex_enter(&LRU_list_mutex);
if (srv_buf_pool_old_size == srv_buf_pool_size) { if (srv_buf_pool_old_size == srv_buf_pool_size) {
buf_pool_mutex_exit(); //buf_pool_mutex_exit();
mutex_exit(&LRU_list_mutex);
return; return;
} }
if (srv_buf_pool_curr_size + 1048576 > srv_buf_pool_size) { if (srv_buf_pool_curr_size + 1048576 > srv_buf_pool_size) {
buf_pool_mutex_exit(); //buf_pool_mutex_exit();
mutex_exit(&LRU_list_mutex);
/* Disable adaptive hash indexes and empty the index /* Disable adaptive hash indexes and empty the index
in order to free up memory in the buffer pool chunks. */ in order to free up memory in the buffer pool chunks. */
...@@ -1374,7 +1412,8 @@ buf_pool_resize(void) ...@@ -1374,7 +1412,8 @@ buf_pool_resize(void)
} }
srv_buf_pool_old_size = srv_buf_pool_size; srv_buf_pool_old_size = srv_buf_pool_size;
buf_pool_mutex_exit(); //buf_pool_mutex_exit();
mutex_exit(&LRU_list_mutex);
} }
buf_pool_page_hash_rebuild(); buf_pool_page_hash_rebuild();
...@@ -1396,12 +1435,14 @@ buf_block_make_young( ...@@ -1396,12 +1435,14 @@ buf_block_make_young(
if (buf_page_peek_if_too_old(bpage)) { if (buf_page_peek_if_too_old(bpage)) {
buf_pool_mutex_enter(); //buf_pool_mutex_enter();
mutex_enter(&LRU_list_mutex);
/* There has been freeing activity in the LRU list: /* There has been freeing activity in the LRU list:
best to move to the head of the LRU list */ best to move to the head of the LRU list */
buf_LRU_make_block_young(bpage); buf_LRU_make_block_young(bpage);
buf_pool_mutex_exit(); //buf_pool_mutex_exit();
mutex_exit(&LRU_list_mutex);
} }
} }
...@@ -1415,13 +1456,15 @@ buf_page_make_young( ...@@ -1415,13 +1456,15 @@ buf_page_make_young(
/*================*/ /*================*/
buf_page_t* bpage) /* in: buffer block of a file page */ buf_page_t* bpage) /* in: buffer block of a file page */
{ {
buf_pool_mutex_enter(); //buf_pool_mutex_enter();
mutex_enter(&LRU_list_mutex);
ut_a(buf_page_in_file(bpage)); ut_a(buf_page_in_file(bpage));
buf_LRU_make_block_young(bpage); buf_LRU_make_block_young(bpage);
buf_pool_mutex_exit(); //buf_pool_mutex_exit();
mutex_exit(&LRU_list_mutex);
} }
/************************************************************************ /************************************************************************
...@@ -1436,7 +1479,8 @@ buf_reset_check_index_page_at_flush( ...@@ -1436,7 +1479,8 @@ buf_reset_check_index_page_at_flush(
{ {
buf_block_t* block; buf_block_t* block;
buf_pool_mutex_enter(); //buf_pool_mutex_enter();
mutex_enter(&page_hash_mutex);
block = (buf_block_t*) buf_page_hash_get(space, offset); block = (buf_block_t*) buf_page_hash_get(space, offset);
...@@ -1444,7 +1488,8 @@ buf_reset_check_index_page_at_flush( ...@@ -1444,7 +1488,8 @@ buf_reset_check_index_page_at_flush(
block->check_index_page_at_flush = FALSE; block->check_index_page_at_flush = FALSE;
} }
buf_pool_mutex_exit(); //buf_pool_mutex_exit();
mutex_exit(&page_hash_mutex);
} }
/************************************************************************ /************************************************************************
...@@ -1463,7 +1508,8 @@ buf_page_peek_if_search_hashed( ...@@ -1463,7 +1508,8 @@ buf_page_peek_if_search_hashed(
buf_block_t* block; buf_block_t* block;
ibool is_hashed; ibool is_hashed;
buf_pool_mutex_enter(); //buf_pool_mutex_enter();
mutex_enter(&page_hash_mutex);
block = (buf_block_t*) buf_page_hash_get(space, offset); block = (buf_block_t*) buf_page_hash_get(space, offset);
...@@ -1473,7 +1519,8 @@ buf_page_peek_if_search_hashed( ...@@ -1473,7 +1519,8 @@ buf_page_peek_if_search_hashed(
is_hashed = block->is_hashed; is_hashed = block->is_hashed;
} }
buf_pool_mutex_exit(); //buf_pool_mutex_exit();
mutex_exit(&page_hash_mutex);
return(is_hashed); return(is_hashed);
} }
...@@ -1495,7 +1542,8 @@ buf_page_set_file_page_was_freed( ...@@ -1495,7 +1542,8 @@ buf_page_set_file_page_was_freed(
{ {
buf_page_t* bpage; buf_page_t* bpage;
buf_pool_mutex_enter(); //buf_pool_mutex_enter();
mutex_enter(&page_hash_mutex);
bpage = buf_page_hash_get(space, offset); bpage = buf_page_hash_get(space, offset);
...@@ -1503,7 +1551,8 @@ buf_page_set_file_page_was_freed( ...@@ -1503,7 +1551,8 @@ buf_page_set_file_page_was_freed(
bpage->file_page_was_freed = TRUE; bpage->file_page_was_freed = TRUE;
} }
buf_pool_mutex_exit(); //buf_pool_mutex_exit();
mutex_exit(&page_hash_mutex);
return(bpage); return(bpage);
} }
...@@ -1524,7 +1573,8 @@ buf_page_reset_file_page_was_freed( ...@@ -1524,7 +1573,8 @@ buf_page_reset_file_page_was_freed(
{ {
buf_page_t* bpage; buf_page_t* bpage;
buf_pool_mutex_enter(); //buf_pool_mutex_enter();
mutex_enter(&page_hash_mutex);
bpage = buf_page_hash_get(space, offset); bpage = buf_page_hash_get(space, offset);
...@@ -1532,7 +1582,8 @@ buf_page_reset_file_page_was_freed( ...@@ -1532,7 +1582,8 @@ buf_page_reset_file_page_was_freed(
bpage->file_page_was_freed = FALSE; bpage->file_page_was_freed = FALSE;
} }
buf_pool_mutex_exit(); //buf_pool_mutex_exit();
mutex_exit(&page_hash_mutex);
return(bpage); return(bpage);
} }
...@@ -1565,7 +1616,8 @@ buf_page_get_zip( ...@@ -1565,7 +1616,8 @@ buf_page_get_zip(
buf_pool->n_page_gets++; buf_pool->n_page_gets++;
for (;;) { for (;;) {
buf_pool_mutex_enter(); //buf_pool_mutex_enter();
mutex_enter(&page_hash_mutex);
lookup: lookup:
bpage = buf_page_hash_get(space, offset); bpage = buf_page_hash_get(space, offset);
if (bpage) { if (bpage) {
...@@ -1574,7 +1626,8 @@ buf_page_get_zip( ...@@ -1574,7 +1626,8 @@ buf_page_get_zip(
/* Page not in buf_pool: needs to be read from file */ /* Page not in buf_pool: needs to be read from file */
buf_pool_mutex_exit(); //buf_pool_mutex_exit();
mutex_exit(&page_hash_mutex);
buf_read_page(space, zip_size, offset); buf_read_page(space, zip_size, offset);
...@@ -1585,13 +1638,16 @@ buf_page_get_zip( ...@@ -1585,13 +1638,16 @@ buf_page_get_zip(
if (UNIV_UNLIKELY(!bpage->zip.data)) { if (UNIV_UNLIKELY(!bpage->zip.data)) {
/* There is no compressed page. */ /* There is no compressed page. */
buf_pool_mutex_exit(); //buf_pool_mutex_exit();
mutex_exit(&page_hash_mutex);
return(NULL); return(NULL);
} }
block_mutex = buf_page_get_mutex(bpage); block_mutex = buf_page_get_mutex(bpage);
mutex_enter(block_mutex); mutex_enter(block_mutex);
mutex_exit(&page_hash_mutex);
switch (buf_page_get_state(bpage)) { switch (buf_page_get_state(bpage)) {
case BUF_BLOCK_NOT_USED: case BUF_BLOCK_NOT_USED:
case BUF_BLOCK_READY_FOR_USE: case BUF_BLOCK_READY_FOR_USE:
...@@ -1620,7 +1676,7 @@ buf_page_get_zip( ...@@ -1620,7 +1676,7 @@ buf_page_get_zip(
must_read = buf_page_get_io_fix(bpage) == BUF_IO_READ; must_read = buf_page_get_io_fix(bpage) == BUF_IO_READ;
buf_pool_mutex_exit(); //buf_pool_mutex_exit();
buf_page_set_accessed(bpage, TRUE); buf_page_set_accessed(bpage, TRUE);
...@@ -1764,7 +1820,7 @@ buf_block_is_uncompressed( ...@@ -1764,7 +1820,7 @@ buf_block_is_uncompressed(
const buf_chunk_t* chunk = buf_pool->chunks; const buf_chunk_t* chunk = buf_pool->chunks;
const buf_chunk_t* const echunk = chunk + buf_pool->n_chunks; const buf_chunk_t* const echunk = chunk + buf_pool->n_chunks;
ut_ad(buf_pool_mutex_own()); //ut_ad(buf_pool_mutex_own());
if (UNIV_UNLIKELY((((ulint) block) % sizeof *block) != 0)) { if (UNIV_UNLIKELY((((ulint) block) % sizeof *block) != 0)) {
/* The pointer should be aligned. */ /* The pointer should be aligned. */
...@@ -1822,9 +1878,11 @@ buf_page_get_gen( ...@@ -1822,9 +1878,11 @@ buf_page_get_gen(
buf_pool->n_page_gets++; buf_pool->n_page_gets++;
loop: loop:
block = guess; block = guess;
buf_pool_mutex_enter(); //buf_pool_mutex_enter();
if (block) { if (block) {
mutex_enter(&block->mutex);
/* If the guess is a compressed page descriptor that /* If the guess is a compressed page descriptor that
has been allocated by buf_buddy_alloc(), it may have has been allocated by buf_buddy_alloc(), it may have
been invalidated by buf_buddy_relocate(). In that been invalidated by buf_buddy_relocate(). In that
...@@ -1838,6 +1896,8 @@ buf_page_get_gen( ...@@ -1838,6 +1896,8 @@ buf_page_get_gen(
|| space != block->page.space || space != block->page.space
|| buf_block_get_state(block) != BUF_BLOCK_FILE_PAGE) { || buf_block_get_state(block) != BUF_BLOCK_FILE_PAGE) {
mutex_exit(&block->mutex);
block = guess = NULL; block = guess = NULL;
} else { } else {
ut_ad(!block->page.in_zip_hash); ut_ad(!block->page.in_zip_hash);
...@@ -1846,14 +1906,19 @@ buf_page_get_gen( ...@@ -1846,14 +1906,19 @@ buf_page_get_gen(
} }
if (block == NULL) { if (block == NULL) {
mutex_enter(&page_hash_mutex);
block = (buf_block_t*) buf_page_hash_get(space, offset); block = (buf_block_t*) buf_page_hash_get(space, offset);
if (block) {
mutex_enter(&block->mutex);
}
mutex_exit(&page_hash_mutex);
} }
loop2: loop2:
if (block == NULL) { if (block == NULL) {
/* Page not in buf_pool: needs to be read from file */ /* Page not in buf_pool: needs to be read from file */
buf_pool_mutex_exit(); //buf_pool_mutex_exit();
if (mode == BUF_GET_IF_IN_POOL) { if (mode == BUF_GET_IF_IN_POOL) {
...@@ -1874,7 +1939,8 @@ buf_page_get_gen( ...@@ -1874,7 +1939,8 @@ buf_page_get_gen(
if (must_read && mode == BUF_GET_IF_IN_POOL) { if (must_read && mode == BUF_GET_IF_IN_POOL) {
/* The page is only being read to buffer */ /* The page is only being read to buffer */
buf_pool_mutex_exit(); //buf_pool_mutex_exit();
mutex_exit(&block->mutex);
return(NULL); return(NULL);
} }
...@@ -1898,19 +1964,24 @@ buf_page_get_gen( ...@@ -1898,19 +1964,24 @@ buf_page_get_gen(
wait_until_unfixed: wait_until_unfixed:
/* The block is buffer-fixed or I/O-fixed. /* The block is buffer-fixed or I/O-fixed.
Try again later. */ Try again later. */
buf_pool_mutex_exit(); //buf_pool_mutex_exit();
mutex_exit(&block->mutex);
os_thread_sleep(WAIT_FOR_READ); os_thread_sleep(WAIT_FOR_READ);
goto loop; goto loop;
} }
/* Allocate an uncompressed page. */ /* Allocate an uncompressed page. */
buf_pool_mutex_exit(); //buf_pool_mutex_exit();
mutex_exit(&block->mutex);
block = buf_LRU_get_free_block(0); block = buf_LRU_get_free_block(0);
ut_a(block); ut_a(block);
buf_pool_mutex_enter(); //buf_pool_mutex_enter();
mutex_enter(&flush_list_mutex);
mutex_enter(&LRU_list_mutex);
mutex_enter(&page_hash_mutex);
mutex_enter(&block->mutex); mutex_enter(&block->mutex);
{ {
...@@ -1926,6 +1997,11 @@ buf_page_get_gen( ...@@ -1926,6 +1997,11 @@ buf_page_get_gen(
mutex_exit(&block->mutex); mutex_exit(&block->mutex);
block = (buf_block_t*) hash_bpage; block = (buf_block_t*) hash_bpage;
mutex_enter(&block->mutex);
mutex_exit(&page_hash_mutex);
mutex_exit(&LRU_list_mutex);
mutex_exit(&flush_list_mutex);
goto loop2; goto loop2;
} }
} }
...@@ -1940,8 +2016,11 @@ buf_page_get_gen( ...@@ -1940,8 +2016,11 @@ buf_page_get_gen(
This should be extremely unlikely. */ This should be extremely unlikely. */
buf_LRU_block_free_non_file_page(block); buf_LRU_block_free_non_file_page(block);
mutex_exit(&block->mutex); //mutex_exit(&block->mutex);
mutex_exit(&page_hash_mutex);
mutex_exit(&LRU_list_mutex);
mutex_exit(&flush_list_mutex);
goto wait_until_unfixed; goto wait_until_unfixed;
} }
...@@ -1951,6 +2030,9 @@ buf_page_get_gen( ...@@ -1951,6 +2030,9 @@ buf_page_get_gen(
mutex_enter(&buf_pool_zip_mutex); mutex_enter(&buf_pool_zip_mutex);
buf_relocate(bpage, &block->page); buf_relocate(bpage, &block->page);
mutex_exit(&page_hash_mutex);
buf_block_init_low(block); buf_block_init_low(block);
block->lock_hash_val = lock_rec_hash(space, offset); block->lock_hash_val = lock_rec_hash(space, offset);
...@@ -1982,6 +2064,8 @@ buf_page_get_gen( ...@@ -1982,6 +2064,8 @@ buf_page_get_gen(
} }
} }
mutex_exit(&flush_list_mutex);
/* Buffer-fix, I/O-fix, and X-latch the block /* Buffer-fix, I/O-fix, and X-latch the block
for the duration of the decompression. for the duration of the decompression.
Also add the block to the unzip_LRU list. */ Also add the block to the unzip_LRU list. */
...@@ -1990,16 +2074,22 @@ buf_page_get_gen( ...@@ -1990,16 +2074,22 @@ buf_page_get_gen(
/* Insert at the front of unzip_LRU list */ /* Insert at the front of unzip_LRU list */
buf_unzip_LRU_add_block(block, FALSE); buf_unzip_LRU_add_block(block, FALSE);
mutex_exit(&LRU_list_mutex);
block->page.buf_fix_count = 1; block->page.buf_fix_count = 1;
buf_block_set_io_fix(block, BUF_IO_READ); buf_block_set_io_fix(block, BUF_IO_READ);
mutex_enter(&buf_pool_mutex);
buf_pool->n_pend_unzip++; buf_pool->n_pend_unzip++;
mutex_exit(&buf_pool_mutex);
rw_lock_x_lock(&block->lock); rw_lock_x_lock(&block->lock);
mutex_exit(&block->mutex); mutex_exit(&block->mutex);
mutex_exit(&buf_pool_zip_mutex); mutex_exit(&buf_pool_zip_mutex);
buf_buddy_free(bpage, sizeof *bpage); buf_buddy_free(bpage, sizeof *bpage);
buf_pool_mutex_exit(); //buf_pool_mutex_exit();
/* Decompress the page and apply buffered operations /* Decompress the page and apply buffered operations
while not holding buf_pool_mutex or block->mutex. */ while not holding buf_pool_mutex or block->mutex. */
...@@ -2011,17 +2101,20 @@ buf_page_get_gen( ...@@ -2011,17 +2101,20 @@ buf_page_get_gen(
} }
/* Unfix and unlatch the block. */ /* Unfix and unlatch the block. */
buf_pool_mutex_enter(); //buf_pool_mutex_enter();
mutex_enter(&block->mutex); mutex_enter(&block->mutex);
mutex_enter(&buf_pool_mutex);
buf_pool->n_pend_unzip--; buf_pool->n_pend_unzip--;
mutex_exit(&buf_pool_mutex);
block->page.buf_fix_count--; block->page.buf_fix_count--;
buf_block_set_io_fix(block, BUF_IO_NONE); buf_block_set_io_fix(block, BUF_IO_NONE);
mutex_exit(&block->mutex); //mutex_exit(&block->mutex);
rw_lock_x_unlock(&block->lock); rw_lock_x_unlock(&block->lock);
if (UNIV_UNLIKELY(!success)) { if (UNIV_UNLIKELY(!success)) {
buf_pool_mutex_exit(); //buf_pool_mutex_exit();
mutex_exit(&block->mutex);
return(NULL); return(NULL);
} }
...@@ -2038,11 +2131,11 @@ buf_page_get_gen( ...@@ -2038,11 +2131,11 @@ buf_page_get_gen(
ut_ad(buf_block_get_state(block) == BUF_BLOCK_FILE_PAGE); ut_ad(buf_block_get_state(block) == BUF_BLOCK_FILE_PAGE);
mutex_enter(&block->mutex); //mutex_enter(&block->mutex);
UNIV_MEM_ASSERT_RW(&block->page, sizeof block->page); UNIV_MEM_ASSERT_RW(&block->page, sizeof block->page);
buf_block_buf_fix_inc(block, file, line); buf_block_buf_fix_inc(block, file, line);
buf_pool_mutex_exit(); //buf_pool_mutex_exit();
/* Check if this is the first access to the page */ /* Check if this is the first access to the page */
...@@ -2352,16 +2445,19 @@ buf_page_try_get_func( ...@@ -2352,16 +2445,19 @@ buf_page_try_get_func(
ibool success; ibool success;
ulint fix_type; ulint fix_type;
buf_pool_mutex_enter(); //buf_pool_mutex_enter();
mutex_enter(&page_hash_mutex);
block = buf_block_hash_get(space_id, page_no); block = buf_block_hash_get(space_id, page_no);
if (!block) { if (!block) {
buf_pool_mutex_exit(); //buf_pool_mutex_exit();
mutex_exit(&page_hash_mutex);
return(NULL); return(NULL);
} }
mutex_enter(&block->mutex); mutex_enter(&block->mutex);
buf_pool_mutex_exit(); //buf_pool_mutex_exit();
mutex_exit(&page_hash_mutex);
#if defined UNIV_DEBUG || defined UNIV_BUF_DEBUG #if defined UNIV_DEBUG || defined UNIV_BUF_DEBUG
ut_a(buf_block_get_state(block) == BUF_BLOCK_FILE_PAGE); ut_a(buf_block_get_state(block) == BUF_BLOCK_FILE_PAGE);
...@@ -2476,7 +2572,8 @@ buf_page_init( ...@@ -2476,7 +2572,8 @@ buf_page_init(
{ {
buf_page_t* hash_page; buf_page_t* hash_page;
ut_ad(buf_pool_mutex_own()); //ut_ad(buf_pool_mutex_own());
ut_ad(mutex_own(&page_hash_mutex));
ut_ad(mutex_own(&(block->mutex))); ut_ad(mutex_own(&(block->mutex)));
ut_a(buf_block_get_state(block) != BUF_BLOCK_FILE_PAGE); ut_a(buf_block_get_state(block) != BUF_BLOCK_FILE_PAGE);
...@@ -2509,7 +2606,8 @@ buf_page_init( ...@@ -2509,7 +2606,8 @@ buf_page_init(
(const void*) hash_page, (const void*) block); (const void*) hash_page, (const void*) block);
#if defined UNIV_DEBUG || defined UNIV_BUF_DEBUG #if defined UNIV_DEBUG || defined UNIV_BUF_DEBUG
mutex_exit(&block->mutex); mutex_exit(&block->mutex);
buf_pool_mutex_exit(); //buf_pool_mutex_exit();
mutex_exit(&page_hash_mutex);
buf_print(); buf_print();
buf_LRU_print(); buf_LRU_print();
buf_validate(); buf_validate();
...@@ -2587,7 +2685,9 @@ buf_page_init_for_read( ...@@ -2587,7 +2685,9 @@ buf_page_init_for_read(
ut_ad(block); ut_ad(block);
} }
buf_pool_mutex_enter(); //buf_pool_mutex_enter();
mutex_enter(&LRU_list_mutex);
mutex_enter(&page_hash_mutex);
if (buf_page_hash_get(space, offset)) { if (buf_page_hash_get(space, offset)) {
/* The page is already in the buffer pool. */ /* The page is already in the buffer pool. */
...@@ -2599,7 +2699,9 @@ buf_page_init_for_read( ...@@ -2599,7 +2699,9 @@ buf_page_init_for_read(
} }
err_exit2: err_exit2:
buf_pool_mutex_exit(); //buf_pool_mutex_exit();
mutex_exit(&LRU_list_mutex);
mutex_exit(&page_hash_mutex);
if (mode == BUF_READ_IBUF_PAGES_ONLY) { if (mode == BUF_READ_IBUF_PAGES_ONLY) {
...@@ -2623,6 +2725,8 @@ buf_page_init_for_read( ...@@ -2623,6 +2725,8 @@ buf_page_init_for_read(
mutex_enter(&block->mutex); mutex_enter(&block->mutex);
buf_page_init(space, offset, block); buf_page_init(space, offset, block);
mutex_exit(&page_hash_mutex);
/* The block must be put to the LRU list, to the old blocks */ /* The block must be put to the LRU list, to the old blocks */
buf_LRU_add_block(bpage, TRUE/* to old blocks */); buf_LRU_add_block(bpage, TRUE/* to old blocks */);
...@@ -2649,9 +2753,9 @@ buf_page_init_for_read( ...@@ -2649,9 +2753,9 @@ buf_page_init_for_read(
operation until after the block descriptor has operation until after the block descriptor has
been added to buf_pool->LRU and been added to buf_pool->LRU and
buf_pool->page_hash. */ buf_pool->page_hash. */
mutex_exit(&block->mutex); //mutex_exit(&block->mutex); /*##may be able to removed?##*/
data = buf_buddy_alloc(zip_size, &lru); data = buf_buddy_alloc(zip_size, &lru);
mutex_enter(&block->mutex); //mutex_enter(&block->mutex); /*##may be able to removed?##*/
block->page.zip.data = data; block->page.zip.data = data;
/* To maintain the invariant /* To maintain the invariant
...@@ -2663,6 +2767,7 @@ buf_page_init_for_read( ...@@ -2663,6 +2767,7 @@ buf_page_init_for_read(
buf_unzip_LRU_add_block(block, TRUE); buf_unzip_LRU_add_block(block, TRUE);
} }
mutex_exit(&LRU_list_mutex);
mutex_exit(&block->mutex); mutex_exit(&block->mutex);
} else { } else {
/* Defer buf_buddy_alloc() until after the block has /* Defer buf_buddy_alloc() until after the block has
...@@ -2680,14 +2785,16 @@ buf_page_init_for_read( ...@@ -2680,14 +2785,16 @@ buf_page_init_for_read(
/* If buf_buddy_alloc() allocated storage from the LRU list, /* If buf_buddy_alloc() allocated storage from the LRU list,
it released and reacquired buf_pool_mutex. Thus, we must it released and reacquired buf_pool_mutex. Thus, we must
check the page_hash again, as it may have been modified. */ check the page_hash again, as it may have been modified. */
if (UNIV_UNLIKELY(lru) /* !!! page_hash_mutex is not released yet
&& UNIV_LIKELY_NULL(buf_page_hash_get(space, offset))) { So always buf_page_hash_get(space, offset) == 0 !!!*/
//if (UNIV_UNLIKELY(lru)
// && UNIV_LIKELY_NULL(buf_page_hash_get(space, offset))) {
/* The block was added by some other thread. */ // /* The block was added by some other thread. */
buf_buddy_free(bpage, sizeof *bpage); // buf_buddy_free(bpage, sizeof *bpage);
buf_buddy_free(data, zip_size); // buf_buddy_free(data, zip_size);
goto err_exit2; // goto err_exit2;
} //}
page_zip_des_init(&bpage->zip); page_zip_des_init(&bpage->zip);
page_zip_set_size(&bpage->zip, zip_size); page_zip_set_size(&bpage->zip, zip_size);
...@@ -2713,17 +2820,23 @@ buf_page_init_for_read( ...@@ -2713,17 +2820,23 @@ buf_page_init_for_read(
HASH_INSERT(buf_page_t, hash, buf_pool->page_hash, HASH_INSERT(buf_page_t, hash, buf_pool->page_hash,
buf_page_address_fold(space, offset), bpage); buf_page_address_fold(space, offset), bpage);
mutex_exit(&page_hash_mutex);
/* The block must be put to the LRU list, to the old blocks */ /* The block must be put to the LRU list, to the old blocks */
buf_LRU_add_block(bpage, TRUE/* to old blocks */); buf_LRU_add_block(bpage, TRUE/* to old blocks */);
buf_LRU_insert_zip_clean(bpage); buf_LRU_insert_zip_clean(bpage);
mutex_exit(&LRU_list_mutex);
buf_page_set_io_fix(bpage, BUF_IO_READ); buf_page_set_io_fix(bpage, BUF_IO_READ);
mutex_exit(&buf_pool_zip_mutex); mutex_exit(&buf_pool_zip_mutex);
} }
mutex_enter(&buf_pool_mutex);
buf_pool->n_pend_reads++; buf_pool->n_pend_reads++;
buf_pool_mutex_exit(); mutex_exit(&buf_pool_mutex);
//buf_pool_mutex_exit();
if (mode == BUF_READ_IBUF_PAGES_ONLY) { if (mode == BUF_READ_IBUF_PAGES_ONLY) {
...@@ -2759,7 +2872,9 @@ buf_page_create( ...@@ -2759,7 +2872,9 @@ buf_page_create(
free_block = buf_LRU_get_free_block(0); free_block = buf_LRU_get_free_block(0);
buf_pool_mutex_enter(); //buf_pool_mutex_enter();
mutex_enter(&LRU_list_mutex);
mutex_enter(&page_hash_mutex);
block = (buf_block_t*) buf_page_hash_get(space, offset); block = (buf_block_t*) buf_page_hash_get(space, offset);
...@@ -2772,7 +2887,9 @@ buf_page_create( ...@@ -2772,7 +2887,9 @@ buf_page_create(
#endif /* UNIV_DEBUG_FILE_ACCESSES */ #endif /* UNIV_DEBUG_FILE_ACCESSES */
/* Page can be found in buf_pool */ /* Page can be found in buf_pool */
buf_pool_mutex_exit(); //buf_pool_mutex_exit();
mutex_exit(&LRU_list_mutex);
mutex_exit(&page_hash_mutex);
buf_block_free(free_block); buf_block_free(free_block);
...@@ -2794,6 +2911,7 @@ buf_page_create( ...@@ -2794,6 +2911,7 @@ buf_page_create(
mutex_enter(&block->mutex); mutex_enter(&block->mutex);
buf_page_init(space, offset, block); buf_page_init(space, offset, block);
mutex_exit(&page_hash_mutex);
/* The block must be put to the LRU list */ /* The block must be put to the LRU list */
buf_LRU_add_block(&block->page, FALSE); buf_LRU_add_block(&block->page, FALSE);
...@@ -2813,7 +2931,7 @@ buf_page_create( ...@@ -2813,7 +2931,7 @@ buf_page_create(
rw_lock_x_lock(&block->lock); rw_lock_x_lock(&block->lock);
page_zip_set_size(&block->page.zip, zip_size); page_zip_set_size(&block->page.zip, zip_size);
mutex_exit(&block->mutex); //mutex_exit(&block->mutex); /*##may be able to removed?##*/
/* buf_pool_mutex may be released and reacquired by /* buf_pool_mutex may be released and reacquired by
buf_buddy_alloc(). Thus, we must release block->mutex buf_buddy_alloc(). Thus, we must release block->mutex
in order not to break the latching order in in order not to break the latching order in
...@@ -2821,7 +2939,7 @@ buf_page_create( ...@@ -2821,7 +2939,7 @@ buf_page_create(
defer this operation until after the block descriptor defer this operation until after the block descriptor
has been added to buf_pool->LRU and buf_pool->page_hash. */ has been added to buf_pool->LRU and buf_pool->page_hash. */
data = buf_buddy_alloc(zip_size, &lru); data = buf_buddy_alloc(zip_size, &lru);
mutex_enter(&block->mutex); //mutex_enter(&block->mutex); /*##may be able to removed?##*/
block->page.zip.data = data; block->page.zip.data = data;
/* To maintain the invariant /* To maintain the invariant
...@@ -2836,7 +2954,8 @@ buf_page_create( ...@@ -2836,7 +2954,8 @@ buf_page_create(
rw_lock_x_unlock(&block->lock); rw_lock_x_unlock(&block->lock);
} }
buf_pool_mutex_exit(); //buf_pool_mutex_exit();
mutex_exit(&LRU_list_mutex);
mtr_memo_push(mtr, block, MTR_MEMO_BUF_FIX); mtr_memo_push(mtr, block, MTR_MEMO_BUF_FIX);
...@@ -2888,6 +3007,7 @@ buf_page_io_complete( ...@@ -2888,6 +3007,7 @@ buf_page_io_complete(
enum buf_io_fix io_type; enum buf_io_fix io_type;
const ibool uncompressed = (buf_page_get_state(bpage) const ibool uncompressed = (buf_page_get_state(bpage)
== BUF_BLOCK_FILE_PAGE); == BUF_BLOCK_FILE_PAGE);
enum buf_flush flush_type;
ut_a(buf_page_in_file(bpage)); ut_a(buf_page_in_file(bpage));
...@@ -3022,8 +3142,17 @@ buf_page_io_complete( ...@@ -3022,8 +3142,17 @@ buf_page_io_complete(
} }
} }
buf_pool_mutex_enter(); //buf_pool_mutex_enter();
if (io_type == BUF_IO_WRITE) {
flush_type = buf_page_get_flush_type(bpage);
/* to keep consistency at buf_LRU_insert_zip_clean() */
//if (flush_type == BUF_FLUSH_LRU) { /* optimistic! */
mutex_enter(&LRU_list_mutex);
//}
mutex_enter(&flush_list_mutex);
}
mutex_enter(buf_page_get_mutex(bpage)); mutex_enter(buf_page_get_mutex(bpage));
mutex_enter(&buf_pool_mutex);
#ifdef UNIV_IBUF_COUNT_DEBUG #ifdef UNIV_IBUF_COUNT_DEBUG
if (io_type == BUF_IO_WRITE || uncompressed) { if (io_type == BUF_IO_WRITE || uncompressed) {
...@@ -3063,6 +3192,12 @@ buf_page_io_complete( ...@@ -3063,6 +3192,12 @@ buf_page_io_complete(
buf_flush_write_complete(bpage); buf_flush_write_complete(bpage);
mutex_exit(&flush_list_mutex);
/* to keep consistency at buf_LRU_insert_zip_clean() */
//if (flush_type == BUF_FLUSH_LRU) { /* optimistic! */
mutex_exit(&LRU_list_mutex);
//}
if (uncompressed) { if (uncompressed) {
rw_lock_s_unlock_gen(&((buf_block_t*) bpage)->lock, rw_lock_s_unlock_gen(&((buf_block_t*) bpage)->lock,
BUF_IO_WRITE); BUF_IO_WRITE);
...@@ -3085,8 +3220,9 @@ buf_page_io_complete( ...@@ -3085,8 +3220,9 @@ buf_page_io_complete(
} }
#endif /* UNIV_DEBUG */ #endif /* UNIV_DEBUG */
mutex_exit(&buf_pool_mutex);
mutex_exit(buf_page_get_mutex(bpage)); mutex_exit(buf_page_get_mutex(bpage));
buf_pool_mutex_exit(); //buf_pool_mutex_exit();
} }
/************************************************************************* /*************************************************************************
...@@ -3108,12 +3244,14 @@ buf_pool_invalidate(void) ...@@ -3108,12 +3244,14 @@ buf_pool_invalidate(void)
freed = buf_LRU_search_and_free_block(100); freed = buf_LRU_search_and_free_block(100);
} }
buf_pool_mutex_enter(); //buf_pool_mutex_enter();
mutex_enter(&LRU_list_mutex);
ut_ad(UT_LIST_GET_LEN(buf_pool->LRU) == 0); ut_ad(UT_LIST_GET_LEN(buf_pool->LRU) == 0);
ut_ad(UT_LIST_GET_LEN(buf_pool->unzip_LRU) == 0); ut_ad(UT_LIST_GET_LEN(buf_pool->unzip_LRU) == 0);
buf_pool_mutex_exit(); //buf_pool_mutex_exit();
mutex_exit(&LRU_list_mutex);
} }
#if defined UNIV_DEBUG || defined UNIV_BUF_DEBUG #if defined UNIV_DEBUG || defined UNIV_BUF_DEBUG
...@@ -3137,7 +3275,11 @@ buf_validate(void) ...@@ -3137,7 +3275,11 @@ buf_validate(void)
ut_ad(buf_pool); ut_ad(buf_pool);
buf_pool_mutex_enter(); //buf_pool_mutex_enter();
mutex_enter(&LRU_list_mutex);
mutex_enter(&flush_list_mutex);
mutex_enter(&page_hash_mutex);
/* for keep the new latch order, it cannot validate correctly... */
chunk = buf_pool->chunks; chunk = buf_pool->chunks;
...@@ -3330,7 +3472,10 @@ buf_validate(void) ...@@ -3330,7 +3472,10 @@ buf_validate(void)
ut_a(buf_pool->n_flush[BUF_FLUSH_LIST] == n_list_flush); ut_a(buf_pool->n_flush[BUF_FLUSH_LIST] == n_list_flush);
ut_a(buf_pool->n_flush[BUF_FLUSH_LRU] == n_lru_flush); ut_a(buf_pool->n_flush[BUF_FLUSH_LRU] == n_lru_flush);
buf_pool_mutex_exit(); //buf_pool_mutex_exit();
mutex_exit(&LRU_list_mutex);
mutex_exit(&flush_list_mutex);
mutex_exit(&page_hash_mutex);
ut_a(buf_LRU_validate()); ut_a(buf_LRU_validate());
ut_a(buf_flush_validate()); ut_a(buf_flush_validate());
...@@ -3364,7 +3509,10 @@ buf_print(void) ...@@ -3364,7 +3509,10 @@ buf_print(void)
index_ids = mem_alloc(sizeof(dulint) * size); index_ids = mem_alloc(sizeof(dulint) * size);
counts = mem_alloc(sizeof(ulint) * size); counts = mem_alloc(sizeof(ulint) * size);
buf_pool_mutex_enter(); //buf_pool_mutex_enter();
mutex_enter(&LRU_list_mutex);
mutex_enter(&flush_list_mutex);
mutex_enter(&free_list_mutex);
fprintf(stderr, fprintf(stderr,
"buf_pool size %lu\n" "buf_pool size %lu\n"
...@@ -3427,7 +3575,10 @@ buf_print(void) ...@@ -3427,7 +3575,10 @@ buf_print(void)
} }
} }
buf_pool_mutex_exit(); //buf_pool_mutex_exit();
mutex_exit(&LRU_list_mutex);
mutex_exit(&flush_list_mutex);
mutex_exit(&free_list_mutex);
for (i = 0; i < n_found; i++) { for (i = 0; i < n_found; i++) {
index = dict_index_get_if_in_cache(index_ids[i]); index = dict_index_get_if_in_cache(index_ids[i]);
...@@ -3465,7 +3616,7 @@ buf_get_latched_pages_number(void) ...@@ -3465,7 +3616,7 @@ buf_get_latched_pages_number(void)
ulint i; ulint i;
ulint fixed_pages_number = 0; ulint fixed_pages_number = 0;
buf_pool_mutex_enter(); //buf_pool_mutex_enter();
chunk = buf_pool->chunks; chunk = buf_pool->chunks;
...@@ -3535,7 +3686,7 @@ buf_get_latched_pages_number(void) ...@@ -3535,7 +3686,7 @@ buf_get_latched_pages_number(void)
} }
mutex_exit(&buf_pool_zip_mutex); mutex_exit(&buf_pool_zip_mutex);
buf_pool_mutex_exit(); //buf_pool_mutex_exit();
return(fixed_pages_number); return(fixed_pages_number);
} }
...@@ -3564,7 +3715,7 @@ buf_get_modified_ratio_pct(void) ...@@ -3564,7 +3715,7 @@ buf_get_modified_ratio_pct(void)
{ {
ulint ratio; ulint ratio;
buf_pool_mutex_enter(); //buf_pool_mutex_enter(); /* optimistic */
ratio = (100 * UT_LIST_GET_LEN(buf_pool->flush_list)) ratio = (100 * UT_LIST_GET_LEN(buf_pool->flush_list))
/ (1 + UT_LIST_GET_LEN(buf_pool->LRU) / (1 + UT_LIST_GET_LEN(buf_pool->LRU)
...@@ -3572,7 +3723,7 @@ buf_get_modified_ratio_pct(void) ...@@ -3572,7 +3723,7 @@ buf_get_modified_ratio_pct(void)
/* 1 + is there to avoid division by zero */ /* 1 + is there to avoid division by zero */
buf_pool_mutex_exit(); //buf_pool_mutex_exit(); /* optimistic */
return(ratio); return(ratio);
} }
...@@ -3592,7 +3743,11 @@ buf_print_io( ...@@ -3592,7 +3743,11 @@ buf_print_io(
ut_ad(buf_pool); ut_ad(buf_pool);
size = buf_pool->curr_size; size = buf_pool->curr_size;
buf_pool_mutex_enter(); //buf_pool_mutex_enter();
mutex_enter(&LRU_list_mutex);
mutex_enter(&flush_list_mutex);
mutex_enter(&free_list_mutex);
mutex_enter(&buf_pool_mutex);
fprintf(file, fprintf(file,
"Buffer pool size %lu\n" "Buffer pool size %lu\n"
...@@ -3659,7 +3814,11 @@ buf_print_io( ...@@ -3659,7 +3814,11 @@ buf_print_io(
buf_LRU_stat_sum.io, buf_LRU_stat_cur.io, buf_LRU_stat_sum.io, buf_LRU_stat_cur.io,
buf_LRU_stat_sum.unzip, buf_LRU_stat_cur.unzip); buf_LRU_stat_sum.unzip, buf_LRU_stat_cur.unzip);
buf_pool_mutex_exit(); //buf_pool_mutex_exit();
mutex_exit(&LRU_list_mutex);
mutex_exit(&flush_list_mutex);
mutex_exit(&free_list_mutex);
mutex_exit(&buf_pool_mutex);
} }
/************************************************************************** /**************************************************************************
...@@ -3688,7 +3847,7 @@ buf_all_freed(void) ...@@ -3688,7 +3847,7 @@ buf_all_freed(void)
ut_ad(buf_pool); ut_ad(buf_pool);
buf_pool_mutex_enter(); //buf_pool_mutex_enter(); /* optimistic */
chunk = buf_pool->chunks; chunk = buf_pool->chunks;
...@@ -3705,7 +3864,7 @@ buf_all_freed(void) ...@@ -3705,7 +3864,7 @@ buf_all_freed(void)
} }
} }
buf_pool_mutex_exit(); //buf_pool_mutex_exit(); /* optimistic */
return(TRUE); return(TRUE);
} }
...@@ -3721,7 +3880,8 @@ buf_pool_check_no_pending_io(void) ...@@ -3721,7 +3880,8 @@ buf_pool_check_no_pending_io(void)
{ {
ibool ret; ibool ret;
buf_pool_mutex_enter(); //buf_pool_mutex_enter();
mutex_enter(&buf_pool_mutex);
if (buf_pool->n_pend_reads + buf_pool->n_flush[BUF_FLUSH_LRU] if (buf_pool->n_pend_reads + buf_pool->n_flush[BUF_FLUSH_LRU]
+ buf_pool->n_flush[BUF_FLUSH_LIST] + buf_pool->n_flush[BUF_FLUSH_LIST]
...@@ -3731,7 +3891,8 @@ buf_pool_check_no_pending_io(void) ...@@ -3731,7 +3891,8 @@ buf_pool_check_no_pending_io(void)
ret = TRUE; ret = TRUE;
} }
buf_pool_mutex_exit(); //buf_pool_mutex_exit();
mutex_exit(&buf_pool_mutex);
return(ret); return(ret);
} }
...@@ -3745,11 +3906,13 @@ buf_get_free_list_len(void) ...@@ -3745,11 +3906,13 @@ buf_get_free_list_len(void)
{ {
ulint len; ulint len;
buf_pool_mutex_enter(); //buf_pool_mutex_enter();
mutex_enter(&free_list_mutex);
len = UT_LIST_GET_LEN(buf_pool->free); len = UT_LIST_GET_LEN(buf_pool->free);
buf_pool_mutex_exit(); //buf_pool_mutex_exit();
mutex_exit(&free_list_mutex);
return(len); return(len);
} }
...@@ -45,7 +45,8 @@ buf_flush_insert_into_flush_list( ...@@ -45,7 +45,8 @@ buf_flush_insert_into_flush_list(
/*=============================*/ /*=============================*/
buf_page_t* bpage) /* in: block which is modified */ buf_page_t* bpage) /* in: block which is modified */
{ {
ut_ad(buf_pool_mutex_own()); //ut_ad(buf_pool_mutex_own());
ut_ad(mutex_own(&flush_list_mutex));
ut_ad((UT_LIST_GET_FIRST(buf_pool->flush_list) == NULL) ut_ad((UT_LIST_GET_FIRST(buf_pool->flush_list) == NULL)
|| (UT_LIST_GET_FIRST(buf_pool->flush_list)->oldest_modification || (UT_LIST_GET_FIRST(buf_pool->flush_list)->oldest_modification
<= bpage->oldest_modification)); <= bpage->oldest_modification));
...@@ -93,7 +94,8 @@ buf_flush_insert_sorted_into_flush_list( ...@@ -93,7 +94,8 @@ buf_flush_insert_sorted_into_flush_list(
buf_page_t* prev_b; buf_page_t* prev_b;
buf_page_t* b; buf_page_t* b;
ut_ad(buf_pool_mutex_own()); //ut_ad(buf_pool_mutex_own());
ut_ad(mutex_own(&flush_list_mutex));
switch (buf_page_get_state(bpage)) { switch (buf_page_get_state(bpage)) {
case BUF_BLOCK_ZIP_PAGE: case BUF_BLOCK_ZIP_PAGE:
...@@ -188,7 +190,7 @@ buf_flush_ready_for_flush( ...@@ -188,7 +190,7 @@ buf_flush_ready_for_flush(
enum buf_flush flush_type)/* in: BUF_FLUSH_LRU or BUF_FLUSH_LIST */ enum buf_flush flush_type)/* in: BUF_FLUSH_LRU or BUF_FLUSH_LIST */
{ {
ut_a(buf_page_in_file(bpage)); ut_a(buf_page_in_file(bpage));
ut_ad(buf_pool_mutex_own()); //ut_ad(buf_pool_mutex_own()); /*optimistic...*/
ut_ad(mutex_own(buf_page_get_mutex(bpage))); ut_ad(mutex_own(buf_page_get_mutex(bpage)));
if (bpage->oldest_modification != 0 if (bpage->oldest_modification != 0
...@@ -220,7 +222,8 @@ buf_flush_remove( ...@@ -220,7 +222,8 @@ buf_flush_remove(
/*=============*/ /*=============*/
buf_page_t* bpage) /* in: pointer to the block in question */ buf_page_t* bpage) /* in: pointer to the block in question */
{ {
ut_ad(buf_pool_mutex_own()); //ut_ad(buf_pool_mutex_own());
ut_ad(mutex_own(&flush_list_mutex));
ut_ad(mutex_own(buf_page_get_mutex(bpage))); ut_ad(mutex_own(buf_page_get_mutex(bpage)));
ut_ad(bpage->in_flush_list); ut_ad(bpage->in_flush_list);
ut_d(bpage->in_flush_list = FALSE); ut_d(bpage->in_flush_list = FALSE);
...@@ -773,12 +776,14 @@ buf_flush_try_page( ...@@ -773,12 +776,14 @@ buf_flush_try_page(
ut_ad(flush_type == BUF_FLUSH_LRU || flush_type == BUF_FLUSH_LIST ut_ad(flush_type == BUF_FLUSH_LRU || flush_type == BUF_FLUSH_LIST
|| flush_type == BUF_FLUSH_SINGLE_PAGE); || flush_type == BUF_FLUSH_SINGLE_PAGE);
buf_pool_mutex_enter(); //buf_pool_mutex_enter();
mutex_enter(&page_hash_mutex);
bpage = buf_page_hash_get(space, offset); bpage = buf_page_hash_get(space, offset);
if (!bpage) { if (!bpage) {
buf_pool_mutex_exit(); //buf_pool_mutex_exit();
mutex_exit(&page_hash_mutex);
return(0); return(0);
} }
...@@ -786,10 +791,13 @@ buf_flush_try_page( ...@@ -786,10 +791,13 @@ buf_flush_try_page(
block_mutex = buf_page_get_mutex(bpage); block_mutex = buf_page_get_mutex(bpage);
mutex_enter(block_mutex); mutex_enter(block_mutex);
mutex_enter(&buf_pool_mutex);
mutex_exit(&page_hash_mutex);
if (!buf_flush_ready_for_flush(bpage, flush_type)) { if (!buf_flush_ready_for_flush(bpage, flush_type)) {
mutex_exit(block_mutex); mutex_exit(block_mutex);
buf_pool_mutex_exit(); //buf_pool_mutex_exit();
mutex_exit(&buf_pool_mutex);
return(0); return(0);
} }
...@@ -818,7 +826,8 @@ buf_flush_try_page( ...@@ -818,7 +826,8 @@ buf_flush_try_page(
} }
mutex_exit(block_mutex); mutex_exit(block_mutex);
buf_pool_mutex_exit(); //buf_pool_mutex_exit();
mutex_exit(&buf_pool_mutex);
if (!locked) { if (!locked) {
buf_flush_buffered_writes(); buf_flush_buffered_writes();
...@@ -861,7 +870,8 @@ buf_flush_try_page( ...@@ -861,7 +870,8 @@ buf_flush_try_page(
immediately. */ immediately. */
mutex_exit(block_mutex); mutex_exit(block_mutex);
buf_pool_mutex_exit(); //buf_pool_mutex_exit();
mutex_exit(&buf_pool_mutex);
break; break;
case BUF_FLUSH_SINGLE_PAGE: case BUF_FLUSH_SINGLE_PAGE:
...@@ -877,8 +887,8 @@ buf_flush_try_page( ...@@ -877,8 +887,8 @@ buf_flush_try_page(
buf_pool->n_flush[flush_type]++; buf_pool->n_flush[flush_type]++;
mutex_exit(block_mutex); mutex_exit(block_mutex);
buf_pool_mutex_exit(); //buf_pool_mutex_exit();
mutex_exit(&buf_pool_mutex);
if (buf_page_get_state(bpage) == BUF_BLOCK_FILE_PAGE) { if (buf_page_get_state(bpage) == BUF_BLOCK_FILE_PAGE) {
rw_lock_s_lock_gen(&((buf_block_t*) bpage)->lock, rw_lock_s_lock_gen(&((buf_block_t*) bpage)->lock,
BUF_IO_WRITE); BUF_IO_WRITE);
...@@ -943,7 +953,8 @@ buf_flush_try_neighbors( ...@@ -943,7 +953,8 @@ buf_flush_try_neighbors(
high = fil_space_get_size(space); high = fil_space_get_size(space);
} }
buf_pool_mutex_enter(); //buf_pool_mutex_enter();
mutex_enter(&page_hash_mutex);
for (i = low; i < high; i++) { for (i = low; i < high; i++) {
...@@ -977,7 +988,8 @@ buf_flush_try_neighbors( ...@@ -977,7 +988,8 @@ buf_flush_try_neighbors(
flush the doublewrite buffer before we start flush the doublewrite buffer before we start
waiting. */ waiting. */
buf_pool_mutex_exit(); //buf_pool_mutex_exit();
mutex_exit(&page_hash_mutex);
mutex_exit(block_mutex); mutex_exit(block_mutex);
...@@ -990,14 +1002,16 @@ buf_flush_try_neighbors( ...@@ -990,14 +1002,16 @@ buf_flush_try_neighbors(
count += buf_flush_try_page(space, i, count += buf_flush_try_page(space, i,
flush_type); flush_type);
buf_pool_mutex_enter(); //buf_pool_mutex_enter();
mutex_enter(&page_hash_mutex);
} else { } else {
mutex_exit(block_mutex); mutex_exit(block_mutex);
} }
} }
} }
buf_pool_mutex_exit(); //buf_pool_mutex_exit();
mutex_exit(&page_hash_mutex);
return(count); return(count);
} }
...@@ -1041,20 +1055,29 @@ buf_flush_batch( ...@@ -1041,20 +1055,29 @@ buf_flush_batch(
ut_ad((flush_type != BUF_FLUSH_LIST) ut_ad((flush_type != BUF_FLUSH_LIST)
|| sync_thread_levels_empty_gen(TRUE)); || sync_thread_levels_empty_gen(TRUE));
#endif /* UNIV_SYNC_DEBUG */ #endif /* UNIV_SYNC_DEBUG */
buf_pool_mutex_enter(); //buf_pool_mutex_enter();
mutex_enter(&buf_pool_mutex);
if ((buf_pool->n_flush[flush_type] > 0) if ((buf_pool->n_flush[flush_type] > 0)
|| (buf_pool->init_flush[flush_type] == TRUE)) { || (buf_pool->init_flush[flush_type] == TRUE)) {
/* There is already a flush batch of the same type running */ /* There is already a flush batch of the same type running */
buf_pool_mutex_exit(); //buf_pool_mutex_exit();
mutex_exit(&buf_pool_mutex);
return(ULINT_UNDEFINED); return(ULINT_UNDEFINED);
} }
buf_pool->init_flush[flush_type] = TRUE; buf_pool->init_flush[flush_type] = TRUE;
mutex_exit(&buf_pool_mutex);
if (flush_type == BUF_FLUSH_LRU) {
mutex_enter(&LRU_list_mutex);
}
mutex_enter(&flush_list_mutex);
for (;;) { for (;;) {
flush_next: flush_next:
/* If we have flushed enough, leave the loop */ /* If we have flushed enough, leave the loop */
...@@ -1099,7 +1122,11 @@ buf_flush_batch( ...@@ -1099,7 +1122,11 @@ buf_flush_batch(
space = buf_page_get_space(bpage); space = buf_page_get_space(bpage);
offset = buf_page_get_page_no(bpage); offset = buf_page_get_page_no(bpage);
buf_pool_mutex_exit(); //buf_pool_mutex_exit();
if (flush_type == BUF_FLUSH_LRU) {
mutex_exit(&LRU_list_mutex);
}
mutex_exit(&flush_list_mutex);
mutex_exit(block_mutex); mutex_exit(block_mutex);
old_page_count = page_count; old_page_count = page_count;
...@@ -1112,7 +1139,11 @@ buf_flush_batch( ...@@ -1112,7 +1139,11 @@ buf_flush_batch(
flush_type, offset, flush_type, offset,
page_count - old_page_count); */ page_count - old_page_count); */
buf_pool_mutex_enter(); //buf_pool_mutex_enter();
if (flush_type == BUF_FLUSH_LRU) {
mutex_enter(&LRU_list_mutex);
}
mutex_enter(&flush_list_mutex);
goto flush_next; goto flush_next;
} else if (flush_type == BUF_FLUSH_LRU) { } else if (flush_type == BUF_FLUSH_LRU) {
...@@ -1135,6 +1166,13 @@ buf_flush_batch( ...@@ -1135,6 +1166,13 @@ buf_flush_batch(
break; break;
} }
if (flush_type == BUF_FLUSH_LRU) {
mutex_exit(&LRU_list_mutex);
}
mutex_exit(&flush_list_mutex);
mutex_enter(&buf_pool_mutex);
buf_pool->init_flush[flush_type] = FALSE; buf_pool->init_flush[flush_type] = FALSE;
if ((buf_pool->n_flush[flush_type] == 0) if ((buf_pool->n_flush[flush_type] == 0)
...@@ -1145,7 +1183,8 @@ buf_flush_batch( ...@@ -1145,7 +1183,8 @@ buf_flush_batch(
os_event_set(buf_pool->no_flush[flush_type]); os_event_set(buf_pool->no_flush[flush_type]);
} }
buf_pool_mutex_exit(); //buf_pool_mutex_exit();
mutex_exit(&buf_pool_mutex);
buf_flush_buffered_writes(); buf_flush_buffered_writes();
...@@ -1297,11 +1336,13 @@ buf_flush_validate(void) ...@@ -1297,11 +1336,13 @@ buf_flush_validate(void)
{ {
ibool ret; ibool ret;
buf_pool_mutex_enter(); //buf_pool_mutex_enter();
mutex_enter(&flush_list_mutex);
ret = buf_flush_validate_low(); ret = buf_flush_validate_low();
buf_pool_mutex_exit(); //buf_pool_mutex_exit();
mutex_exit(&flush_list_mutex);
return(ret); return(ret);
} }
......
...@@ -127,10 +127,12 @@ buf_LRU_evict_from_unzip_LRU(void) ...@@ -127,10 +127,12 @@ buf_LRU_evict_from_unzip_LRU(void)
ulint io_avg; ulint io_avg;
ulint unzip_avg; ulint unzip_avg;
ut_ad(buf_pool_mutex_own()); //ut_ad(buf_pool_mutex_own());
mutex_enter(&LRU_list_mutex);
/* If the unzip_LRU list is empty, we can only use the LRU. */ /* If the unzip_LRU list is empty, we can only use the LRU. */
if (UT_LIST_GET_LEN(buf_pool->unzip_LRU) == 0) { if (UT_LIST_GET_LEN(buf_pool->unzip_LRU) == 0) {
mutex_exit(&LRU_list_mutex);
return(FALSE); return(FALSE);
} }
...@@ -139,14 +141,17 @@ buf_LRU_evict_from_unzip_LRU(void) ...@@ -139,14 +141,17 @@ buf_LRU_evict_from_unzip_LRU(void)
decompressed pages in the buffer pool. */ decompressed pages in the buffer pool. */
if (UT_LIST_GET_LEN(buf_pool->unzip_LRU) if (UT_LIST_GET_LEN(buf_pool->unzip_LRU)
<= UT_LIST_GET_LEN(buf_pool->LRU) / 10) { <= UT_LIST_GET_LEN(buf_pool->LRU) / 10) {
mutex_exit(&LRU_list_mutex);
return(FALSE); return(FALSE);
} }
/* If eviction hasn't started yet, we assume by default /* If eviction hasn't started yet, we assume by default
that a workload is disk bound. */ that a workload is disk bound. */
if (buf_pool->freed_page_clock == 0) { if (buf_pool->freed_page_clock == 0) {
mutex_exit(&LRU_list_mutex);
return(TRUE); return(TRUE);
} }
mutex_exit(&LRU_list_mutex);
/* Calculate the average over past intervals, and add the values /* Calculate the average over past intervals, and add the values
of the current interval. */ of the current interval. */
...@@ -212,7 +217,8 @@ buf_LRU_drop_page_hash_for_tablespace( ...@@ -212,7 +217,8 @@ buf_LRU_drop_page_hash_for_tablespace(
page_arr = ut_malloc(sizeof(ulint) page_arr = ut_malloc(sizeof(ulint)
* BUF_LRU_DROP_SEARCH_HASH_SIZE); * BUF_LRU_DROP_SEARCH_HASH_SIZE);
buf_pool_mutex_enter(); //buf_pool_mutex_enter();
mutex_enter(&LRU_list_mutex);
scan_again: scan_again:
num_entries = 0; num_entries = 0;
...@@ -252,12 +258,14 @@ buf_LRU_drop_page_hash_for_tablespace( ...@@ -252,12 +258,14 @@ buf_LRU_drop_page_hash_for_tablespace(
} }
/* Array full. We release the buf_pool->mutex to /* Array full. We release the buf_pool->mutex to
obey the latching order. */ obey the latching order. */
buf_pool_mutex_exit(); //buf_pool_mutex_exit();
mutex_exit(&LRU_list_mutex);
buf_LRU_drop_page_hash_batch(id, zip_size, page_arr, buf_LRU_drop_page_hash_batch(id, zip_size, page_arr,
num_entries); num_entries);
num_entries = 0; num_entries = 0;
buf_pool_mutex_enter(); //buf_pool_mutex_enter();
mutex_enter(&LRU_list_mutex);
} else { } else {
mutex_exit(block_mutex); mutex_exit(block_mutex);
} }
...@@ -282,7 +290,8 @@ buf_LRU_drop_page_hash_for_tablespace( ...@@ -282,7 +290,8 @@ buf_LRU_drop_page_hash_for_tablespace(
} }
} }
buf_pool_mutex_exit(); //buf_pool_mutex_exit();
mutex_exit(&LRU_list_mutex);
/* Drop any remaining batch of search hashed pages. */ /* Drop any remaining batch of search hashed pages. */
buf_LRU_drop_page_hash_batch(id, zip_size, page_arr, num_entries); buf_LRU_drop_page_hash_batch(id, zip_size, page_arr, num_entries);
...@@ -311,7 +320,10 @@ buf_LRU_invalidate_tablespace( ...@@ -311,7 +320,10 @@ buf_LRU_invalidate_tablespace(
buf_LRU_drop_page_hash_for_tablespace(id); buf_LRU_drop_page_hash_for_tablespace(id);
scan_again: scan_again:
buf_pool_mutex_enter(); //buf_pool_mutex_enter();
mutex_enter(&LRU_list_mutex);
mutex_enter(&flush_list_mutex);
mutex_enter(&page_hash_mutex);
all_freed = TRUE; all_freed = TRUE;
...@@ -352,7 +364,10 @@ buf_LRU_invalidate_tablespace( ...@@ -352,7 +364,10 @@ buf_LRU_invalidate_tablespace(
&& ((buf_block_t*) bpage)->is_hashed) { && ((buf_block_t*) bpage)->is_hashed) {
page_no = buf_page_get_page_no(bpage); page_no = buf_page_get_page_no(bpage);
buf_pool_mutex_exit(); //buf_pool_mutex_exit();
mutex_exit(&LRU_list_mutex);
mutex_exit(&flush_list_mutex);
mutex_exit(&page_hash_mutex);
mutex_exit(block_mutex); mutex_exit(block_mutex);
/* Note that the following call will acquire /* Note that the following call will acquire
...@@ -391,7 +406,10 @@ buf_LRU_invalidate_tablespace( ...@@ -391,7 +406,10 @@ buf_LRU_invalidate_tablespace(
bpage = prev_bpage; bpage = prev_bpage;
} }
buf_pool_mutex_exit(); //buf_pool_mutex_exit();
mutex_exit(&LRU_list_mutex);
mutex_exit(&flush_list_mutex);
mutex_exit(&page_hash_mutex);
if (!all_freed) { if (!all_freed) {
os_thread_sleep(20000); os_thread_sleep(20000);
...@@ -414,14 +432,16 @@ buf_LRU_get_recent_limit(void) ...@@ -414,14 +432,16 @@ buf_LRU_get_recent_limit(void)
ulint len; ulint len;
ulint limit; ulint limit;
buf_pool_mutex_enter(); //buf_pool_mutex_enter();
mutex_enter(&LRU_list_mutex);
len = UT_LIST_GET_LEN(buf_pool->LRU); len = UT_LIST_GET_LEN(buf_pool->LRU);
if (len < BUF_LRU_OLD_MIN_LEN) { if (len < BUF_LRU_OLD_MIN_LEN) {
/* The LRU list is too short to do read-ahead */ /* The LRU list is too short to do read-ahead */
buf_pool_mutex_exit(); //buf_pool_mutex_exit();
mutex_exit(&LRU_list_mutex);
return(0); return(0);
} }
...@@ -430,7 +450,8 @@ buf_LRU_get_recent_limit(void) ...@@ -430,7 +450,8 @@ buf_LRU_get_recent_limit(void)
limit = buf_page_get_LRU_position(bpage) - len / BUF_LRU_INITIAL_RATIO; limit = buf_page_get_LRU_position(bpage) - len / BUF_LRU_INITIAL_RATIO;
buf_pool_mutex_exit(); //buf_pool_mutex_exit();
mutex_exit(&LRU_list_mutex);
return(limit); return(limit);
} }
...@@ -445,7 +466,8 @@ buf_LRU_insert_zip_clean( ...@@ -445,7 +466,8 @@ buf_LRU_insert_zip_clean(
{ {
buf_page_t* b; buf_page_t* b;
ut_ad(buf_pool_mutex_own()); //ut_ad(buf_pool_mutex_own());
ut_ad(mutex_own(&flush_list_mutex));
ut_ad(buf_page_get_state(bpage) == BUF_BLOCK_ZIP_PAGE); ut_ad(buf_page_get_state(bpage) == BUF_BLOCK_ZIP_PAGE);
/* Find the first successor of bpage in the LRU list /* Find the first successor of bpage in the LRU list
...@@ -484,7 +506,7 @@ buf_LRU_free_from_unzip_LRU_list( ...@@ -484,7 +506,7 @@ buf_LRU_free_from_unzip_LRU_list(
buf_block_t* block; buf_block_t* block;
ulint distance; ulint distance;
ut_ad(buf_pool_mutex_own()); //ut_ad(buf_pool_mutex_own()); /* optimistic */
/* Theoratically it should be much easier to find a victim /* Theoratically it should be much easier to find a victim
from unzip_LRU as we can choose even a dirty block (as we'll from unzip_LRU as we can choose even a dirty block (as we'll
...@@ -556,7 +578,7 @@ buf_LRU_free_from_common_LRU_list( ...@@ -556,7 +578,7 @@ buf_LRU_free_from_common_LRU_list(
buf_page_t* bpage; buf_page_t* bpage;
ulint distance; ulint distance;
ut_ad(buf_pool_mutex_own()); //ut_ad(buf_pool_mutex_own()); /* optimistic */
distance = 100 + (n_iterations * buf_pool->curr_size) / 10; distance = 100 + (n_iterations * buf_pool->curr_size) / 10;
...@@ -616,7 +638,8 @@ buf_LRU_search_and_free_block( ...@@ -616,7 +638,8 @@ buf_LRU_search_and_free_block(
{ {
ibool freed = FALSE; ibool freed = FALSE;
buf_pool_mutex_enter(); /* optimistic search... */
//buf_pool_mutex_enter();
freed = buf_LRU_free_from_unzip_LRU_list(n_iterations); freed = buf_LRU_free_from_unzip_LRU_list(n_iterations);
...@@ -624,13 +647,15 @@ buf_LRU_search_and_free_block( ...@@ -624,13 +647,15 @@ buf_LRU_search_and_free_block(
freed = buf_LRU_free_from_common_LRU_list(n_iterations); freed = buf_LRU_free_from_common_LRU_list(n_iterations);
} }
mutex_enter(&buf_pool_mutex);
if (!freed) { if (!freed) {
buf_pool->LRU_flush_ended = 0; buf_pool->LRU_flush_ended = 0;
} else if (buf_pool->LRU_flush_ended > 0) { } else if (buf_pool->LRU_flush_ended > 0) {
buf_pool->LRU_flush_ended--; buf_pool->LRU_flush_ended--;
} }
mutex_exit(&buf_pool_mutex);
buf_pool_mutex_exit(); //buf_pool_mutex_exit();
return(freed); return(freed);
} }
...@@ -648,18 +673,22 @@ void ...@@ -648,18 +673,22 @@ void
buf_LRU_try_free_flushed_blocks(void) buf_LRU_try_free_flushed_blocks(void)
/*=================================*/ /*=================================*/
{ {
buf_pool_mutex_enter(); //buf_pool_mutex_enter();
mutex_enter(&buf_pool_mutex);
while (buf_pool->LRU_flush_ended > 0) { while (buf_pool->LRU_flush_ended > 0) {
buf_pool_mutex_exit(); //buf_pool_mutex_exit();
mutex_exit(&buf_pool_mutex);
buf_LRU_search_and_free_block(1); buf_LRU_search_and_free_block(1);
buf_pool_mutex_enter(); //buf_pool_mutex_enter();
mutex_enter(&buf_pool_mutex);
} }
buf_pool_mutex_exit(); //buf_pool_mutex_exit();
mutex_exit(&buf_pool_mutex);
} }
/********************************************************************** /**********************************************************************
...@@ -675,7 +704,9 @@ buf_LRU_buf_pool_running_out(void) ...@@ -675,7 +704,9 @@ buf_LRU_buf_pool_running_out(void)
{ {
ibool ret = FALSE; ibool ret = FALSE;
buf_pool_mutex_enter(); //buf_pool_mutex_enter();
mutex_enter(&LRU_list_mutex);
mutex_enter(&free_list_mutex);
if (!recv_recovery_on && UT_LIST_GET_LEN(buf_pool->free) if (!recv_recovery_on && UT_LIST_GET_LEN(buf_pool->free)
+ UT_LIST_GET_LEN(buf_pool->LRU) < buf_pool->curr_size / 4) { + UT_LIST_GET_LEN(buf_pool->LRU) < buf_pool->curr_size / 4) {
...@@ -683,7 +714,9 @@ buf_LRU_buf_pool_running_out(void) ...@@ -683,7 +714,9 @@ buf_LRU_buf_pool_running_out(void)
ret = TRUE; ret = TRUE;
} }
buf_pool_mutex_exit(); //buf_pool_mutex_exit();
mutex_exit(&LRU_list_mutex);
mutex_exit(&free_list_mutex);
return(ret); return(ret);
} }
...@@ -700,8 +733,9 @@ buf_LRU_get_free_only(void) ...@@ -700,8 +733,9 @@ buf_LRU_get_free_only(void)
{ {
buf_block_t* block; buf_block_t* block;
ut_ad(buf_pool_mutex_own()); //ut_ad(buf_pool_mutex_own());
mutex_enter(&free_list_mutex);
block = (buf_block_t*) UT_LIST_GET_FIRST(buf_pool->free); block = (buf_block_t*) UT_LIST_GET_FIRST(buf_pool->free);
if (block) { if (block) {
...@@ -712,12 +746,16 @@ buf_LRU_get_free_only(void) ...@@ -712,12 +746,16 @@ buf_LRU_get_free_only(void)
ut_a(!buf_page_in_file(&block->page)); ut_a(!buf_page_in_file(&block->page));
UT_LIST_REMOVE(list, buf_pool->free, (&block->page)); UT_LIST_REMOVE(list, buf_pool->free, (&block->page));
mutex_exit(&free_list_mutex);
mutex_enter(&block->mutex); mutex_enter(&block->mutex);
buf_block_set_state(block, BUF_BLOCK_READY_FOR_USE); buf_block_set_state(block, BUF_BLOCK_READY_FOR_USE);
UNIV_MEM_ALLOC(block->frame, UNIV_PAGE_SIZE); UNIV_MEM_ALLOC(block->frame, UNIV_PAGE_SIZE);
mutex_exit(&block->mutex); mutex_exit(&block->mutex);
} else {
mutex_exit(&free_list_mutex);
} }
return(block); return(block);
...@@ -742,7 +780,7 @@ buf_LRU_get_free_block( ...@@ -742,7 +780,7 @@ buf_LRU_get_free_block(
ibool mon_value_was = FALSE; ibool mon_value_was = FALSE;
ibool started_monitor = FALSE; ibool started_monitor = FALSE;
loop: loop:
buf_pool_mutex_enter(); //buf_pool_mutex_enter();
if (!recv_recovery_on && UT_LIST_GET_LEN(buf_pool->free) if (!recv_recovery_on && UT_LIST_GET_LEN(buf_pool->free)
+ UT_LIST_GET_LEN(buf_pool->LRU) < buf_pool->curr_size / 20) { + UT_LIST_GET_LEN(buf_pool->LRU) < buf_pool->curr_size / 20) {
...@@ -829,7 +867,7 @@ buf_LRU_get_free_block( ...@@ -829,7 +867,7 @@ buf_LRU_get_free_block(
block->page.zip.data = NULL; block->page.zip.data = NULL;
} }
buf_pool_mutex_exit(); //buf_pool_mutex_exit();
if (started_monitor) { if (started_monitor) {
srv_print_innodb_monitor = mon_value_was; srv_print_innodb_monitor = mon_value_was;
...@@ -841,7 +879,7 @@ buf_LRU_get_free_block( ...@@ -841,7 +879,7 @@ buf_LRU_get_free_block(
/* If no block was in the free list, search from the end of the LRU /* If no block was in the free list, search from the end of the LRU
list and try to free a block there */ list and try to free a block there */
buf_pool_mutex_exit(); //buf_pool_mutex_exit();
freed = buf_LRU_search_and_free_block(n_iterations); freed = buf_LRU_search_and_free_block(n_iterations);
...@@ -890,18 +928,21 @@ buf_LRU_get_free_block( ...@@ -890,18 +928,21 @@ buf_LRU_get_free_block(
os_aio_simulated_wake_handler_threads(); os_aio_simulated_wake_handler_threads();
buf_pool_mutex_enter(); //buf_pool_mutex_enter();
mutex_enter(&buf_pool_mutex);
if (buf_pool->LRU_flush_ended > 0) { if (buf_pool->LRU_flush_ended > 0) {
/* We have written pages in an LRU flush. To make the insert /* We have written pages in an LRU flush. To make the insert
buffer more efficient, we try to move these pages to the free buffer more efficient, we try to move these pages to the free
list. */ list. */
buf_pool_mutex_exit(); //buf_pool_mutex_exit();
mutex_exit(&buf_pool_mutex);
buf_LRU_try_free_flushed_blocks(); buf_LRU_try_free_flushed_blocks();
} else { } else {
buf_pool_mutex_exit(); //buf_pool_mutex_exit();
mutex_exit(&buf_pool_mutex);
} }
if (n_iterations > 10) { if (n_iterations > 10) {
...@@ -926,7 +967,8 @@ buf_LRU_old_adjust_len(void) ...@@ -926,7 +967,8 @@ buf_LRU_old_adjust_len(void)
ulint new_len; ulint new_len;
ut_a(buf_pool->LRU_old); ut_a(buf_pool->LRU_old);
ut_ad(buf_pool_mutex_own()); //ut_ad(buf_pool_mutex_own());
ut_ad(mutex_own(&LRU_list_mutex));
#if 3 * (BUF_LRU_OLD_MIN_LEN / 8) <= BUF_LRU_OLD_TOLERANCE + 5 #if 3 * (BUF_LRU_OLD_MIN_LEN / 8) <= BUF_LRU_OLD_TOLERANCE + 5
# error "3 * (BUF_LRU_OLD_MIN_LEN / 8) <= BUF_LRU_OLD_TOLERANCE + 5" # error "3 * (BUF_LRU_OLD_MIN_LEN / 8) <= BUF_LRU_OLD_TOLERANCE + 5"
#endif #endif
...@@ -984,7 +1026,8 @@ buf_LRU_old_init(void) ...@@ -984,7 +1026,8 @@ buf_LRU_old_init(void)
{ {
buf_page_t* bpage; buf_page_t* bpage;
ut_ad(buf_pool_mutex_own()); //ut_ad(buf_pool_mutex_own());
ut_ad(mutex_own(&LRU_list_mutex));
ut_a(UT_LIST_GET_LEN(buf_pool->LRU) == BUF_LRU_OLD_MIN_LEN); ut_a(UT_LIST_GET_LEN(buf_pool->LRU) == BUF_LRU_OLD_MIN_LEN);
/* We first initialize all blocks in the LRU list as old and then use /* We first initialize all blocks in the LRU list as old and then use
...@@ -1016,7 +1059,8 @@ buf_unzip_LRU_remove_block_if_needed( ...@@ -1016,7 +1059,8 @@ buf_unzip_LRU_remove_block_if_needed(
ut_ad(buf_pool); ut_ad(buf_pool);
ut_ad(bpage); ut_ad(bpage);
ut_ad(buf_page_in_file(bpage)); ut_ad(buf_page_in_file(bpage));
ut_ad(buf_pool_mutex_own()); //ut_ad(buf_pool_mutex_own());
ut_ad(mutex_own(&LRU_list_mutex));
if (buf_page_belongs_to_unzip_LRU(bpage)) { if (buf_page_belongs_to_unzip_LRU(bpage)) {
buf_block_t* block = (buf_block_t*) bpage; buf_block_t* block = (buf_block_t*) bpage;
...@@ -1038,7 +1082,8 @@ buf_LRU_remove_block( ...@@ -1038,7 +1082,8 @@ buf_LRU_remove_block(
{ {
ut_ad(buf_pool); ut_ad(buf_pool);
ut_ad(bpage); ut_ad(bpage);
ut_ad(buf_pool_mutex_own()); //ut_ad(buf_pool_mutex_own());
ut_ad(mutex_own(&LRU_list_mutex));
ut_a(buf_page_in_file(bpage)); ut_a(buf_page_in_file(bpage));
...@@ -1065,7 +1110,7 @@ buf_LRU_remove_block( ...@@ -1065,7 +1110,7 @@ buf_LRU_remove_block(
/* Remove the block from the LRU list */ /* Remove the block from the LRU list */
UT_LIST_REMOVE(LRU, buf_pool->LRU, bpage); UT_LIST_REMOVE(LRU, buf_pool->LRU, bpage);
ut_d(bpage->in_LRU_list = FALSE); bpage->in_LRU_list = FALSE;
buf_unzip_LRU_remove_block_if_needed(bpage); buf_unzip_LRU_remove_block_if_needed(bpage);
...@@ -1101,7 +1146,8 @@ buf_unzip_LRU_add_block( ...@@ -1101,7 +1146,8 @@ buf_unzip_LRU_add_block(
{ {
ut_ad(buf_pool); ut_ad(buf_pool);
ut_ad(block); ut_ad(block);
ut_ad(buf_pool_mutex_own()); //ut_ad(buf_pool_mutex_own());
ut_ad(mutex_own(&LRU_list_mutex));
ut_a(buf_page_belongs_to_unzip_LRU(&block->page)); ut_a(buf_page_belongs_to_unzip_LRU(&block->page));
...@@ -1127,7 +1173,8 @@ buf_LRU_add_block_to_end_low( ...@@ -1127,7 +1173,8 @@ buf_LRU_add_block_to_end_low(
ut_ad(buf_pool); ut_ad(buf_pool);
ut_ad(bpage); ut_ad(bpage);
ut_ad(buf_pool_mutex_own()); //ut_ad(buf_pool_mutex_own());
ut_ad(mutex_own(&LRU_list_mutex));
ut_a(buf_page_in_file(bpage)); ut_a(buf_page_in_file(bpage));
...@@ -1141,7 +1188,7 @@ buf_LRU_add_block_to_end_low( ...@@ -1141,7 +1188,7 @@ buf_LRU_add_block_to_end_low(
ut_ad(!bpage->in_LRU_list); ut_ad(!bpage->in_LRU_list);
UT_LIST_ADD_LAST(LRU, buf_pool->LRU, bpage); UT_LIST_ADD_LAST(LRU, buf_pool->LRU, bpage);
ut_d(bpage->in_LRU_list = TRUE); bpage->in_LRU_list = TRUE;
buf_page_set_old(bpage, TRUE); buf_page_set_old(bpage, TRUE);
...@@ -1187,7 +1234,8 @@ buf_LRU_add_block_low( ...@@ -1187,7 +1234,8 @@ buf_LRU_add_block_low(
{ {
ut_ad(buf_pool); ut_ad(buf_pool);
ut_ad(bpage); ut_ad(bpage);
ut_ad(buf_pool_mutex_own()); //ut_ad(buf_pool_mutex_own());
ut_ad(mutex_own(&LRU_list_mutex));
ut_a(buf_page_in_file(bpage)); ut_a(buf_page_in_file(bpage));
ut_ad(!bpage->in_LRU_list); ut_ad(!bpage->in_LRU_list);
...@@ -1218,7 +1266,7 @@ buf_LRU_add_block_low( ...@@ -1218,7 +1266,7 @@ buf_LRU_add_block_low(
bpage->LRU_position = (buf_pool->LRU_old)->LRU_position; bpage->LRU_position = (buf_pool->LRU_old)->LRU_position;
} }
ut_d(bpage->in_LRU_list = TRUE); bpage->in_LRU_list = TRUE;
buf_page_set_old(bpage, old); buf_page_set_old(bpage, old);
...@@ -1308,7 +1356,7 @@ buf_LRU_free_block( ...@@ -1308,7 +1356,7 @@ buf_LRU_free_block(
buf_page_t* b = NULL; buf_page_t* b = NULL;
mutex_t* block_mutex = buf_page_get_mutex(bpage); mutex_t* block_mutex = buf_page_get_mutex(bpage);
ut_ad(buf_pool_mutex_own()); //ut_ad(buf_pool_mutex_own());
ut_ad(mutex_own(block_mutex)); ut_ad(mutex_own(block_mutex));
ut_ad(buf_page_in_file(bpage)); ut_ad(buf_page_in_file(bpage));
ut_ad(bpage->in_LRU_list); ut_ad(bpage->in_LRU_list);
...@@ -1362,6 +1410,27 @@ buf_LRU_free_block( ...@@ -1362,6 +1410,27 @@ buf_LRU_free_block(
} }
#endif /* UNIV_DEBUG */ #endif /* UNIV_DEBUG */
/* not to break latch order, must re-enter block_mutex */
mutex_exit(block_mutex);
mutex_enter(&LRU_list_mutex); /* optimistic */
mutex_enter(&page_hash_mutex);
mutex_enter(block_mutex);
/* recheck states of block */
if (!bpage->in_LRU_list /* <- if statisfy it, is restart of LRU scan needed ? */
|| !buf_page_can_relocate(bpage)
|| ( (zip || !bpage->zip.data) && bpage->oldest_modification )
|| ( bpage->oldest_modification
&& buf_page_get_state(bpage) != BUF_BLOCK_FILE_PAGE ) ) {
if (b) {
buf_buddy_free(b, sizeof *b);
}
mutex_exit(&LRU_list_mutex);
mutex_exit(&page_hash_mutex);
return(BUF_LRU_NOT_FREED);
}
if (buf_LRU_block_remove_hashed_page(bpage, zip) if (buf_LRU_block_remove_hashed_page(bpage, zip)
!= BUF_BLOCK_ZIP_FREE) { != BUF_BLOCK_ZIP_FREE) {
ut_a(bpage->buf_fix_count == 0); ut_a(bpage->buf_fix_count == 0);
...@@ -1443,7 +1512,7 @@ buf_LRU_free_block( ...@@ -1443,7 +1512,7 @@ buf_LRU_free_block(
buf_LRU_old_init(); buf_LRU_old_init();
} }
} else { } else {
ut_d(b->in_LRU_list = FALSE); b->in_LRU_list = FALSE;
buf_LRU_add_block_low(b, buf_page_is_old(b)); buf_LRU_add_block_low(b, buf_page_is_old(b));
} }
...@@ -1486,7 +1555,9 @@ buf_LRU_free_block( ...@@ -1486,7 +1555,9 @@ buf_LRU_free_block(
*buf_pool_mutex_released = TRUE; *buf_pool_mutex_released = TRUE;
} }
buf_pool_mutex_exit(); //buf_pool_mutex_exit();
mutex_exit(&LRU_list_mutex);
mutex_exit(&page_hash_mutex);
mutex_exit(block_mutex); mutex_exit(block_mutex);
/* Remove possible adaptive hash index on the page. /* Remove possible adaptive hash index on the page.
...@@ -1518,7 +1589,7 @@ buf_LRU_free_block( ...@@ -1518,7 +1589,7 @@ buf_LRU_free_block(
: BUF_NO_CHECKSUM_MAGIC); : BUF_NO_CHECKSUM_MAGIC);
} }
buf_pool_mutex_enter(); //buf_pool_mutex_enter();
mutex_enter(block_mutex); mutex_enter(block_mutex);
if (b) { if (b) {
...@@ -1530,7 +1601,8 @@ buf_LRU_free_block( ...@@ -1530,7 +1601,8 @@ buf_LRU_free_block(
buf_LRU_block_free_hashed_page((buf_block_t*) bpage); buf_LRU_block_free_hashed_page((buf_block_t*) bpage);
} else { } else {
mutex_enter(block_mutex); /* It may be bug of 1.0.2 */
//mutex_enter(block_mutex);
} }
return(BUF_LRU_FREED); return(BUF_LRU_FREED);
...@@ -1546,7 +1618,7 @@ buf_LRU_block_free_non_file_page( ...@@ -1546,7 +1618,7 @@ buf_LRU_block_free_non_file_page(
{ {
void* data; void* data;
ut_ad(buf_pool_mutex_own()); //ut_ad(buf_pool_mutex_own());
ut_ad(mutex_own(&block->mutex)); ut_ad(mutex_own(&block->mutex));
ut_ad(block); ut_ad(block);
...@@ -1586,8 +1658,10 @@ buf_LRU_block_free_non_file_page( ...@@ -1586,8 +1658,10 @@ buf_LRU_block_free_non_file_page(
page_zip_set_size(&block->page.zip, 0); page_zip_set_size(&block->page.zip, 0);
} }
mutex_enter(&free_list_mutex);
UT_LIST_ADD_FIRST(list, buf_pool->free, (&block->page)); UT_LIST_ADD_FIRST(list, buf_pool->free, (&block->page));
ut_d(block->page.in_free_list = TRUE); ut_d(block->page.in_free_list = TRUE);
mutex_exit(&free_list_mutex);
UNIV_MEM_ASSERT_AND_FREE(block->frame, UNIV_PAGE_SIZE); UNIV_MEM_ASSERT_AND_FREE(block->frame, UNIV_PAGE_SIZE);
} }
...@@ -1616,7 +1690,9 @@ buf_LRU_block_remove_hashed_page( ...@@ -1616,7 +1690,9 @@ buf_LRU_block_remove_hashed_page(
{ {
const buf_page_t* hashed_bpage; const buf_page_t* hashed_bpage;
ut_ad(bpage); ut_ad(bpage);
ut_ad(buf_pool_mutex_own()); //ut_ad(buf_pool_mutex_own());
ut_ad(mutex_own(&LRU_list_mutex));
ut_ad(mutex_own(&page_hash_mutex));
ut_ad(mutex_own(buf_page_get_mutex(bpage))); ut_ad(mutex_own(buf_page_get_mutex(bpage)));
ut_a(buf_page_get_io_fix(bpage) == BUF_IO_NONE); ut_a(buf_page_get_io_fix(bpage) == BUF_IO_NONE);
...@@ -1717,7 +1793,9 @@ buf_LRU_block_remove_hashed_page( ...@@ -1717,7 +1793,9 @@ buf_LRU_block_remove_hashed_page(
#if defined UNIV_DEBUG || defined UNIV_BUF_DEBUG #if defined UNIV_DEBUG || defined UNIV_BUF_DEBUG
mutex_exit(buf_page_get_mutex(bpage)); mutex_exit(buf_page_get_mutex(bpage));
buf_pool_mutex_exit(); //buf_pool_mutex_exit();
mutex_exit(&LRU_list_mutex);
mutex_exit(&page_hash_mutex);
buf_print(); buf_print();
buf_LRU_print(); buf_LRU_print();
buf_validate(); buf_validate();
...@@ -1795,7 +1873,7 @@ buf_LRU_block_free_hashed_page( ...@@ -1795,7 +1873,7 @@ buf_LRU_block_free_hashed_page(
buf_block_t* block) /* in: block, must contain a file page and buf_block_t* block) /* in: block, must contain a file page and
be in a state where it can be freed */ be in a state where it can be freed */
{ {
ut_ad(buf_pool_mutex_own()); //ut_ad(buf_pool_mutex_own());
ut_ad(mutex_own(&block->mutex)); ut_ad(mutex_own(&block->mutex));
buf_block_set_state(block, BUF_BLOCK_MEMORY); buf_block_set_state(block, BUF_BLOCK_MEMORY);
...@@ -1818,7 +1896,8 @@ buf_LRU_stat_update(void) ...@@ -1818,7 +1896,8 @@ buf_LRU_stat_update(void)
goto func_exit; goto func_exit;
} }
buf_pool_mutex_enter(); //buf_pool_mutex_enter();
mutex_enter(&buf_pool_mutex);
/* Update the index. */ /* Update the index. */
item = &buf_LRU_stat_arr[buf_LRU_stat_arr_ind]; item = &buf_LRU_stat_arr[buf_LRU_stat_arr_ind];
...@@ -1832,7 +1911,8 @@ buf_LRU_stat_update(void) ...@@ -1832,7 +1911,8 @@ buf_LRU_stat_update(void)
/* Put current entry in the array. */ /* Put current entry in the array. */
memcpy(item, &buf_LRU_stat_cur, sizeof *item); memcpy(item, &buf_LRU_stat_cur, sizeof *item);
buf_pool_mutex_exit(); //buf_pool_mutex_exit();
mutex_exit(&buf_pool_mutex);
func_exit: func_exit:
/* Clear the current entry. */ /* Clear the current entry. */
...@@ -1854,7 +1934,8 @@ buf_LRU_validate(void) ...@@ -1854,7 +1934,8 @@ buf_LRU_validate(void)
ulint LRU_pos; ulint LRU_pos;
ut_ad(buf_pool); ut_ad(buf_pool);
buf_pool_mutex_enter(); //buf_pool_mutex_enter();
mutex_enter(&LRU_list_mutex);
if (UT_LIST_GET_LEN(buf_pool->LRU) >= BUF_LRU_OLD_MIN_LEN) { if (UT_LIST_GET_LEN(buf_pool->LRU) >= BUF_LRU_OLD_MIN_LEN) {
...@@ -1913,6 +1994,9 @@ buf_LRU_validate(void) ...@@ -1913,6 +1994,9 @@ buf_LRU_validate(void)
ut_a(buf_pool->LRU_old_len == old_len); ut_a(buf_pool->LRU_old_len == old_len);
} }
mutex_exit(&LRU_list_mutex);
mutex_enter(&free_list_mutex);
UT_LIST_VALIDATE(list, buf_page_t, buf_pool->free); UT_LIST_VALIDATE(list, buf_page_t, buf_pool->free);
for (bpage = UT_LIST_GET_FIRST(buf_pool->free); for (bpage = UT_LIST_GET_FIRST(buf_pool->free);
...@@ -1922,6 +2006,9 @@ buf_LRU_validate(void) ...@@ -1922,6 +2006,9 @@ buf_LRU_validate(void)
ut_a(buf_page_get_state(bpage) == BUF_BLOCK_NOT_USED); ut_a(buf_page_get_state(bpage) == BUF_BLOCK_NOT_USED);
} }
mutex_exit(&free_list_mutex);
mutex_enter(&LRU_list_mutex);
UT_LIST_VALIDATE(unzip_LRU, buf_block_t, buf_pool->unzip_LRU); UT_LIST_VALIDATE(unzip_LRU, buf_block_t, buf_pool->unzip_LRU);
for (block = UT_LIST_GET_FIRST(buf_pool->unzip_LRU); for (block = UT_LIST_GET_FIRST(buf_pool->unzip_LRU);
...@@ -1933,7 +2020,8 @@ buf_LRU_validate(void) ...@@ -1933,7 +2020,8 @@ buf_LRU_validate(void)
ut_a(buf_page_belongs_to_unzip_LRU(&block->page)); ut_a(buf_page_belongs_to_unzip_LRU(&block->page));
} }
buf_pool_mutex_exit(); //buf_pool_mutex_exit();
mutex_exit(&LRU_list_mutex);
return(TRUE); return(TRUE);
} }
#endif /* UNIV_DEBUG || UNIV_BUF_DEBUG */ #endif /* UNIV_DEBUG || UNIV_BUF_DEBUG */
...@@ -1949,7 +2037,8 @@ buf_LRU_print(void) ...@@ -1949,7 +2037,8 @@ buf_LRU_print(void)
const buf_page_t* bpage; const buf_page_t* bpage;
ut_ad(buf_pool); ut_ad(buf_pool);
buf_pool_mutex_enter(); //buf_pool_mutex_enter();
mutex_enter(&LRU_list_mutex);
fprintf(stderr, "Pool ulint clock %lu\n", fprintf(stderr, "Pool ulint clock %lu\n",
(ulong) buf_pool->ulint_clock); (ulong) buf_pool->ulint_clock);
...@@ -2012,6 +2101,7 @@ buf_LRU_print(void) ...@@ -2012,6 +2101,7 @@ buf_LRU_print(void)
bpage = UT_LIST_GET_NEXT(LRU, bpage); bpage = UT_LIST_GET_NEXT(LRU, bpage);
} }
buf_pool_mutex_exit(); //buf_pool_mutex_exit();
mutex_exit(&LRU_list_mutex);
} }
#endif /* UNIV_DEBUG_PRINT || UNIV_DEBUG || UNIV_BUF_DEBUG */ #endif /* UNIV_DEBUG_PRINT || UNIV_DEBUG || UNIV_BUF_DEBUG */
...@@ -229,18 +229,22 @@ buf_read_ahead_random( ...@@ -229,18 +229,22 @@ buf_read_ahead_random(
LRU_recent_limit = buf_LRU_get_recent_limit(); LRU_recent_limit = buf_LRU_get_recent_limit();
buf_pool_mutex_enter(); //buf_pool_mutex_enter();
mutex_enter(&buf_pool_mutex);
if (buf_pool->n_pend_reads if (buf_pool->n_pend_reads
> buf_pool->curr_size / BUF_READ_AHEAD_PEND_LIMIT) { > buf_pool->curr_size / BUF_READ_AHEAD_PEND_LIMIT) {
buf_pool_mutex_exit(); //buf_pool_mutex_exit();
mutex_exit(&buf_pool_mutex);
return(0); return(0);
} }
mutex_exit(&buf_pool_mutex);
/* Count how many blocks in the area have been recently accessed, /* Count how many blocks in the area have been recently accessed,
that is, reside near the start of the LRU list. */ that is, reside near the start of the LRU list. */
mutex_enter(&page_hash_mutex);
for (i = low; i < high; i++) { for (i = low; i < high; i++) {
const buf_page_t* bpage = buf_page_hash_get(space, i); const buf_page_t* bpage = buf_page_hash_get(space, i);
...@@ -252,13 +256,15 @@ buf_read_ahead_random( ...@@ -252,13 +256,15 @@ buf_read_ahead_random(
if (recent_blocks >= BUF_READ_AHEAD_RANDOM_THRESHOLD) { if (recent_blocks >= BUF_READ_AHEAD_RANDOM_THRESHOLD) {
buf_pool_mutex_exit(); //buf_pool_mutex_exit();
mutex_exit(&page_hash_mutex);
goto read_ahead; goto read_ahead;
} }
} }
} }
buf_pool_mutex_exit(); //buf_pool_mutex_exit();
mutex_exit(&page_hash_mutex);
/* Do nothing */ /* Do nothing */
return(0); return(0);
...@@ -452,10 +458,12 @@ buf_read_ahead_linear( ...@@ -452,10 +458,12 @@ buf_read_ahead_linear(
tablespace_version = fil_space_get_version(space); tablespace_version = fil_space_get_version(space);
buf_pool_mutex_enter(); //buf_pool_mutex_enter();
mutex_enter(&buf_pool_mutex);
if (high > fil_space_get_size(space)) { if (high > fil_space_get_size(space)) {
buf_pool_mutex_exit(); //buf_pool_mutex_exit();
mutex_exit(&buf_pool_mutex);
/* The area is not whole, return */ /* The area is not whole, return */
return(0); return(0);
...@@ -463,10 +471,12 @@ buf_read_ahead_linear( ...@@ -463,10 +471,12 @@ buf_read_ahead_linear(
if (buf_pool->n_pend_reads if (buf_pool->n_pend_reads
> buf_pool->curr_size / BUF_READ_AHEAD_PEND_LIMIT) { > buf_pool->curr_size / BUF_READ_AHEAD_PEND_LIMIT) {
buf_pool_mutex_exit(); //buf_pool_mutex_exit();
mutex_exit(&buf_pool_mutex);
return(0); return(0);
} }
mutex_exit(&buf_pool_mutex);
/* Check that almost all pages in the area have been accessed; if /* Check that almost all pages in the area have been accessed; if
offset == low, the accesses must be in a descending order, otherwise, offset == low, the accesses must be in a descending order, otherwise,
...@@ -480,6 +490,7 @@ buf_read_ahead_linear( ...@@ -480,6 +490,7 @@ buf_read_ahead_linear(
fail_count = 0; fail_count = 0;
mutex_enter(&page_hash_mutex);
for (i = low; i < high; i++) { for (i = low; i < high; i++) {
bpage = buf_page_hash_get(space, i); bpage = buf_page_hash_get(space, i);
...@@ -503,7 +514,8 @@ buf_read_ahead_linear( ...@@ -503,7 +514,8 @@ buf_read_ahead_linear(
* LINEAR_AREA_THRESHOLD_COEF) { * LINEAR_AREA_THRESHOLD_COEF) {
/* Too many failures: return */ /* Too many failures: return */
buf_pool_mutex_exit(); //buf_pool_mutex_exit();
mutex_exit(&page_hash_mutex);
return(0); return(0);
} }
...@@ -514,7 +526,8 @@ buf_read_ahead_linear( ...@@ -514,7 +526,8 @@ buf_read_ahead_linear(
bpage = buf_page_hash_get(space, offset); bpage = buf_page_hash_get(space, offset);
if (bpage == NULL) { if (bpage == NULL) {
buf_pool_mutex_exit(); //buf_pool_mutex_exit();
mutex_exit(&page_hash_mutex);
return(0); return(0);
} }
...@@ -540,7 +553,8 @@ buf_read_ahead_linear( ...@@ -540,7 +553,8 @@ buf_read_ahead_linear(
pred_offset = fil_page_get_prev(frame); pred_offset = fil_page_get_prev(frame);
succ_offset = fil_page_get_next(frame); succ_offset = fil_page_get_next(frame);
buf_pool_mutex_exit(); //buf_pool_mutex_exit();
mutex_exit(&page_hash_mutex);
if ((offset == low) && (succ_offset == offset + 1)) { if ((offset == low) && (succ_offset == offset + 1)) {
......
...@@ -2287,7 +2287,8 @@ i_s_cmpmem_fill_low( ...@@ -2287,7 +2287,8 @@ i_s_cmpmem_fill_low(
RETURN_IF_INNODB_NOT_STARTED(tables->schema_table_name); RETURN_IF_INNODB_NOT_STARTED(tables->schema_table_name);
buf_pool_mutex_enter(); //buf_pool_mutex_enter();
mutex_enter(&zip_free_mutex);
for (uint x = 0; x <= BUF_BUDDY_SIZES; x++) { for (uint x = 0; x <= BUF_BUDDY_SIZES; x++) {
buf_buddy_stat_t* buddy_stat = &buf_buddy_stat[x]; buf_buddy_stat_t* buddy_stat = &buf_buddy_stat[x];
...@@ -2313,7 +2314,8 @@ i_s_cmpmem_fill_low( ...@@ -2313,7 +2314,8 @@ i_s_cmpmem_fill_low(
} }
} }
buf_pool_mutex_exit(); //buf_pool_mutex_exit();
mutex_exit(&zip_free_mutex);
DBUG_RETURN(status); DBUG_RETURN(status);
} }
......
...@@ -29,5 +29,6 @@ struct innodb_enhancement { ...@@ -29,5 +29,6 @@ struct innodb_enhancement {
{"innodb_rw_lock","InnoDB RW-lock fixes","Useful for 8+ cores SMP systems","http://www.percona.com/docs/wiki/percona-xtradb:innodb_rw_lock"}, {"innodb_rw_lock","InnoDB RW-lock fixes","Useful for 8+ cores SMP systems","http://www.percona.com/docs/wiki/percona-xtradb:innodb_rw_lock"},
{"innodb_opt_lru_count","Fix of buffer_pool mutex","Decreases contention on buffer_pool mutex on LRU operations","http://www.percona.com/docs/wiki/percona-xtradb:innodb_opt_lru_count"}, {"innodb_opt_lru_count","Fix of buffer_pool mutex","Decreases contention on buffer_pool mutex on LRU operations","http://www.percona.com/docs/wiki/percona-xtradb:innodb_opt_lru_count"},
{"innodb_buffer_pool_pages","Information of buffer pool content","","http://www.percona.com/docs/wiki/percona-xtradb:innodb_buffer_pool_pages"}, {"innodb_buffer_pool_pages","Information of buffer pool content","","http://www.percona.com/docs/wiki/percona-xtradb:innodb_buffer_pool_pages"},
{"innodb_split_buf_pool_mutex","More fix of buffer_pool mutex","Spliting buf_pool_mutex and optimizing based on innodb_opt_lru_count","http://www.percona.com/docs/wiki/percona-xtradb:innodb_split_buf_pool_mutex"},
{NULL, NULL, NULL, NULL} {NULL, NULL, NULL, NULL}
}; };
...@@ -86,7 +86,7 @@ buf_buddy_alloc( ...@@ -86,7 +86,7 @@ buf_buddy_alloc(
and buf_pool_mutex was temporarily released, and buf_pool_mutex was temporarily released,
or NULL if the LRU list should not be used */ or NULL if the LRU list should not be used */
{ {
ut_ad(buf_pool_mutex_own()); //ut_ad(buf_pool_mutex_own());
return(buf_buddy_alloc_low(buf_buddy_get_slot(size), lru)); return(buf_buddy_alloc_low(buf_buddy_get_slot(size), lru));
} }
...@@ -101,9 +101,11 @@ buf_buddy_free( ...@@ -101,9 +101,11 @@ buf_buddy_free(
pointed to by the buffer pool */ pointed to by the buffer pool */
ulint size) /* in: block size, up to UNIV_PAGE_SIZE */ ulint size) /* in: block size, up to UNIV_PAGE_SIZE */
{ {
ut_ad(buf_pool_mutex_own()); //ut_ad(buf_pool_mutex_own());
mutex_enter(&zip_free_mutex);
buf_buddy_free_low(buf, buf_buddy_get_slot(size)); buf_buddy_free_low(buf, buf_buddy_get_slot(size));
mutex_exit(&zip_free_mutex);
} }
#ifdef UNIV_MATERIALIZE #ifdef UNIV_MATERIALIZE
......
...@@ -1055,10 +1055,10 @@ struct buf_page_struct{ ...@@ -1055,10 +1055,10 @@ struct buf_page_struct{
UT_LIST_NODE_T(buf_page_t) LRU; UT_LIST_NODE_T(buf_page_t) LRU;
/* node of the LRU list */ /* node of the LRU list */
#ifdef UNIV_DEBUG //#ifdef UNIV_DEBUG
ibool in_LRU_list; /* TRUE if the page is in the LRU list; ibool in_LRU_list; /* TRUE if the page is in the LRU list;
used in debugging */ used in debugging */
#endif /* UNIV_DEBUG */ //#endif /* UNIV_DEBUG */
unsigned old:1; /* TRUE if the block is in the old unsigned old:1; /* TRUE if the block is in the old
blocks in the LRU list */ blocks in the LRU list */
unsigned LRU_position:31;/* value which monotonically decreases unsigned LRU_position:31;/* value which monotonically decreases
...@@ -1310,6 +1310,12 @@ struct buf_pool_struct{ ...@@ -1310,6 +1310,12 @@ struct buf_pool_struct{
/* mutex protecting the buffer pool struct and control blocks, except the /* mutex protecting the buffer pool struct and control blocks, except the
read-write lock in them */ read-write lock in them */
extern mutex_t buf_pool_mutex; extern mutex_t buf_pool_mutex;
extern mutex_t LRU_list_mutex;
extern mutex_t flush_list_mutex;
extern mutex_t page_hash_mutex;
extern mutex_t free_list_mutex;
extern mutex_t zip_free_mutex;
extern mutex_t zip_hash_mutex;
/* mutex protecting the control blocks of compressed-only pages /* mutex protecting the control blocks of compressed-only pages
(of type buf_page_t, not buf_block_t) */ (of type buf_page_t, not buf_block_t) */
extern mutex_t buf_pool_zip_mutex; extern mutex_t buf_pool_zip_mutex;
......
...@@ -76,7 +76,8 @@ buf_pool_get_oldest_modification(void) ...@@ -76,7 +76,8 @@ buf_pool_get_oldest_modification(void)
buf_page_t* bpage; buf_page_t* bpage;
ib_uint64_t lsn; ib_uint64_t lsn;
buf_pool_mutex_enter(); //buf_pool_mutex_enter();
mutex_enter(&flush_list_mutex);
bpage = UT_LIST_GET_LAST(buf_pool->flush_list); bpage = UT_LIST_GET_LAST(buf_pool->flush_list);
...@@ -87,7 +88,8 @@ buf_pool_get_oldest_modification(void) ...@@ -87,7 +88,8 @@ buf_pool_get_oldest_modification(void)
lsn = bpage->oldest_modification; lsn = bpage->oldest_modification;
} }
buf_pool_mutex_exit(); //buf_pool_mutex_exit();
mutex_exit(&flush_list_mutex);
return(lsn); return(lsn);
} }
...@@ -101,7 +103,8 @@ buf_pool_clock_tic(void) ...@@ -101,7 +103,8 @@ buf_pool_clock_tic(void)
/*====================*/ /*====================*/
/* out: new clock value */ /* out: new clock value */
{ {
ut_ad(buf_pool_mutex_own()); //ut_ad(buf_pool_mutex_own());
ut_ad(mutex_own(&LRU_list_mutex));
buf_pool->ulint_clock++; buf_pool->ulint_clock++;
...@@ -382,7 +385,7 @@ buf_page_set_io_fix( ...@@ -382,7 +385,7 @@ buf_page_set_io_fix(
buf_page_t* bpage, /* in/out: control block */ buf_page_t* bpage, /* in/out: control block */
enum buf_io_fix io_fix) /* in: io_fix state */ enum buf_io_fix io_fix) /* in: io_fix state */
{ {
ut_ad(buf_pool_mutex_own()); //ut_ad(buf_pool_mutex_own());
ut_ad(mutex_own(buf_page_get_mutex(bpage))); ut_ad(mutex_own(buf_page_get_mutex(bpage)));
bpage->io_fix = io_fix; bpage->io_fix = io_fix;
...@@ -410,7 +413,7 @@ buf_page_can_relocate( ...@@ -410,7 +413,7 @@ buf_page_can_relocate(
/*==================*/ /*==================*/
const buf_page_t* bpage) /* control block being relocated */ const buf_page_t* bpage) /* control block being relocated */
{ {
ut_ad(buf_pool_mutex_own()); //ut_ad(buf_pool_mutex_own());
ut_ad(mutex_own(buf_page_get_mutex(bpage))); ut_ad(mutex_own(buf_page_get_mutex(bpage)));
ut_ad(buf_page_in_file(bpage)); ut_ad(buf_page_in_file(bpage));
ut_ad(bpage->in_LRU_list); ut_ad(bpage->in_LRU_list);
...@@ -443,7 +446,8 @@ buf_page_set_old( ...@@ -443,7 +446,8 @@ buf_page_set_old(
ibool old) /* in: old */ ibool old) /* in: old */
{ {
ut_a(buf_page_in_file(bpage)); ut_a(buf_page_in_file(bpage));
ut_ad(buf_pool_mutex_own()); //ut_ad(buf_pool_mutex_own());
ut_ad(mutex_own(&LRU_list_mutex));
ut_ad(bpage->in_LRU_list); ut_ad(bpage->in_LRU_list);
#ifdef UNIV_LRU_DEBUG #ifdef UNIV_LRU_DEBUG
...@@ -659,9 +663,9 @@ buf_frame_get_page_zip( ...@@ -659,9 +663,9 @@ buf_frame_get_page_zip(
const byte* ptr) /* in: pointer to the page */ const byte* ptr) /* in: pointer to the page */
{ {
const page_zip_des_t* page_zip; const page_zip_des_t* page_zip;
buf_pool_mutex_enter(); //buf_pool_mutex_enter();
page_zip = buf_block_get_page_zip(buf_block_align(ptr)); page_zip = buf_block_get_page_zip(buf_block_align(ptr));
buf_pool_mutex_exit(); //buf_pool_mutex_exit();
return(page_zip); return(page_zip);
} }
#endif /* UNIV_DEBUG || UNIV_ZIP_DEBUG */ #endif /* UNIV_DEBUG || UNIV_ZIP_DEBUG */
...@@ -726,7 +730,7 @@ buf_block_free( ...@@ -726,7 +730,7 @@ buf_block_free(
/*===========*/ /*===========*/
buf_block_t* block) /* in, own: block to be freed */ buf_block_t* block) /* in, own: block to be freed */
{ {
buf_pool_mutex_enter(); //buf_pool_mutex_enter();
mutex_enter(&block->mutex); mutex_enter(&block->mutex);
...@@ -736,7 +740,7 @@ buf_block_free( ...@@ -736,7 +740,7 @@ buf_block_free(
mutex_exit(&block->mutex); mutex_exit(&block->mutex);
buf_pool_mutex_exit(); //buf_pool_mutex_exit();
} }
/************************************************************************* /*************************************************************************
...@@ -781,14 +785,17 @@ buf_page_io_query( ...@@ -781,14 +785,17 @@ buf_page_io_query(
buf_page_t* bpage) /* in: buf_pool block, must be bufferfixed */ buf_page_t* bpage) /* in: buf_pool block, must be bufferfixed */
{ {
ibool io_fixed; ibool io_fixed;
mutex_t* block_mutex = buf_page_get_mutex(bpage);
buf_pool_mutex_enter(); //buf_pool_mutex_enter();
mutex_enter(block_mutex);
ut_ad(buf_page_in_file(bpage)); ut_ad(buf_page_in_file(bpage));
ut_ad(bpage->buf_fix_count > 0); ut_ad(bpage->buf_fix_count > 0);
io_fixed = buf_page_get_io_fix(bpage) != BUF_IO_NONE; io_fixed = buf_page_get_io_fix(bpage) != BUF_IO_NONE;
buf_pool_mutex_exit(); //buf_pool_mutex_exit();
mutex_exit(block_mutex);
return(io_fixed); return(io_fixed);
} }
...@@ -805,8 +812,10 @@ buf_page_get_newest_modification( ...@@ -805,8 +812,10 @@ buf_page_get_newest_modification(
page frame */ page frame */
{ {
ib_uint64_t lsn; ib_uint64_t lsn;
mutex_t* block_mutex = buf_page_get_mutex(bpage);
buf_pool_mutex_enter(); //buf_pool_mutex_enter();
mutex_enter(block_mutex);
if (buf_page_in_file(bpage)) { if (buf_page_in_file(bpage)) {
lsn = bpage->newest_modification; lsn = bpage->newest_modification;
...@@ -814,7 +823,8 @@ buf_page_get_newest_modification( ...@@ -814,7 +823,8 @@ buf_page_get_newest_modification(
lsn = 0; lsn = 0;
} }
buf_pool_mutex_exit(); //buf_pool_mutex_exit();
mutex_exit(block_mutex);
return(lsn); return(lsn);
} }
...@@ -914,7 +924,8 @@ buf_page_hash_get( ...@@ -914,7 +924,8 @@ buf_page_hash_get(
ulint fold; ulint fold;
ut_ad(buf_pool); ut_ad(buf_pool);
ut_ad(buf_pool_mutex_own()); //ut_ad(buf_pool_mutex_own());
ut_ad(mutex_own(&page_hash_mutex));
/* Look for the page in the hash table */ /* Look for the page in the hash table */
...@@ -961,11 +972,13 @@ buf_page_peek( ...@@ -961,11 +972,13 @@ buf_page_peek(
{ {
const buf_page_t* bpage; const buf_page_t* bpage;
buf_pool_mutex_enter(); //buf_pool_mutex_enter();
mutex_enter(&page_hash_mutex);
bpage = buf_page_hash_get(space, offset); bpage = buf_page_hash_get(space, offset);
buf_pool_mutex_exit(); //buf_pool_mutex_exit();
mutex_exit(&page_hash_mutex);
return(bpage != NULL); return(bpage != NULL);
} }
...@@ -1028,9 +1041,11 @@ buf_page_release( ...@@ -1028,9 +1041,11 @@ buf_page_release(
ut_a(block->page.buf_fix_count > 0); ut_a(block->page.buf_fix_count > 0);
if (rw_latch == RW_X_LATCH && mtr->modifications) { if (rw_latch == RW_X_LATCH && mtr->modifications) {
buf_pool_mutex_enter(); //buf_pool_mutex_enter();
mutex_enter(&flush_list_mutex);
buf_flush_note_modification(block, mtr); buf_flush_note_modification(block, mtr);
buf_pool_mutex_exit(); //buf_pool_mutex_exit();
mutex_exit(&flush_list_mutex);
} }
mutex_enter(&block->mutex); mutex_enter(&block->mutex);
......
...@@ -36,7 +36,8 @@ buf_flush_note_modification( ...@@ -36,7 +36,8 @@ buf_flush_note_modification(
#ifdef UNIV_SYNC_DEBUG #ifdef UNIV_SYNC_DEBUG
ut_ad(rw_lock_own(&(block->lock), RW_LOCK_EX)); ut_ad(rw_lock_own(&(block->lock), RW_LOCK_EX));
#endif /* UNIV_SYNC_DEBUG */ #endif /* UNIV_SYNC_DEBUG */
ut_ad(buf_pool_mutex_own()); //ut_ad(buf_pool_mutex_own());
ut_ad(mutex_own(&flush_list_mutex));
ut_ad(mtr->start_lsn != 0); ut_ad(mtr->start_lsn != 0);
ut_ad(mtr->modifications); ut_ad(mtr->modifications);
...@@ -76,7 +77,8 @@ buf_flush_recv_note_modification( ...@@ -76,7 +77,8 @@ buf_flush_recv_note_modification(
ut_ad(rw_lock_own(&(block->lock), RW_LOCK_EX)); ut_ad(rw_lock_own(&(block->lock), RW_LOCK_EX));
#endif /* UNIV_SYNC_DEBUG */ #endif /* UNIV_SYNC_DEBUG */
buf_pool_mutex_enter(); //buf_pool_mutex_enter();
mutex_enter(&flush_list_mutex);
ut_ad(block->page.newest_modification <= end_lsn); ut_ad(block->page.newest_modification <= end_lsn);
...@@ -93,5 +95,6 @@ buf_flush_recv_note_modification( ...@@ -93,5 +95,6 @@ buf_flush_recv_note_modification(
ut_ad(block->page.oldest_modification <= start_lsn); ut_ad(block->page.oldest_modification <= start_lsn);
} }
buf_pool_mutex_exit(); //buf_pool_mutex_exit();
mutex_exit(&flush_list_mutex);
} }
...@@ -191,10 +191,10 @@ mlog_write_initial_log_record_fast( ...@@ -191,10 +191,10 @@ mlog_write_initial_log_record_fast(
#endif #endif
#ifdef UNIV_DEBUG #ifdef UNIV_DEBUG
buf_pool_mutex_enter(); //buf_pool_mutex_enter();
/* We now assume that all x-latched pages have been modified! */ /* We now assume that all x-latched pages have been modified! */
block = (buf_block_t*) buf_block_align(ptr); block = (buf_block_t*) buf_block_align(ptr);
buf_pool_mutex_exit(); //buf_pool_mutex_exit();
if (!mtr_memo_contains(mtr, block, MTR_MEMO_MODIFY)) { if (!mtr_memo_contains(mtr, block, MTR_MEMO_MODIFY)) {
......
...@@ -139,9 +139,9 @@ row_upd_rec_sys_fields( ...@@ -139,9 +139,9 @@ row_upd_rec_sys_fields(
ut_ad(rec_offs_validate(rec, index, offsets)); ut_ad(rec_offs_validate(rec, index, offsets));
#ifdef UNIV_SYNC_DEBUG #ifdef UNIV_SYNC_DEBUG
if (!rw_lock_own(&btr_search_latch, RW_LOCK_EX)) { if (!rw_lock_own(&btr_search_latch, RW_LOCK_EX)) {
buf_pool_mutex_enter(); //buf_pool_mutex_enter();
ut_ad(!buf_block_align(rec)->is_hashed); ut_ad(!buf_block_align(rec)->is_hashed);
buf_pool_mutex_exit(); //buf_pool_mutex_exit();
} }
#endif /* UNIV_SYNC_DEBUG */ #endif /* UNIV_SYNC_DEBUG */
......
...@@ -12,7 +12,7 @@ Created 1/20/1994 Heikki Tuuri ...@@ -12,7 +12,7 @@ Created 1/20/1994 Heikki Tuuri
#define INNODB_VERSION_MAJOR 1 #define INNODB_VERSION_MAJOR 1
#define INNODB_VERSION_MINOR 0 #define INNODB_VERSION_MINOR 0
#define INNODB_VERSION_BUGFIX 2 #define INNODB_VERSION_BUGFIX 2
#define PERCONA_INNODB_VERSION 1 #define PERCONA_INNODB_VERSION 2
/* The following is the InnoDB version as shown in /* The following is the InnoDB version as shown in
SELECT plugin_version FROM information_schema.plugins; SELECT plugin_version FROM information_schema.plugins;
......
...@@ -314,9 +314,9 @@ mtr_memo_contains_page( ...@@ -314,9 +314,9 @@ mtr_memo_contains_page(
{ {
ibool ret; ibool ret;
buf_pool_mutex_enter(); //buf_pool_mutex_enter();
ret = mtr_memo_contains(mtr, buf_block_align(ptr), type); ret = mtr_memo_contains(mtr, buf_block_align(ptr), type);
buf_pool_mutex_exit(); //buf_pool_mutex_exit();
return(ret); return(ret);
} }
......
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