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 80 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
91 double wasteRatio = (double) waste / (double) pageSize; | 91 double wasteRatio = (double) waste / (double) pageSize; |
92 if (wasteRatio < bestWasteRatio) { | 92 if (wasteRatio < bestWasteRatio) { |
93 bestWasteRatio = wasteRatio; | 93 bestWasteRatio = wasteRatio; |
94 bestPages = i; | 94 bestPages = i; |
95 } | 95 } |
96 } | 96 } |
97 ASSERT(bestPages > 0); | 97 ASSERT(bestPages > 0); |
98 return bestPages; | 98 return bestPages; |
99 } | 99 } |
100 | 100 |
101 static void parititonAllocBaseInit(PartitionRootBase* root) | 101 static void partitionAllocBaseInit(PartitionRootBase* root) |
102 { | 102 { |
103 ASSERT(!root->initialized); | 103 ASSERT(!root->initialized); |
104 | 104 |
105 spinLockLock(&PartitionRootBase::gInitializedLock); | 105 spinLockLock(&PartitionRootBase::gInitializedLock); |
106 if (!PartitionRootBase::gInitialized) { | 106 if (!PartitionRootBase::gInitialized) { |
107 PartitionRootBase::gInitialized = true; | 107 PartitionRootBase::gInitialized = true; |
108 // We mark the seed page as free to make sure it is skipped by our | 108 // We mark the seed page as free to make sure it is skipped by our |
109 // logic to find a new active page. | 109 // logic to find a new active page. |
110 PartitionRootBase::gPagedBucket.activePagesHead = &PartitionRootGeneric:
:gSeedPage; | 110 PartitionRootBase::gPagedBucket.activePagesHead = &PartitionRootGeneric:
:gSeedPage; |
111 } | 111 } |
(...skipping 21 matching lines...) Expand all Loading... |
133 { | 133 { |
134 bucket->activePagesHead = &PartitionRootGeneric::gSeedPage; | 134 bucket->activePagesHead = &PartitionRootGeneric::gSeedPage; |
135 bucket->emptyPagesHead = 0; | 135 bucket->emptyPagesHead = 0; |
136 bucket->decommittedPagesHead = 0; | 136 bucket->decommittedPagesHead = 0; |
137 bucket->numFullPages = 0; | 137 bucket->numFullPages = 0; |
138 bucket->numSystemPagesPerSlotSpan = partitionBucketNumSystemPages(bucket->sl
otSize); | 138 bucket->numSystemPagesPerSlotSpan = partitionBucketNumSystemPages(bucket->sl
otSize); |
139 } | 139 } |
140 | 140 |
141 void partitionAllocInit(PartitionRoot* root, size_t numBuckets, size_t maxAlloca
tion) | 141 void partitionAllocInit(PartitionRoot* root, size_t numBuckets, size_t maxAlloca
tion) |
142 { | 142 { |
143 parititonAllocBaseInit(root); | 143 partitionAllocBaseInit(root); |
144 | 144 |
145 root->numBuckets = numBuckets; | 145 root->numBuckets = numBuckets; |
146 root->maxAllocation = maxAllocation; | 146 root->maxAllocation = maxAllocation; |
147 size_t i; | 147 size_t i; |
148 for (i = 0; i < root->numBuckets; ++i) { | 148 for (i = 0; i < root->numBuckets; ++i) { |
149 PartitionBucket* bucket = &root->buckets()[i]; | 149 PartitionBucket* bucket = &root->buckets()[i]; |
150 if (!i) | 150 if (!i) |
151 bucket->slotSize = kAllocationGranularity; | 151 bucket->slotSize = kAllocationGranularity; |
152 else | 152 else |
153 bucket->slotSize = i << kBucketShift; | 153 bucket->slotSize = i << kBucketShift; |
154 partitionBucketInitBase(bucket, root); | 154 partitionBucketInitBase(bucket, root); |
155 } | 155 } |
156 } | 156 } |
157 | 157 |
158 void partitionAllocGenericInit(PartitionRootGeneric* root) | 158 void partitionAllocGenericInit(PartitionRootGeneric* root) |
159 { | 159 { |
160 parititonAllocBaseInit(root); | 160 partitionAllocBaseInit(root); |
161 | 161 |
162 root->lock = 0; | 162 root->lock = 0; |
163 | 163 |
164 // Precalculate some shift and mask constants used in the hot path. | 164 // Precalculate some shift and mask constants used in the hot path. |
165 // Example: malloc(41) == 101001 binary. | 165 // Example: malloc(41) == 101001 binary. |
166 // Order is 6 (1 << 6-1)==32 is highest bit set. | 166 // Order is 6 (1 << 6-1)==32 is highest bit set. |
167 // orderIndex is the next three MSB == 010 == 2. | 167 // orderIndex is the next three MSB == 010 == 2. |
168 // subOrderIndexMask is a mask for the remaining bits == 11 (masking to 01 f
or the subOrderIndex). | 168 // subOrderIndexMask is a mask for the remaining bits == 11 (masking to 01 f
or the subOrderIndex). |
169 size_t order; | 169 size_t order; |
170 for (order = 0; order <= kBitsPerSizet; ++order) { | 170 for (order = 0; order <= kBitsPerSizet; ++order) { |
(...skipping 1225 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1396 partitionStats.totalDiscardableBytes += memoryStats[i].discardableBy
tes; | 1396 partitionStats.totalDiscardableBytes += memoryStats[i].discardableBy
tes; |
1397 if (!isLightDump) | 1397 if (!isLightDump) |
1398 partitionStatsDumper->partitionsDumpBucketStats(partitionName, &
memoryStats[i]); | 1398 partitionStatsDumper->partitionsDumpBucketStats(partitionName, &
memoryStats[i]); |
1399 } | 1399 } |
1400 } | 1400 } |
1401 partitionStatsDumper->partitionDumpTotals(partitionName, &partitionStats); | 1401 partitionStatsDumper->partitionDumpTotals(partitionName, &partitionStats); |
1402 } | 1402 } |
1403 | 1403 |
1404 } // namespace WTF | 1404 } // namespace WTF |
1405 | 1405 |
OLD | NEW |