Commit bd70ae05 authored by Marko Mäkelä's avatar Marko Mäkelä

MDEV-27774 fixup: Replace sspin_lock with srw_lock

srw_lock in log_sys.append_prepare() turned out to yield best throughput.
We might try a NUMA aware spin lock implementation later.
parent a635c406
......@@ -214,7 +214,7 @@ struct log_t
private:
/** spin lock protecting lsn, buf_free in append_prepare() */
MY_ALIGNED(CPU_LEVEL1_DCACHE_LINESIZE) sspin_lock lsn_lock;
MY_ALIGNED(CPU_LEVEL1_DCACHE_LINESIZE) srw_mutex lsn_lock;
public:
/** first free offset within buf use; protected by lsn_lock */
Atomic_relaxed<size_t> buf_free;
......
......@@ -520,12 +520,3 @@ typedef srw_lock_impl<false> srw_lock;
typedef srw_lock_impl<true> srw_spin_lock;
#endif
/** Simple spin lock */
struct sspin_lock
{
std::atomic<uint32_t> word{0};
void lock() noexcept;
void unlock() noexcept
{ ut_ad(word); word.store(0, std::memory_order_release); }
};
......@@ -101,6 +101,7 @@ void log_t::create()
ut_ad(!is_initialised());
latch.SRW_LOCK_INIT(log_latch_key);
lsn_lock.init();
/* LSN 0 and 1 are reserved; @see buf_page_t::oldest_modification_ */
lsn.store(FIRST_LSN, std::memory_order_relaxed);
......@@ -1070,6 +1071,7 @@ void log_t::close()
#endif
latch.destroy();
lsn_lock.destroy();
recv_sys.close();
......
......@@ -789,7 +789,7 @@ ATTRIBUTE_COLD static void log_overwrite_warning(lsn_t age, lsn_t capacity)
ATTRIBUTE_COLD void log_t::append_prepare_wait(bool ex) noexcept
{
log_sys.waits++;
log_sys.lsn_lock.unlock();
log_sys.lsn_lock.wr_unlock();
if (ex)
log_sys.latch.wr_unlock();
......@@ -804,7 +804,7 @@ ATTRIBUTE_COLD void log_t::append_prepare_wait(bool ex) noexcept
else
log_sys.latch.rd_lock(SRW_LOCK_CALL);
log_sys.lsn_lock.lock();
log_sys.lsn_lock.wr_lock();
}
/** Reserve space in the log buffer for appending data.
......@@ -823,7 +823,7 @@ std::pair<lsn_t,byte*> log_t::append_prepare(size_t size, bool ex) noexcept
#endif
const lsn_t checkpoint_margin{last_checkpoint_lsn + log_capacity - size};
const size_t avail{(pmem ? size_t(capacity()) : buf_size) - size};
lsn_lock.lock();
lsn_lock.wr_lock(); /* Just use SRWLOCK or pthread_mutex_t */
write_to_buf++;
for (ut_d(int count= 50);
......@@ -844,7 +844,7 @@ std::pair<lsn_t,byte*> log_t::append_prepare(size_t size, bool ex) noexcept
if (pmem && new_buf_free >= file_size)
new_buf_free-= size_t(capacity());
buf_free= new_buf_free;
lsn_lock.unlock();
lsn_lock.wr_unlock();
if (UNIV_UNLIKELY(l > checkpoint_margin) ||
(!pmem && b >= max_buf_free))
......
......@@ -102,13 +102,6 @@ static inline void srw_pause(unsigned delay)
HMT_medium();
}
void sspin_lock::lock() noexcept
{
while (word.exchange(true, std::memory_order_acquire))
while (word.load(std::memory_order_relaxed))
srw_pause(1);
}
#ifdef SUX_LOCK_GENERIC
template<> void srw_mutex_impl<true>::wr_wait()
{
......
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