Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 /* | 1 /* |
| 2 * Copyright (C) 2013 Google Inc. All rights reserved. | 2 * Copyright (C) 2013 Google Inc. 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 111 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 122 static const size_t kMaxPartitionSize = 2046u * 1024u * 1024u; | 122 static const size_t kMaxPartitionSize = 2046u * 1024u * 1024u; |
| 123 | 123 |
| 124 // Allocation granularity of sizeof(void*) bytes. | 124 // Allocation granularity of sizeof(void*) bytes. |
| 125 static const size_t kAllocationGranularity = sizeof(void*); | 125 static const size_t kAllocationGranularity = sizeof(void*); |
| 126 static const size_t kAllocationGranularityMask = kAllocationGranularity - 1; | 126 static const size_t kAllocationGranularityMask = kAllocationGranularity - 1; |
| 127 static const size_t kBucketShift = (kAllocationGranularity == 8) ? 3 : 2; | 127 static const size_t kBucketShift = (kAllocationGranularity == 8) ? 3 : 2; |
| 128 | 128 |
| 129 // Underlying partition storage pages are a power-of-two size. It is typical | 129 // Underlying partition storage pages are a power-of-two size. It is typical |
| 130 // for a partition page to be based on multiple system pages. Most references to | 130 // for a partition page to be based on multiple system pages. Most references to |
| 131 // "page" refer to partition pages. | 131 // "page" refer to partition pages. |
| 132 // We also have the concept of "super pages" -- these are the underlying system // allocations we make. Super pages contain multiple partition pages inside them | 132 // We also have the concept of "super pages" -- these are the underlying system |
| 133 // allocations we make. Super pages contain multiple partition pages inside them | |
| 133 // and include space for a small amount of metadata per partition page. | 134 // and include space for a small amount of metadata per partition page. |
| 134 // Inside super pages, we store "slot spans". A slot span is a continguous range | 135 // Inside super pages, we store "slot spans". A slot span is a continguous range |
| 135 // of one or more partition pages that stores allocations of the same size. | 136 // of one or more partition pages that stores allocations of the same size. |
| 136 // Slot span sizes are adjusted depending on the allocation size, to make sure | 137 // Slot span sizes are adjusted depending on the allocation size, to make sure |
| 137 // the packing does not lead to unused (wasted) space at the end of the last | 138 // the packing does not lead to unused (wasted) space at the end of the last |
| 138 // system page of the span. For our current max slot span size of 64k and other | 139 // system page of the span. For our current max slot span size of 64k and other |
| 139 // constant values, we pack _all_ partitionAllocGeneric() sizes perfectly up | 140 // constant values, we pack _all_ partitionAllocGeneric() sizes perfectly up |
| 140 // against the end of a system page. | 141 // against the end of a system page. |
| 141 static const size_t kPartitionPageShift = 14; // 16KB | 142 static const size_t kPartitionPageShift = 14; // 16KB |
| 142 static const size_t kPartitionPageSize = 1 << kPartitionPageShift; | 143 static const size_t kPartitionPageSize = 1 << kPartitionPageShift; |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 175 // In terms of allocation sizes, order 0 covers 0, order 1 covers 1, order 2 | 176 // In terms of allocation sizes, order 0 covers 0, order 1 covers 1, order 2 |
| 176 // covers 2->3, order 3 covers 4->7, order 4 covers 8->15. | 177 // covers 2->3, order 3 covers 4->7, order 4 covers 8->15. |
| 177 static const size_t kGenericMinBucketedOrder = 4; // 8 bytes. | 178 static const size_t kGenericMinBucketedOrder = 4; // 8 bytes. |
| 178 static const size_t kGenericMaxBucketedOrder = 20; // Largest bucketed order is 1<<(20-1) (storing 512KB -> almost 1MB) | 179 static const size_t kGenericMaxBucketedOrder = 20; // Largest bucketed order is 1<<(20-1) (storing 512KB -> almost 1MB) |
| 179 static const size_t kGenericNumBucketedOrders = (kGenericMaxBucketedOrder - kGen ericMinBucketedOrder) + 1; | 180 static const size_t kGenericNumBucketedOrders = (kGenericMaxBucketedOrder - kGen ericMinBucketedOrder) + 1; |
| 180 static const size_t kGenericNumBucketsPerOrderBits = 3; // Eight buckets per ord er (for the higher orders), e.g. order 8 is 128, 144, 160, ..., 240 | 181 static const size_t kGenericNumBucketsPerOrderBits = 3; // Eight buckets per ord er (for the higher orders), e.g. order 8 is 128, 144, 160, ..., 240 |
| 181 static const size_t kGenericNumBucketsPerOrder = 1 << kGenericNumBucketsPerOrder Bits; | 182 static const size_t kGenericNumBucketsPerOrder = 1 << kGenericNumBucketsPerOrder Bits; |
| 182 static const size_t kGenericSmallestBucket = 1 << (kGenericMinBucketedOrder - 1) ; | 183 static const size_t kGenericSmallestBucket = 1 << (kGenericMinBucketedOrder - 1) ; |
| 183 static const size_t kGenericMaxBucketSpacing = 1 << ((kGenericMaxBucketedOrder - 1) - kGenericNumBucketsPerOrderBits); | 184 static const size_t kGenericMaxBucketSpacing = 1 << ((kGenericMaxBucketedOrder - 1) - kGenericNumBucketsPerOrderBits); |
| 184 static const size_t kGenericMaxBucketed = (1 << (kGenericMaxBucketedOrder - 1)) + ((kGenericNumBucketsPerOrder - 1) * kGenericMaxBucketSpacing); | 185 static const size_t kGenericMaxBucketed = (1 << (kGenericMaxBucketedOrder - 1)) + ((kGenericNumBucketsPerOrder - 1) * kGenericMaxBucketSpacing); |
| 186 static const size_t kGenericMinDirectMapped = 10 * kPartitionPageSize; // Limit when downsizing a direct mapping using realloc(); allows 10 % allocation overhea d. | |
|
Chris Evans
2014/03/06 05:55:13
At the risk of giving away my OCD, can we make tha
| |
| 185 static const size_t kGenericMaxDirectMapped = INT_MAX - kSystemPageSize; | 187 static const size_t kGenericMaxDirectMapped = INT_MAX - kSystemPageSize; |
| 186 static const size_t kBitsPerSizet = sizeof(void*) * CHAR_BIT; | 188 static const size_t kBitsPerSizet = sizeof(void*) * CHAR_BIT; |
| 187 | 189 |
| 188 // Constants for the memory reclaim logic. | 190 // Constants for the memory reclaim logic. |
| 189 static const size_t kMaxFreeableSpans = 16; | 191 static const size_t kMaxFreeableSpans = 16; |
| 190 | 192 |
| 191 #ifndef NDEBUG | 193 #ifndef NDEBUG |
| 192 // These two byte values match tcmalloc. | 194 // These two byte values match tcmalloc. |
| 193 static const unsigned char kUninitializedByte = 0xAB; | 195 static const unsigned char kUninitializedByte = 0xAB; |
| 194 static const unsigned char kFreedByte = 0xCD; | 196 static const unsigned char kFreedByte = 0xCD; |
| (...skipping 461 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 656 using WTF::partitionAlloc; | 658 using WTF::partitionAlloc; |
| 657 using WTF::partitionFree; | 659 using WTF::partitionFree; |
| 658 using WTF::partitionAllocGeneric; | 660 using WTF::partitionAllocGeneric; |
| 659 using WTF::partitionFreeGeneric; | 661 using WTF::partitionFreeGeneric; |
| 660 using WTF::partitionReallocGeneric; | 662 using WTF::partitionReallocGeneric; |
| 661 using WTF::partitionAllocActualSize; | 663 using WTF::partitionAllocActualSize; |
| 662 using WTF::partitionAllocSupportsGetSize; | 664 using WTF::partitionAllocSupportsGetSize; |
| 663 using WTF::partitionAllocGetSize; | 665 using WTF::partitionAllocGetSize; |
| 664 | 666 |
| 665 #endif // WTF_PartitionAlloc_h | 667 #endif // WTF_PartitionAlloc_h |
| OLD | NEW |