From db7201c5926fa217b61f3f34adad3978a1c4442f Mon Sep 17 00:00:00 2001 From: "kyle.cao" Date: Wed, 28 Dec 2022 16:17:23 +0800 Subject: [PATCH 1/2] 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_; From c89a1218cdc4470f76fa63523fa572a19757ca94 Mon Sep 17 00:00:00 2001 From: "kyle.cao" Date: Wed, 28 Dec 2022 16:44:22 +0800 Subject: [PATCH 2/2] small rename --- src/common/memory/MemoryTracker.h | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/common/memory/MemoryTracker.h b/src/common/memory/MemoryTracker.h index 10022d0596d..d06f3ab7a94 100644 --- a/src/common/memory/MemoryTracker.h +++ b/src/common/memory/MemoryTracker.h @@ -13,9 +13,9 @@ namespace memory { constexpr size_t #if defined(__cpp_lib_hardware_interference_size) - L1_CACHE_LINE_SIZE = hardware_destructive_interference_size; + CACHE_LINE_SIZE = hardware_destructive_interference_size; #else - L1_CACHE_LINE_SIZE = 64; + CACHE_LINE_SIZE = 64; #endif // Memory stats for each thread. @@ -121,7 +121,7 @@ class MemoryStats { private: // Global - alignas(L1_CACHE_LINE_SIZE) int64_t limit_{std::numeric_limits::max()}; + alignas(CACHE_LINE_SIZE) int64_t limit_{std::numeric_limits::max()}; std::atomic used_{0}; // Thread Local static thread_local ThreadMemoryStats threadMemoryStats_;