summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--include/my_counter.h2
-rw-r--r--storage/innobase/buf/buf0buf.cc36
-rw-r--r--storage/innobase/buf/buf0lru.cc2
-rw-r--r--storage/innobase/include/buf0buf.h44
-rw-r--r--storage/innobase/include/buf0buf.ic53
-rw-r--r--storage/innobase/include/mtr0mtr.ic2
-rw-r--r--storage/innobase/mtr/mtr0mtr.cc4
7 files changed, 39 insertions, 104 deletions
diff --git a/include/my_counter.h b/include/my_counter.h
index 68c04fb3f1d..c5cbe296df0 100644
--- a/include/my_counter.h
+++ b/include/my_counter.h
@@ -28,6 +28,8 @@ template <typename Type> class Atomic_counter
Type sub(Type i) { return m_counter.fetch_sub(i, std::memory_order_relaxed); }
public:
+ Atomic_counter(const Atomic_counter<Type> &rhs)
+ { m_counter.store(rhs, std::memory_order_relaxed); }
Atomic_counter(Type val): m_counter(val) {}
Atomic_counter() {}
diff --git a/storage/innobase/buf/buf0buf.cc b/storage/innobase/buf/buf0buf.cc
index 4bfcdb27f76..dd2e45791f6 100644
--- a/storage/innobase/buf/buf0buf.cc
+++ b/storage/innobase/buf/buf0buf.cc
@@ -3404,7 +3404,7 @@ page_found:
}
/* Add to an existing watch. */
- buf_block_fix(bpage);
+ bpage->fix();
return(NULL);
}
@@ -3544,7 +3544,7 @@ void buf_pool_watch_unset(const page_id_t page_id)
increments buf_fix_count. */
bpage = buf_page_hash_get_low(buf_pool, page_id);
- if (buf_block_unfix(bpage) == 0
+ if (bpage->unfix() == 0
&& buf_pool_watch_is_sentinel(buf_pool, bpage)) {
buf_pool_watch_remove(buf_pool, bpage);
}
@@ -3777,7 +3777,7 @@ err_exit:
case BUF_BLOCK_ZIP_PAGE:
case BUF_BLOCK_ZIP_DIRTY:
- buf_block_fix(bpage);
+ bpage->fix();
block_mutex = &buf_pool->zip_mutex;
mutex_enter(block_mutex);
goto got_block;
@@ -4296,10 +4296,10 @@ loop:
= buf_page_get_mutex(
&fix_block->page);
mutex_enter(fix_mutex);
- buf_block_fix(fix_block);
+ fix_block->fix();
mutex_exit(fix_mutex);
} else {
- buf_block_fix(fix_block);
+ fix_block->fix();
}
/* Now safe to release page_hash mutex */
@@ -4406,10 +4406,10 @@ loop:
BPageMutex* fix_mutex = buf_page_get_mutex(
&fix_block->page);
mutex_enter(fix_mutex);
- buf_block_fix(fix_block);
+ fix_block->fix();
mutex_exit(fix_mutex);
} else {
- buf_block_fix(fix_block);
+ fix_block->fix();
}
/* Now safe to release page_hash mutex */
@@ -4432,7 +4432,7 @@ got_block:
/* The page is being read to buffer pool,
but we cannot wait around for the read to
complete. */
- buf_block_unfix(fix_block);
+ fix_block->unfix();
return(NULL);
}
@@ -4448,7 +4448,7 @@ got_block:
/* This suggests that the page is being flushed.
Avoid returning reference to this page.
Instead wait for the flush action to complete. */
- buf_block_unfix(fix_block);
+ fix_block->unfix();
os_thread_sleep(WAIT_FOR_WRITE);
goto loop;
}
@@ -4457,7 +4457,7 @@ got_block:
evict_from_pool:
ut_ad(!fix_block->page.oldest_modification);
buf_pool_mutex_enter(buf_pool);
- buf_block_unfix(fix_block);
+ fix_block->unfix();
if (!buf_LRU_free_page(&fix_block->page, true)) {
ut_ad(0);
@@ -4475,7 +4475,7 @@ evict_from_pool:
adaptive hash index. There cannot be an
adaptive hash index for a compressed-only
page, so do not bother decompressing the page. */
- buf_block_unfix(fix_block);
+ fix_block->unfix();
return(NULL);
}
@@ -4489,7 +4489,7 @@ evict_from_pool:
/* This condition often occurs when the buffer
is not buffer-fixed, but I/O-fixed by
buf_page_init_for_read(). */
- buf_block_unfix(fix_block);
+ fix_block->unfix();
/* The block is buffer-fixed or I/O-fixed.
Try again later. */
@@ -4518,7 +4518,7 @@ evict_from_pool:
/* Buffer-fixing prevents the page_hash from changing. */
ut_ad(bpage == buf_page_hash_get_low(buf_pool, page_id));
- buf_block_unfix(fix_block);
+ fix_block->unfix();
buf_page_mutex_enter(block);
mutex_enter(&buf_pool->zip_mutex);
@@ -4610,7 +4610,7 @@ evict_from_pool:
buf_page_mutex_exit(fix_block);
--buf_pool->n_pend_unzip;
- buf_block_unfix(fix_block);
+ fix_block->unfix();
buf_pool_mutex_exit(buf_pool);
rw_lock_x_unlock(&fix_block->lock);
@@ -4673,7 +4673,7 @@ evict_from_pool:
buf_pool_mutex_enter(buf_pool);
- buf_block_unfix(fix_block);
+ fix_block->unfix();
/* Now we are only holding the buf_pool->mutex,
not block->mutex or hash_lock. Blocks cannot be
@@ -4732,7 +4732,7 @@ evict_from_pool:
buf_page_mutex_exit(fix_block);
- buf_block_fix(fix_block);
+ fix_block->fix();
/* Failed to evict the page; change it directly */
@@ -5233,7 +5233,7 @@ buf_page_init(
ut_a(buf_fix_count > 0);
- my_atomic_add32((int32*) &block->page.buf_fix_count, buf_fix_count);
+ block->page.buf_fix_count += buf_fix_count;
buf_pool_watch_remove(buf_pool, hash_page);
} else {
@@ -5474,7 +5474,7 @@ buf_page_init_for_read(
ut_a(buf_fix_count > 0);
- my_atomic_add32((int32*) &bpage->buf_fix_count, buf_fix_count);
+ bpage->buf_fix_count += buf_fix_count;
ut_ad(buf_pool_watch_is_sentinel(buf_pool, watch_page));
buf_pool_watch_remove(buf_pool, watch_page);
diff --git a/storage/innobase/buf/buf0lru.cc b/storage/innobase/buf/buf0lru.cc
index 859d5ece06a..9baa299910a 100644
--- a/storage/innobase/buf/buf0lru.cc
+++ b/storage/innobase/buf/buf0lru.cc
@@ -2459,7 +2459,7 @@ buf_LRU_print_instance(
if (bpage->buf_fix_count) {
fprintf(stderr, "buffix count %u ",
- bpage->buf_fix_count);
+ uint32_t(bpage->buf_fix_count));
}
if (buf_page_get_io_fix(bpage)) {
diff --git a/storage/innobase/include/buf0buf.h b/storage/innobase/include/buf0buf.h
index d4157fbd040..e1a6efecf9f 100644
--- a/storage/innobase/include/buf0buf.h
+++ b/storage/innobase/include/buf0buf.h
@@ -665,37 +665,6 @@ buf_block_buf_fix_inc_func(
buf_block_t* block) /*!< in/out: block to bufferfix */
MY_ATTRIBUTE((nonnull));
-/** Increments the bufferfix count.
-@param[in,out] bpage block to bufferfix
-@return the count */
-UNIV_INLINE
-ulint
-buf_block_fix(
- buf_page_t* bpage);
-
-/** Increments the bufferfix count.
-@param[in,out] block block to bufferfix
-@return the count */
-UNIV_INLINE
-ulint
-buf_block_fix(
- buf_block_t* block);
-
-/** Decrements the bufferfix count.
-@param[in,out] bpage block to bufferunfix
-@return the remaining buffer-fix count */
-UNIV_INLINE
-ulint
-buf_block_unfix(
- buf_page_t* bpage);
-/** Decrements the bufferfix count.
-@param[in,out] block block to bufferunfix
-@return the remaining buffer-fix count */
-UNIV_INLINE
-ulint
-buf_block_unfix(
- buf_block_t* block);
-
# ifdef UNIV_DEBUG
/** Increments the bufferfix count.
@param[in,out] b block to bufferfix
@@ -1490,7 +1459,7 @@ public:
page_size_t size;
/** Count of how manyfold this block is currently bufferfixed. */
- ib_uint32_t buf_fix_count;
+ Atomic_counter<uint32_t> buf_fix_count;
/** type of pending I/O operation; also protected by
buf_pool->mutex for writes only */
@@ -1645,6 +1614,14 @@ public:
protected by buf_pool->zip_mutex
or buf_block_t::mutex. */
# endif /* UNIV_DEBUG */
+
+ void fix() { buf_fix_count++; }
+ uint32_t unfix()
+ {
+ uint32_t count= buf_fix_count--;
+ ut_ad(count != 0);
+ return count - 1;
+ }
};
/** The buffer control block structure */
@@ -1808,6 +1785,9 @@ struct buf_block_t{
and accessed; we introduce this new
mutex in InnoDB-5.1 to relieve
contention on the buffer pool mutex */
+
+ void fix() { page.fix(); }
+ uint32_t unfix() { return page.unfix(); }
};
/** Check if a buf_block_t object is in a valid state
diff --git a/storage/innobase/include/buf0buf.ic b/storage/innobase/include/buf0buf.ic
index 0908a7cf574..2169eedd015 100644
--- a/storage/innobase/include/buf0buf.ic
+++ b/storage/innobase/include/buf0buf.ic
@@ -945,28 +945,6 @@ buf_block_get_modify_clock(
return(block->modify_clock);
}
-/** Increments the bufferfix count.
-@param[in,out] bpage block to bufferfix
-@return the count */
-UNIV_INLINE
-ulint
-buf_block_fix(
- buf_page_t* bpage)
-{
- return uint32(my_atomic_add32((int32*) &bpage->buf_fix_count, 1) + 1);
-}
-
-/** Increments the bufferfix count.
-@param[in,out] block block to bufferfix
-@return the count */
-UNIV_INLINE
-ulint
-buf_block_fix(
- buf_block_t* block)
-{
- return(buf_block_fix(&block->page));
-}
-
/*******************************************************************//**
Increments the bufferfix count. */
UNIV_INLINE
@@ -990,32 +968,7 @@ buf_block_buf_fix_inc_func(
}
#endif /* UNIV_DEBUG */
- buf_block_fix(block);
-}
-
-/** Decrements the bufferfix count.
-@param[in,out] bpage block to bufferunfix
-@return the remaining buffer-fix count */
-UNIV_INLINE
-ulint
-buf_block_unfix(
- buf_page_t* bpage)
-{
- uint32 count = uint32(my_atomic_add32((int32*) &bpage->buf_fix_count,
- -1));
- ut_ad(count != 0);
- return count - 1;
-}
-
-/** Decrements the bufferfix count.
-@param[in,out] block block to bufferunfix
-@return the remaining buffer-fix count */
-UNIV_INLINE
-ulint
-buf_block_unfix(
- buf_block_t* block)
-{
- return(buf_block_unfix(&block->page));
+ block->fix();
}
/*******************************************************************//**
@@ -1026,7 +979,7 @@ buf_block_buf_fix_dec(
/*==================*/
buf_block_t* block) /*!< in/out: block to bufferunfix */
{
- buf_block_unfix(block);
+ block->unfix();
#ifdef UNIV_DEBUG
/* No debug latch is acquired if block belongs to system temporary.
@@ -1283,7 +1236,7 @@ buf_page_release_zip(
/* Fall through */
case BUF_BLOCK_ZIP_PAGE:
case BUF_BLOCK_ZIP_DIRTY:
- buf_block_unfix(reinterpret_cast<buf_block_t*>(bpage));
+ reinterpret_cast<buf_block_t*>(bpage)->unfix();
return;
case BUF_BLOCK_POOL_WATCH:
diff --git a/storage/innobase/include/mtr0mtr.ic b/storage/innobase/include/mtr0mtr.ic
index 82f552f22ce..5213f90d966 100644
--- a/storage/innobase/include/mtr0mtr.ic
+++ b/storage/innobase/include/mtr0mtr.ic
@@ -170,7 +170,7 @@ mtr_t::release_block_at_savepoint(
ut_a(slot->object == block);
- buf_block_unfix(reinterpret_cast<buf_block_t*>(block));
+ reinterpret_cast<buf_block_t*>(block)->unfix();
buf_page_release_latch(block, slot->type);
diff --git a/storage/innobase/mtr/mtr0mtr.cc b/storage/innobase/mtr/mtr0mtr.cc
index 110ed45056f..13934546448 100644
--- a/storage/innobase/mtr/mtr0mtr.cc
+++ b/storage/innobase/mtr/mtr0mtr.cc
@@ -191,7 +191,7 @@ memo_slot_release(mtr_memo_slot_t* slot)
block = reinterpret_cast<buf_block_t*>(slot->object);
- buf_block_unfix(block);
+ block->unfix();
buf_page_release_latch(block, slot->type);
break;
}
@@ -228,7 +228,7 @@ memo_block_unfix(mtr_memo_slot_t* slot)
case MTR_MEMO_PAGE_S_FIX:
case MTR_MEMO_PAGE_X_FIX:
case MTR_MEMO_PAGE_SX_FIX: {
- buf_block_unfix(reinterpret_cast<buf_block_t*>(slot->object));
+ reinterpret_cast<buf_block_t*>(slot->object)->unfix();
break;
}