summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDair Grant <dair@feralinteractive.com>2015-10-01 13:46:22 +0100
committerAliaksey Kandratsenka <alk@tut.by>2015-10-03 14:50:53 -0700
commitae0a444db06b2327441e6160eafa33d8b7b95629 (patch)
tree034f62a750fc2c383bb2c7a0af37319df74cb646
parentea0b1d315497771d9d077c754fb9d6a92d1c01dc (diff)
downloadgperftools-ae0a444db06b2327441e6160eafa33d8b7b95629.tar.gz
Ensure ThreadCache objects are CACHELINE_ALIGNED.
-rw-r--r--src/base/basictypes.h6
-rw-r--r--src/common.cc6
-rwxr-xr-xsrc/system-alloc.cc7
3 files changed, 9 insertions, 10 deletions
diff --git a/src/base/basictypes.h b/src/base/basictypes.h
index 4779611..997f12c 100644
--- a/src/base/basictypes.h
+++ b/src/base/basictypes.h
@@ -364,6 +364,12 @@ class AssignAttributeStartEnd {
# define CACHELINE_ALIGNED
#endif // defined(HAVE___ATTRIBUTE__) && (__i386__ || __x86_64__)
+// Structure for discovering alignment
+union MemoryAligner {
+ void* p;
+ double d;
+ size_t s;
+} CACHELINE_ALIGNED;
// The following enum should be used only as a constructor argument to indicate
// that the variable has static storage class, and that the constructor should
diff --git a/src/common.cc b/src/common.cc
index 3b66afe..2cf507e 100644
--- a/src/common.cc
+++ b/src/common.cc
@@ -221,9 +221,9 @@ void SizeMap::Init() {
static uint64_t metadata_system_bytes_ = 0;
static const size_t kMetadataAllocChunkSize = 8*1024*1024;
static const size_t kMetadataBigAllocThreshold = kMetadataAllocChunkSize / 8;
-// usually malloc uses larger alignments, but because metadata cannot
-// have and fancy simd types, aligning on pointer size seems fine
-static const size_t kMetadataAllignment = sizeof(void *);
+// As ThreadCache objects are allocated with MetaDataAlloc, and also
+// CACHELINE_ALIGNED, we must use the same alignment as TCMalloc_SystemAlloc.
+static const size_t kMetadataAllignment = sizeof(MemoryAligner);
static char *metadata_chunk_alloc_;
static size_t metadata_chunk_avail_;
diff --git a/src/system-alloc.cc b/src/system-alloc.cc
index e61c087..18c3f02 100755
--- a/src/system-alloc.cc
+++ b/src/system-alloc.cc
@@ -106,13 +106,6 @@ template <> bool CheckAddressBits<8 * sizeof(void*)>(uintptr_t ptr) {
COMPILE_ASSERT(kAddressBits <= 8 * sizeof(void*),
address_bits_larger_than_pointer_size);
-// Structure for discovering alignment
-union MemoryAligner {
- void* p;
- double d;
- size_t s;
-} CACHELINE_ALIGNED;
-
static SpinLock spinlock(SpinLock::LINKER_INITIALIZED);
#if defined(HAVE_MMAP) || defined(MADV_FREE)