Commit 5608a737 authored by Sergey Vojtovich's avatar Sergey Vojtovich

MDEV-10813 - Clean-up InnoDB atomics, memory barriers and mutexes

No point to issue RELEASE memory barrier in os_thread_create_func(): thread
creation is full memory barrier.

No point to issue os_wmb in rw_lock_set_waiter_flag() and
rw_lock_reset_waiter_flag(): this is deadcode and it is unlikely operational
anyway. If atomic builtins are unavailable - memory barriers are most certainly
unavailable too.

RELEASE memory barrier is definitely abused in buf_pool_withdraw_blocks(): most
probably it was supposed to commit volatile variable update, which is not what
memory barriers actually do. To operate properly it needs corresponding ACQUIRE
barrier without an associated atomic operation anyway.

ACQUIRE memory barrier is definitely abused in log_write_up_to(): most probably
it was supposed to synchronize dirty read of log_sys->write_lsn. To operate
properly it needs corresponding RELEASE barrier without an associated atomic
operation anyway.

Removed a bunch of ACQUIRE memory barriers from InnoDB rwlocks. They're
meaningless without corresponding RELEASE memory barriers.

Valid usage example of memory barriers without an associated atomic operation:
http://en.cppreference.com/w/cpp/atomic/atomic_thread_fence
parent f4d885c4
......@@ -2504,7 +2504,6 @@ buf_pool_withdraw_blocks(
/* retry is not needed */
++buf_withdraw_clock;
os_wmb;
return(false);
}
......
......@@ -92,7 +92,6 @@ rw_lock_set_waiter_flag(
my_atomic_storelint(&lock->waiters, 1);
#else /* INNODB_RW_LOCKS_USE_ATOMICS */
lock->waiters = 1;
os_wmb;
#endif /* INNODB_RW_LOCKS_USE_ATOMICS */
}
......@@ -110,7 +109,6 @@ rw_lock_reset_waiter_flag(
my_atomic_storelint(&lock->waiters, 0);
#else /* INNODB_RW_LOCKS_USE_ATOMICS */
lock->waiters = 0;
os_wmb;
#endif /* INNODB_RW_LOCKS_USE_ATOMICS */
}
......@@ -272,7 +270,6 @@ rw_lock_lock_word_decr(
#ifdef INNODB_RW_LOCKS_USE_ATOMICS
lint local_lock_word;
os_rmb;
local_lock_word = lock->lock_word;
while (local_lock_word > threshold) {
if (my_atomic_caslint(&lock->lock_word,
......
......@@ -1247,7 +1247,6 @@ log_write_up_to(
(flush_to_disk == true) case, because the log_mutex
contention also works as the arbitrator for write-IO
(fsync) bandwidth between log files and data files. */
os_rmb;
if (!flush_to_disk && log_sys->write_lsn >= lsn) {
return;
}
......
......@@ -117,9 +117,6 @@ os_thread_create_func(
{
os_thread_id_t new_thread_id;
/* the new thread should look recent changes up here so far. */
os_wmb;
#ifdef _WIN32
HANDLE handle;
......
......@@ -307,7 +307,6 @@ rw_lock_free_func(
/*==============*/
rw_lock_t* lock) /*!< in/out: rw-lock */
{
os_rmb;
ut_ad(rw_lock_validate(lock));
ut_a(lock->lock_word == X_LOCK_DECR);
......@@ -356,7 +355,6 @@ rw_lock_s_lock_spin(
lock_loop:
/* Spin waiting for the writer field to become free */
os_rmb;
HMT_low();
while (i < srv_n_spin_wait_rounds && lock->lock_word <= 0) {
if (srv_spin_wait_delay) {
......@@ -364,7 +362,6 @@ rw_lock_s_lock_spin(
}
i++;
os_rmb;
}
HMT_medium();
......@@ -480,7 +477,6 @@ rw_lock_x_lock_wait_func(
sync_array_t* sync_arr;
uint64_t count_os_wait = 0;
os_rmb;
ut_ad(lock->lock_word <= threshold);
while (lock->lock_word < threshold) {
......@@ -493,7 +489,6 @@ rw_lock_x_lock_wait_func(
if (i < srv_n_spin_wait_rounds) {
i++;
os_rmb;
continue;
}
HMT_medium();
......@@ -596,10 +591,6 @@ rw_lock_x_lock_low(
} else {
os_thread_id_t thread_id = os_thread_get_curr_id();
if (!pass) {
os_rmb;
}
/* Decrement failed: An X or SX lock is held by either
this thread or another. Try to relock. */
if (!pass
......@@ -681,10 +672,6 @@ rw_lock_sx_lock_low(
} else {
os_thread_id_t thread_id = os_thread_get_curr_id();
if (!pass) {
os_rmb;
}
/* Decrement failed: It already has an X or SX lock by this
thread or another thread. If it is this thread, relock,
else fail. */
......@@ -776,7 +763,6 @@ rw_lock_x_lock_func(
} else {
/* Spin waiting for the lock_word to become free */
os_rmb;
HMT_low();
while (i < srv_n_spin_wait_rounds
&& lock->lock_word <= X_LOCK_HALF_DECR) {
......@@ -787,7 +773,6 @@ rw_lock_x_lock_func(
}
i++;
os_rmb;
}
HMT_medium();
......@@ -885,7 +870,6 @@ rw_lock_sx_lock_func(
++spin_wait_count;
/* Spin waiting for the lock_word to become free */
os_rmb;
while (i < srv_n_spin_wait_rounds
&& lock->lock_word <= X_LOCK_HALF_DECR) {
......
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