From 15348ff994e678d2873473eb27fa8be9d6f7ceea Mon Sep 17 00:00:00 2001 From: Yannay Date: Fri, 5 Apr 2024 20:05:49 +0300 Subject: [PATCH] fix: put key_gen_ in a separate cache line Prevents false sharing when one thread writes to key_gen_ and others read other class members (that reside on the same cache line) --- benchmark/DB_oindex.hh | 11 ++++++++--- benchmark/DB_uindex.hh | 11 ++++++++--- 2 files changed, 16 insertions(+), 6 deletions(-) diff --git a/benchmark/DB_oindex.hh b/benchmark/DB_oindex.hh index b59f0910..9ec25ea1 100644 --- a/benchmark/DB_oindex.hh +++ b/benchmark/DB_oindex.hh @@ -773,7 +773,10 @@ protected: private: table_type table_; - uint64_t key_gen_; + union alignas(CACHE_LINE_SIZE) { + uint64_t key_gen_; + uint8_t _[CACHE_LINE_SIZE]; + }; static bool access_all(std::array& cell_accesses, std::array&, std::array&, internal_elem*) { // always_assert(false, "Not implemented."); diff --git a/benchmark/DB_uindex.hh b/benchmark/DB_uindex.hh index 8c4c75c9..8a3700b6 100644 --- a/benchmark/DB_uindex.hh +++ b/benchmark/DB_uindex.hh @@ -84,8 +84,10 @@ private: Hash hasher_; Pred pred_; - uint64_t key_gen_; - + union alignas(CACHE_LINE_SIZE) { + uint64_t key_gen_; + uint8_t _[CACHE_LINE_SIZE]; + }; // used to mark whether a key is a bucket (for bucket version checks) // or a pointer (which will always have the lower 3 bits as 0) static constexpr uintptr_t bucket_bit = C::item_key_tag; @@ -681,7 +683,10 @@ private: Hash hasher_; Pred pred_; - uint64_t key_gen_; + union alignas(CACHE_LINE_SIZE) { + uint64_t key_gen_; + uint8_t _[CACHE_LINE_SIZE]; + }; // used to mark whether a key is a bucket (for bucket version checks) // or a pointer (which will always have the lower 3 bits as 0)