From a05bab586a69f0de5ad4f6206ab682df0ed65d62 Mon Sep 17 00:00:00 2001 From: Aliaksey Kandratsenka Date: Sun, 4 Feb 2024 19:33:12 -0500 Subject: [PATCH] align CentralFreeList on cache line size instead of just 64 We had hardcoded size alignment on 64 bytes, seemingly to avoid cacheline contention when taking per-size-class central free list locks. But it makes more sense to do platform specific alignment. I did consider std::hardware_constructive_interference_size, but practical values seem to differ from what we have configured at least on some platforms. --- src/central_freelist.h | 2 +- src/static_vars.cc | 3 +-- 2 files changed, 2 insertions(+), 3 deletions(-) diff --git a/src/central_freelist.h b/src/central_freelist.h index 8464724..2eaecfb 100644 --- a/src/central_freelist.h +++ b/src/central_freelist.h @@ -45,7 +45,7 @@ namespace tcmalloc { // Data kept per size-class in central cache. -class alignas(64) CentralFreeList { +class CACHELINE_ALIGNED CentralFreeList { public: constexpr CentralFreeList() {} diff --git a/src/static_vars.cc b/src/static_vars.cc index 3a0b802..6b7fc8a 100644 --- a/src/static_vars.cc +++ b/src/static_vars.cc @@ -60,8 +60,7 @@ void Static::InitStaticVars() { span_allocator_.New(); // Reduce cache conflicts span_allocator_.New(); // Reduce cache conflicts stacktrace_allocator_.Init(); - // Do a bit of sanitizing: make sure central_cache is aligned properly - CHECK_CONDITION((sizeof(central_cache_[0]) % 64) == 0); + for (int i = 0; i < num_size_classes(); ++i) { central_cache_[i].Init(i); }