Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(3)

Side by Side Diff: third_party/tcmalloc/chromium/src/common.cc

Issue 7430007: Merge tcmalloc r111 (perftools v. 1.8) with the chromium/ branch. Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: '' Created 9 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2008, Google Inc. 1 // Copyright (c) 2008, Google Inc.
2 // All rights reserved. 2 // All rights reserved.
3 // 3 //
4 // Redistribution and use in source and binary forms, with or without 4 // Redistribution and use in source and binary forms, with or without
5 // modification, are permitted provided that the following conditions are 5 // modification, are permitted provided that the following conditions are
6 // met: 6 // met:
7 // 7 //
8 // * Redistributions of source code must retain the above copyright 8 // * Redistributions of source code must retain the above copyright
9 // notice, this list of conditions and the following disclaimer. 9 // notice, this list of conditions and the following disclaimer.
10 // * Redistributions in binary form must reproduce the above 10 // * Redistributions in binary form must reproduce the above
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
47 n = x; 47 n = x;
48 log += shift; 48 log += shift;
49 } 49 }
50 } 50 }
51 ASSERT(n == 1); 51 ASSERT(n == 1);
52 return log; 52 return log;
53 } 53 }
54 54
55 int AlignmentForSize(size_t size) { 55 int AlignmentForSize(size_t size) {
56 int alignment = kAlignment; 56 int alignment = kAlignment;
57 if (size >= 2048) { 57 if (size > kMaxSize) {
58 // Cap alignment at 256 for large sizes. 58 // Cap alignment at kPageSize for large sizes.
59 alignment = 256; 59 alignment = kPageSize;
60 } else if (size >= 128) { 60 } else if (size >= 128) {
61 // Space wasted due to alignment is at most 1/8, i.e., 12.5%. 61 // Space wasted due to alignment is at most 1/8, i.e., 12.5%.
62 alignment = (1 << LgFloor(size)) / 8; 62 alignment = (1 << LgFloor(size)) / 8;
63 } else if (size >= 16) { 63 } else if (size >= 16) {
64 // We need an alignment of at least 16 bytes to satisfy 64 // We need an alignment of at least 16 bytes to satisfy
65 // requirements for some SSE types. 65 // requirements for some SSE types.
66 alignment = 16; 66 alignment = 16;
67 } 67 }
68 // Maximum alignment allowed is page size alignment.
69 if (alignment > kPageSize) {
70 alignment = kPageSize;
71 }
68 CHECK_CONDITION(size < 16 || alignment >= 16); 72 CHECK_CONDITION(size < 16 || alignment >= 16);
69 CHECK_CONDITION((alignment & (alignment - 1)) == 0); 73 CHECK_CONDITION((alignment & (alignment - 1)) == 0);
70 return alignment; 74 return alignment;
71 } 75 }
72 76
73 int SizeMap::NumMoveSize(size_t size) { 77 int SizeMap::NumMoveSize(size_t size) {
74 if (size == 0) return 0; 78 if (size == 0) return 0;
75 // Use approx 64k transfers between thread and central caches. 79 // Use approx 64k transfers between thread and central caches.
76 int num = static_cast<int>(64.0 * 1024.0 / size); 80 int num = static_cast<int>(64.0 * 1024.0 / size);
77 if (num < 2) num = 2; 81 if (num < 2) num = 2;
(...skipping 20 matching lines...) Expand all
98 CRASH("Invalid class index %d for size 0\n", ClassIndex(0)); 102 CRASH("Invalid class index %d for size 0\n", ClassIndex(0));
99 } 103 }
100 if (ClassIndex(kMaxSize) >= sizeof(class_array_)) { 104 if (ClassIndex(kMaxSize) >= sizeof(class_array_)) {
101 CRASH("Invalid class index %d for kMaxSize\n", ClassIndex(kMaxSize)); 105 CRASH("Invalid class index %d for kMaxSize\n", ClassIndex(kMaxSize));
102 } 106 }
103 107
104 // Compute the size classes we want to use 108 // Compute the size classes we want to use
105 int sc = 1; // Next size class to assign 109 int sc = 1; // Next size class to assign
106 int alignment = kAlignment; 110 int alignment = kAlignment;
107 CHECK_CONDITION(kAlignment <= 16); 111 CHECK_CONDITION(kAlignment <= 16);
108 int last_lg = -1;
109 for (size_t size = kAlignment; size <= kMaxSize; size += alignment) { 112 for (size_t size = kAlignment; size <= kMaxSize; size += alignment) {
110 int lg = LgFloor(size); 113 alignment = AlignmentForSize(size);
111 if (lg > last_lg) {
112 // Increase alignment every so often to reduce number of size classes.
113 alignment = AlignmentForSize(size);
114 last_lg = lg;
115 }
116 CHECK_CONDITION((size % alignment) == 0); 114 CHECK_CONDITION((size % alignment) == 0);
117 115
118 // Allocate enough pages so leftover is less than 1/8 of total. 116 int blocks_to_move = NumMoveSize(size) / 4;
119 // This bounds wasted space to at most 12.5%. 117 size_t psize = 0;
120 size_t psize = kPageSize; 118 do {
121 while ((psize % size) > (psize >> 3)) {
122 psize += kPageSize; 119 psize += kPageSize;
123 } 120 // Allocate enough pages so leftover is less than 1/8 of total.
121 // This bounds wasted space to at most 12.5%.
122 while ((psize % size) > (psize >> 3)) {
123 psize += kPageSize;
124 }
125 // Continue to add pages until there are at least as many objects in
jar (doing other things) 2011/07/31 08:19:39 I'm not clear on the justification for doing this.
126 // the span as are needed when moving objects from the central
127 // freelists and spans to the thread caches.
128 } while ((psize / size) < (blocks_to_move));
124 const size_t my_pages = psize >> kPageShift; 129 const size_t my_pages = psize >> kPageShift;
125 130
126 if (sc > 1 && my_pages == class_to_pages_[sc-1]) { 131 if (sc > 1 && my_pages == class_to_pages_[sc-1]) {
127 // See if we can merge this into the previous class without 132 // See if we can merge this into the previous class without
128 // increasing the fragmentation of the previous class. 133 // increasing the fragmentation of the previous class.
129 const size_t my_objects = (my_pages << kPageShift) / size; 134 const size_t my_objects = (my_pages << kPageShift) / size;
130 const size_t prev_objects = (class_to_pages_[sc-1] << kPageShift) 135 const size_t prev_objects = (class_to_pages_[sc-1] << kPageShift)
131 / class_to_size_[sc-1]; 136 / class_to_size_[sc-1];
132 if (my_objects == prev_objects) { 137 if (my_objects == prev_objects) {
133 // Adjust last class to include this size 138 // Adjust last class to include this size
(...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after
208 return result; 213 return result;
209 } 214 }
210 215
211 uint64_t metadata_system_bytes() { return metadata_system_bytes_; } 216 uint64_t metadata_system_bytes() { return metadata_system_bytes_; }
212 217
213 void increment_metadata_system_bytes(size_t bytes) { 218 void increment_metadata_system_bytes(size_t bytes) {
214 metadata_system_bytes_ += bytes; 219 metadata_system_bytes_ += bytes;
215 } 220 }
216 221
217 } // namespace tcmalloc 222 } // namespace tcmalloc
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698