diff options
author | chappedm@gmail.com <chappedm@gmail.com@6b5cf1ce-ec42-a296-1ba9-69fdba395a50> | 2012-11-04 18:15:11 +0000 |
---|---|---|
committer | chappedm@gmail.com <chappedm@gmail.com@6b5cf1ce-ec42-a296-1ba9-69fdba395a50> | 2012-11-04 18:15:11 +0000 |
commit | abeaf46028c8dfab7e7867ee7a3a49ebe21cf129 (patch) | |
tree | 9bddb1e6d99fd8111aa3629f1083640d9dd0f774 | |
parent | baaf0188295582ca68df03f70baa13d96a88e2eb (diff) | |
download | gperftools-abeaf46028c8dfab7e7867ee7a3a49ebe21cf129.tar.gz |
issue-430: Introduces 8-byte alignment support for tcmalloc
git-svn-id: http://gperftools.googlecode.com/svn/trunk@175 6b5cf1ce-ec42-a296-1ba9-69fdba395a50
-rw-r--r-- | src/common.cc | 8 | ||||
-rw-r--r-- | src/common.h | 11 | ||||
-rw-r--r-- | src/tests/tcmalloc_unittest.cc | 7 |
3 files changed, 19 insertions, 7 deletions
diff --git a/src/common.cc b/src/common.cc index dad7372..d911e36 100644 --- a/src/common.cc +++ b/src/common.cc @@ -60,16 +60,16 @@ int AlignmentForSize(size_t size) { } else if (size >= 128) { // Space wasted due to alignment is at most 1/8, i.e., 12.5%. alignment = (1 << LgFloor(size)) / 8; - } else if (size >= 16) { + } else if (size >= kMinAlign) { // We need an alignment of at least 16 bytes to satisfy // requirements for some SSE types. - alignment = 16; + alignment = kMinAlign; } // Maximum alignment allowed is page size alignment. if (alignment > kPageSize) { alignment = kPageSize; } - CHECK_CONDITION(size < 16 || alignment >= 16); + CHECK_CONDITION(size < kMinAlign || alignment >= kMinAlign); CHECK_CONDITION((alignment & (alignment - 1)) == 0); return alignment; } @@ -110,7 +110,7 @@ void SizeMap::Init() { // Compute the size classes we want to use int sc = 1; // Next size class to assign int alignment = kAlignment; - CHECK_CONDITION(kAlignment <= 16); + CHECK_CONDITION(kAlignment <= kMinAlign); for (size_t size = kAlignment; size <= kMaxSize; size += alignment) { alignment = AlignmentForSize(size); CHECK_CONDITION((size % alignment) == 0); diff --git a/src/common.h b/src/common.h index f6d1cd6..8987255 100644 --- a/src/common.h +++ b/src/common.h @@ -64,12 +64,23 @@ typedef uintptr_t Length; #if defined(TCMALLOC_LARGE_PAGES) static const size_t kPageShift = 15; static const size_t kNumClasses = 78; +static const size_t kMinAlign = 16; #elif defined(TCMALLOC_LARGE_PAGES64K) static const size_t kPageShift = 16; static const size_t kNumClasses = 82; +static const size_t kMinAlign = 16; +#elif defined(TCMALLOC_ALIGN_8BYTES) +static const size_t kPageShift = 13; +static const size_t kNumClasses = 93; +// Unless we force to use 8 bytes alignment we use an alignment of +// at least 16 bytes to statisfy requirements for some SSE types. +// Keep in mind when using the 16 bytes alignment you can have a space +// waste due alignment of 25%. (eg malloc of 24 bytes will get 32 bytes) +static const size_t kMinAlign = 8; #else static const size_t kPageShift = 13; static const size_t kNumClasses = 86; +static const size_t kMinAlign = 16; #endif static const size_t kMaxThreadCacheSize = 4 << 20; diff --git a/src/tests/tcmalloc_unittest.cc b/src/tests/tcmalloc_unittest.cc index 079cad2..e9526ae 100644 --- a/src/tests/tcmalloc_unittest.cc +++ b/src/tests/tcmalloc_unittest.cc @@ -759,9 +759,10 @@ static void TestAlignmentForSize(int size) { CHECK((p % sizeof(void*)) == 0); CHECK((p % sizeof(double)) == 0); - // Must have 16-byte alignment for large enough objects - if (size >= 16) { - CHECK((p % 16) == 0); + // Must have 16-byte (or 8-byte in case of -DTCMALLOC_ALIGN_8BYTES) + // alignment for large enough objects + if (size >= kMinAlign) { + CHECK((p % kMinAlign) == 0); } } for (int i = 0; i < kNum; i++) { |