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
vesoft-inc#2038)

* Enhance MemoryStats to avoid the false sharing effect on the CPU cache

* small rename

Co-authored-by: Sophie <84560950+Sophie-Xie@users.noreply.github.com>

Co-authored-by: kyle.cao <kyle.cao@vesoft.com>
Co-authored-by: Sophie <84560950+Sophie-Xie@users.noreply.github.com>
  • Loading branch information
3 people authored Dec 28, 2022
1 parent 225f618 commit dfbb392
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)
CACHE_LINE_SIZE = hardware_destructive_interference_size;
#else
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(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 dfbb392

Please sign in to comment.