issue-430: Introduces 8-byte alignment support for tcmalloc

git-svn-id: http://gperftools.googlecode.com/svn/trunk@175 6b5cf1ce-ec42-a296-1ba9-69fdba395a50
This commit is contained in:
chappedm@gmail.com 2012-11-04 18:15:11 +00:00
parent baaf018829
commit abeaf46028
3 changed files with 19 additions and 7 deletions

View File

@ -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);

View File

@ -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;

View File

@ -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++) {