| OLD | NEW |
| 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 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 56 // Deallocation may speed up by a factor as the page map gets 8x smaller, so | 56 // Deallocation may speed up by a factor as the page map gets 8x smaller, so |
| 57 // lookups in the page map result in fewer L2 cache misses, which translates to | 57 // lookups in the page map result in fewer L2 cache misses, which translates to |
| 58 // speedup for application/platform combinations with high L2 cache pressure. | 58 // speedup for application/platform combinations with high L2 cache pressure. |
| 59 // As the number of size classes increases with large pages, we increase | 59 // As the number of size classes increases with large pages, we increase |
| 60 // the thread cache allowance to avoid passing more free ranges to and from | 60 // the thread cache allowance to avoid passing more free ranges to and from |
| 61 // central lists. Also, larger pages are less likely to get freed. | 61 // central lists. Also, larger pages are less likely to get freed. |
| 62 // These two factors cause a bounded increase in memory use. | 62 // These two factors cause a bounded increase in memory use. |
| 63 | 63 |
| 64 #if defined(TCMALLOC_LARGE_PAGES) | 64 #if defined(TCMALLOC_LARGE_PAGES) |
| 65 static const size_t kPageShift = 15; | 65 static const size_t kPageShift = 15; |
| 66 static const size_t kNumClasses = 95; | 66 static const size_t kNumClasses = 78; |
| 67 #else |
| 68 static const size_t kPageShift = 13; |
| 69 static const size_t kNumClasses = 86; |
| 70 #endif |
| 67 static const size_t kMaxThreadCacheSize = 4 << 20; | 71 static const size_t kMaxThreadCacheSize = 4 << 20; |
| 68 #else | |
| 69 static const size_t kPageShift = 12; | |
| 70 static const size_t kNumClasses = 61; | |
| 71 static const size_t kMaxThreadCacheSize = 2 << 20; | |
| 72 #endif | |
| 73 | 72 |
| 74 static const size_t kPageSize = 1 << kPageShift; | 73 static const size_t kPageSize = 1 << kPageShift; |
| 75 static const size_t kMaxSize = 8u * kPageSize; | 74 static const size_t kMaxSize = 256 * 1024; |
| 76 static const size_t kAlignment = 8; | 75 static const size_t kAlignment = 8; |
| 77 static const size_t kLargeSizeClass = 0; | 76 static const size_t kLargeSizeClass = 0; |
| 78 // For all span-lengths < kMaxPages we keep an exact-size list. | 77 // For all span-lengths < kMaxPages we keep an exact-size list. |
| 79 static const size_t kMaxPages = 1 << (20 - kPageShift); | 78 static const size_t kMaxPages = 1 << (20 - kPageShift); |
| 80 | 79 |
| 81 // Default bound on the total amount of thread caches. | 80 // Default bound on the total amount of thread caches. |
| 82 #ifdef TCMALLOC_SMALL_BUT_SLOW | 81 #ifdef TCMALLOC_SMALL_BUT_SLOW |
| 83 // Make the overall thread cache no bigger than that of a single thread | 82 // Make the overall thread cache no bigger than that of a single thread |
| 84 // for the small memory footprint case. | 83 // for the small memory footprint case. |
| 85 static const size_t kDefaultOverallThreadCacheSize = kMaxThreadCacheSize; | 84 static const size_t kDefaultOverallThreadCacheSize = kMaxThreadCacheSize; |
| (...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 159 // ------------------------------------------------------- | 158 // ------------------------------------------------------- |
| 160 // 0 (0 + 7) / 8 0 | 159 // 0 (0 + 7) / 8 0 |
| 161 // 1 (1 + 7) / 8 1 | 160 // 1 (1 + 7) / 8 1 |
| 162 // ... | 161 // ... |
| 163 // 1024 (1024 + 7) / 8 128 | 162 // 1024 (1024 + 7) / 8 128 |
| 164 // 1025 (1025 + 127 + (120<<7)) / 128 129 | 163 // 1025 (1025 + 127 + (120<<7)) / 128 129 |
| 165 // ... | 164 // ... |
| 166 // 32768 (32768 + 127 + (120<<7)) / 128 376 | 165 // 32768 (32768 + 127 + (120<<7)) / 128 376 |
| 167 static const int kMaxSmallSize = 1024; | 166 static const int kMaxSmallSize = 1024; |
| 168 static const size_t kClassArraySize = | 167 static const size_t kClassArraySize = |
| 169 (((1 << kPageShift) * 8u + 127 + (120 << 7)) >> 7) + 1; | 168 ((kMaxSize + 127 + (120 << 7)) >> 7) + 1; |
| 170 unsigned char class_array_[kClassArraySize]; | 169 unsigned char class_array_[kClassArraySize]; |
| 171 | 170 |
| 172 // Compute index of the class_array[] entry for a given size | 171 // Compute index of the class_array[] entry for a given size |
| 173 static inline int ClassIndex(int s) { | 172 static inline int ClassIndex(int s) { |
| 174 ASSERT(0 <= s); | 173 ASSERT(0 <= s); |
| 175 ASSERT(s <= kMaxSize); | 174 ASSERT(s <= kMaxSize); |
| 176 const bool big = (s > kMaxSmallSize); | 175 const bool big = (s > kMaxSmallSize); |
| 177 const int add_amount = big ? (127 + (120<<7)) : 7; | 176 const int add_amount = big ? (127 + (120<<7)) : 7; |
| 178 const int shift_amount = big ? 7 : 3; | 177 const int shift_amount = big ? 7 : 3; |
| 179 return (s + add_amount) >> shift_amount; | 178 return (s + add_amount) >> shift_amount; |
| (...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 241 static const int kMaxStackDepth = 31; | 240 static const int kMaxStackDepth = 31; |
| 242 struct StackTrace { | 241 struct StackTrace { |
| 243 uintptr_t size; // Size of object | 242 uintptr_t size; // Size of object |
| 244 uintptr_t depth; // Number of PC values stored in array below | 243 uintptr_t depth; // Number of PC values stored in array below |
| 245 void* stack[kMaxStackDepth]; | 244 void* stack[kMaxStackDepth]; |
| 246 }; | 245 }; |
| 247 | 246 |
| 248 } // namespace tcmalloc | 247 } // namespace tcmalloc |
| 249 | 248 |
| 250 #endif // TCMALLOC_COMMON_H_ | 249 #endif // TCMALLOC_COMMON_H_ |
| OLD | NEW |