diff --git a/db/db_impl/db_impl.h b/db/db_impl/db_impl.h index 9c07e81fc..c37a46c3e 100644 --- a/db/db_impl/db_impl.h +++ b/db/db_impl/db_impl.h @@ -1187,7 +1187,10 @@ class DBImpl : public DB { // WriteToWAL need different synchronization: log_empty_, alive_log_files_, // logs_, logfile_number_. Refer to the definition of each variable below for // more description. - mutable InstrumentedMutex mutex_; + // + // `mutex_` can be a hot lock in some workloads, so it deserves dedicated + // cachelines. + mutable CacheAlignedInstrumentedMutex mutex_; ColumnFamilyHandleImpl* default_cf_handle_; InternalStats* default_cf_internal_stats_; diff --git a/monitoring/instrumented_mutex.h b/monitoring/instrumented_mutex.h index 1e72815bf..e05c6addd 100644 --- a/monitoring/instrumented_mutex.h +++ b/monitoring/instrumented_mutex.h @@ -51,6 +51,14 @@ class InstrumentedMutex { int stats_code_; }; +class ALIGN_AS(CACHE_LINE_SIZE) CacheAlignedInstrumentedMutex + : public InstrumentedMutex { + using InstrumentedMutex::InstrumentedMutex; + char padding[(CACHE_LINE_SIZE - sizeof(InstrumentedMutex) % CACHE_LINE_SIZE) % + CACHE_LINE_SIZE] ROCKSDB_FIELD_UNUSED; +}; +static_assert(sizeof(CacheAlignedInstrumentedMutex) % CACHE_LINE_SIZE == 0); + // RAII wrapper for InstrumentedMutex class InstrumentedMutexLock { public: