Skip to content

Commit

Permalink
Enhance MemoryStats to avoid the false sharing effect on the CPU cache
Browse files Browse the repository at this point in the history
  • Loading branch information
czpmango committed Dec 28, 2022
1 parent b0f42bf commit db7201c
Showing 1 changed file with 8 additions and 1 deletion.
9 changes: 8 additions & 1 deletion src/common/memory/MemoryTracker.h
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down Expand Up @@ -114,7 +121,7 @@ class MemoryStats {

private:
// Global
int64_t limit_{std::numeric_limits<int64_t>::max()};
alignas(L1_CACHE_LINE_SIZE) int64_t limit_{std::numeric_limits<int64_t>::max()};
std::atomic<int64_t> used_{0};
// Thread Local
static thread_local ThreadMemoryStats threadMemoryStats_;
Expand Down

0 comments on commit db7201c

Please sign in to comment.