From db7201c5926fa217b61f3f34adad3978a1c4442f Mon Sep 17 00:00:00 2001 From: "kyle.cao" Date: Wed, 28 Dec 2022 16:17:23 +0800 Subject: [PATCH] Enhance MemoryStats to avoid the false sharing effect on the CPU cache --- src/common/memory/MemoryTracker.h | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/src/common/memory/MemoryTracker.h b/src/common/memory/MemoryTracker.h index 08b8ec7ad56..10022d0596d 100644 --- a/src/common/memory/MemoryTracker.h +++ b/src/common/memory/MemoryTracker.h @@ -11,6 +11,13 @@ namespace nebula { namespace memory { +constexpr size_t +#if defined(__cpp_lib_hardware_interference_size) + L1_CACHE_LINE_SIZE = hardware_destructive_interference_size; +#else + L1_CACHE_LINE_SIZE = 64; +#endif + // Memory stats for each thread. struct ThreadMemoryStats { ThreadMemoryStats(); @@ -114,7 +121,7 @@ class MemoryStats { private: // Global - int64_t limit_{std::numeric_limits::max()}; + alignas(L1_CACHE_LINE_SIZE) int64_t limit_{std::numeric_limits::max()}; std::atomic used_{0}; // Thread Local static thread_local ThreadMemoryStats threadMemoryStats_;