Commit b00b32c7 authored by Vadim Tkachenko's avatar Vadim Tkachenko

sync with extensions rev18

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