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 ...@@ -214,7 +214,7 @@ struct log_t
private: private:
/** spin lock protecting lsn, buf_free in append_prepare() */ /** 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: public:
/** first free offset within buf use; protected by lsn_lock */ /** first free offset within buf use; protected by lsn_lock */
Atomic_relaxed<size_t> buf_free; Atomic_relaxed<size_t> buf_free;
......
...@@ -520,12 +520,3 @@ typedef srw_lock_impl<false> srw_lock; ...@@ -520,12 +520,3 @@ typedef srw_lock_impl<false> srw_lock;
typedef srw_lock_impl<true> srw_spin_lock; typedef srw_lock_impl<true> srw_spin_lock;
#endif #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() ...@@ -101,6 +101,7 @@ void log_t::create()
ut_ad(!is_initialised()); ut_ad(!is_initialised());
latch.SRW_LOCK_INIT(log_latch_key); latch.SRW_LOCK_INIT(log_latch_key);
lsn_lock.init();
/* LSN 0 and 1 are reserved; @see buf_page_t::oldest_modification_ */ /* LSN 0 and 1 are reserved; @see buf_page_t::oldest_modification_ */
lsn.store(FIRST_LSN, std::memory_order_relaxed); lsn.store(FIRST_LSN, std::memory_order_relaxed);
...@@ -1070,6 +1071,7 @@ void log_t::close() ...@@ -1070,6 +1071,7 @@ void log_t::close()
#endif #endif
latch.destroy(); latch.destroy();
lsn_lock.destroy();
recv_sys.close(); recv_sys.close();
......
...@@ -789,7 +789,7 @@ ATTRIBUTE_COLD static void log_overwrite_warning(lsn_t age, lsn_t capacity) ...@@ -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 ATTRIBUTE_COLD void log_t::append_prepare_wait(bool ex) noexcept
{ {
log_sys.waits++; log_sys.waits++;
log_sys.lsn_lock.unlock(); log_sys.lsn_lock.wr_unlock();
if (ex) if (ex)
log_sys.latch.wr_unlock(); log_sys.latch.wr_unlock();
...@@ -804,7 +804,7 @@ ATTRIBUTE_COLD void log_t::append_prepare_wait(bool ex) noexcept ...@@ -804,7 +804,7 @@ ATTRIBUTE_COLD void log_t::append_prepare_wait(bool ex) noexcept
else else
log_sys.latch.rd_lock(SRW_LOCK_CALL); 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. /** 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 ...@@ -823,7 +823,7 @@ std::pair<lsn_t,byte*> log_t::append_prepare(size_t size, bool ex) noexcept
#endif #endif
const lsn_t checkpoint_margin{last_checkpoint_lsn + log_capacity - size}; const lsn_t checkpoint_margin{last_checkpoint_lsn + log_capacity - size};
const size_t avail{(pmem ? size_t(capacity()) : buf_size) - 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++; write_to_buf++;
for (ut_d(int count= 50); 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 ...@@ -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) if (pmem && new_buf_free >= file_size)
new_buf_free-= size_t(capacity()); new_buf_free-= size_t(capacity());
buf_free= new_buf_free; buf_free= new_buf_free;
lsn_lock.unlock(); lsn_lock.wr_unlock();
if (UNIV_UNLIKELY(l > checkpoint_margin) || if (UNIV_UNLIKELY(l > checkpoint_margin) ||
(!pmem && b >= max_buf_free)) (!pmem && b >= max_buf_free))
......
...@@ -102,13 +102,6 @@ static inline void srw_pause(unsigned delay) ...@@ -102,13 +102,6 @@ static inline void srw_pause(unsigned delay)
HMT_medium(); 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 #ifdef SUX_LOCK_GENERIC
template<> void srw_mutex_impl<true>::wr_wait() 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