Chromium Code Reviews| Index: third_party/tcmalloc/chromium/src/common.cc |
| diff --git a/third_party/tcmalloc/chromium/src/common.cc b/third_party/tcmalloc/chromium/src/common.cc |
| index 69514b6f4d08f5363015c4f98754312d8465367f..dd175f223692a5adb37048140b30422bae79fe40 100644 |
| --- a/third_party/tcmalloc/chromium/src/common.cc |
| +++ b/third_party/tcmalloc/chromium/src/common.cc |
| @@ -58,9 +58,9 @@ static inline int LgFloor(size_t n) { |
| int AlignmentForSize(size_t size) { |
| int alignment = kAlignment; |
| - if (size >= 2048) { |
| - // Cap alignment at 256 for large sizes. |
| - alignment = 256; |
| + if (size > kMaxSize) { |
| + // Cap alignment at kPageSize for large sizes. |
| + alignment = kPageSize; |
| } else if (size >= 128) { |
| // Space wasted due to alignment is at most 1/8, i.e., 12.5%. |
| alignment = (1 << LgFloor(size)) / 8; |
| @@ -69,6 +69,10 @@ int AlignmentForSize(size_t size) { |
| // requirements for some SSE types. |
| alignment = 16; |
| } |
| + // Maximum alignment allowed is page size alignment. |
| + if (alignment > kPageSize) { |
| + alignment = kPageSize; |
| + } |
| CHECK_CONDITION(size < 16 || alignment >= 16); |
| CHECK_CONDITION((alignment & (alignment - 1)) == 0); |
| return alignment; |
| @@ -99,32 +103,35 @@ int SizeMap::NumMoveSize(size_t size) { |
| void SizeMap::Init() { |
| // Do some sanity checking on add_amount[]/shift_amount[]/class_array[] |
| if (ClassIndex(0) < 0) { |
| - CRASH("Invalid class index %d for size 0\n", ClassIndex(0)); |
| + Log(kCrash, __FILE__, __LINE__, |
| + "Invalid class index for size 0", ClassIndex(0)); |
| } |
| if (ClassIndex(kMaxSize) >= sizeof(class_array_)) { |
| - CRASH("Invalid class index %d for kMaxSize\n", ClassIndex(kMaxSize)); |
| + Log(kCrash, __FILE__, __LINE__, |
| + "Invalid class index for kMaxSize", ClassIndex(kMaxSize)); |
| } |
| // Compute the size classes we want to use |
| int sc = 1; // Next size class to assign |
| int alignment = kAlignment; |
| CHECK_CONDITION(kAlignment <= 16); |
| - int last_lg = -1; |
| for (size_t size = kMinClassSize; size <= kMaxSize; size += alignment) { |
| - int lg = LgFloor(size); |
| - if (lg > last_lg) { |
| - // Increase alignment every so often to reduce number of size classes. |
| - alignment = AlignmentForSize(size); |
| - last_lg = lg; |
| - } |
| + alignment = AlignmentForSize(size); |
| CHECK_CONDITION((size % alignment) == 0); |
| - // Allocate enough pages so leftover is less than 1/8 of total. |
| - // This bounds wasted space to at most 12.5%. |
| - size_t psize = kPageSize; |
| - while ((psize % size) > (psize >> 3)) { |
| + int blocks_to_move = NumMoveSize(size) / 4; |
| + size_t psize = 0; |
| + do { |
| psize += kPageSize; |
| - } |
| + // Allocate enough pages so leftover is less than 1/8 of total. |
| + // This bounds wasted space to at most 12.5%. |
| + while ((psize % size) > (psize >> 3)) { |
| + psize += kPageSize; |
| + } |
| + // Continue to add pages until there are at least as many objects in |
|
Dai Mikurube (NOT FULLTIME)
2012/02/14 11:32:09
From http://codereview.chromium.org/7430007/diff/1
|
| + // the span as are needed when moving objects from the central |
| + // freelists and spans to the thread caches. |
| + } while ((psize / size) < (blocks_to_move)); |
| const size_t my_pages = psize >> kPageShift; |
| if (sc > 1 && my_pages == class_to_pages_[sc-1]) { |
| @@ -146,8 +153,8 @@ void SizeMap::Init() { |
| sc++; |
| } |
| if (sc != kNumClasses) { |
| - CRASH("wrong number of size classes: found %d instead of %d\n", |
| - sc, int(kNumClasses)); |
| + Log(kCrash, __FILE__, __LINE__, |
| + "wrong number of size classes: (found vs. expected )", sc, kNumClasses); |
| } |
| // Initialize the mapping arrays |
| @@ -164,18 +171,17 @@ void SizeMap::Init() { |
| for (size_t size = 0; size <= kMaxSize; size++) { |
| const int sc = SizeClass(size); |
| if (sc <= 0 || sc >= kNumClasses) { |
| - CRASH("Bad size class %d for %" PRIuS "\n", sc, size); |
| + Log(kCrash, __FILE__, __LINE__, |
| + "Bad size class (class, size)", sc, size); |
| } |
| if (sc > 1 && size <= class_to_size_[sc-1]) { |
| - CRASH("Allocating unnecessarily large class %d for %" PRIuS |
| - "\n", sc, size); |
| + Log(kCrash, __FILE__, __LINE__, |
| + "Allocating unnecessarily large class (class, size)", sc, size); |
| } |
| const size_t s = class_to_size_[sc]; |
| - if (size > s) { |
| - CRASH("Bad size %" PRIuS " for %" PRIuS " (sc = %d)\n", s, size, sc); |
| - } |
| - if (s == 0) { |
| - CRASH("Bad size %" PRIuS " for %" PRIuS " (sc = %d)\n", s, size, sc); |
| + if (size > s || s == 0) { |
| + Log(kCrash, __FILE__, __LINE__, |
| + "Bad (class, size, requested)", sc, s, size); |
| } |
| } |
| @@ -185,23 +191,6 @@ void SizeMap::Init() { |
| } |
| } |
| -void SizeMap::Dump(TCMalloc_Printer* out) { |
| - // Dump class sizes and maximum external wastage per size class |
| - for (size_t cl = 1; cl < kNumClasses; ++cl) { |
| - const int alloc_size = class_to_pages_[cl] << kPageShift; |
| - const int alloc_objs = alloc_size / class_to_size_[cl]; |
| - const int min_used = (class_to_size_[cl-1] + 1) * alloc_objs; |
| - const int max_waste = alloc_size - min_used; |
| - out->printf("SC %3d [ %8d .. %8d ] from %8d ; %2.0f%% maxwaste\n", |
| - int(cl), |
| - int(class_to_size_[cl-1] + 1), |
| - int(class_to_size_[cl]), |
| - int(class_to_pages_[cl] << kPageShift), |
| - max_waste * 100.0 / alloc_size |
| - ); |
| - } |
| -} |
| - |
| // Metadata allocator -- keeps stats about how many bytes allocated. |
| static uint64_t metadata_system_bytes_ = 0; |
| void* MetaDataAlloc(size_t bytes) { |