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 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
55 namespace WTF { | 55 namespace WTF { |
56 | 56 |
57 SpinLock PartitionRootBase::gInitializedLock; | 57 SpinLock PartitionRootBase::gInitializedLock; |
58 bool PartitionRootBase::gInitialized = false; | 58 bool PartitionRootBase::gInitialized = false; |
59 PartitionPage PartitionRootBase::gSeedPage; | 59 PartitionPage PartitionRootBase::gSeedPage; |
60 PartitionBucket PartitionRootBase::gPagedBucket; | 60 PartitionBucket PartitionRootBase::gPagedBucket; |
61 void (*PartitionRootBase::gOomHandlingFunction)() = nullptr; | 61 void (*PartitionRootBase::gOomHandlingFunction)() = nullptr; |
62 PartitionAllocHooks::AllocationHook* PartitionAllocHooks::m_allocationHook = nul lptr; | 62 PartitionAllocHooks::AllocationHook* PartitionAllocHooks::m_allocationHook = nul lptr; |
63 PartitionAllocHooks::FreeHook* PartitionAllocHooks::m_freeHook = nullptr; | 63 PartitionAllocHooks::FreeHook* PartitionAllocHooks::m_freeHook = nullptr; |
64 | 64 |
65 static uint16_t partitionBucketNumSystemPages(size_t size) | 65 static uint8_t partitionBucketNumSystemPages(size_t size) |
66 { | 66 { |
67 // This works out reasonably for the current bucket sizes of the generic | 67 // This works out reasonably for the current bucket sizes of the generic |
68 // allocator, and the current values of partition page size and constants. | 68 // allocator, and the current values of partition page size and constants. |
69 // Specifically, we have enough room to always pack the slots perfectly into | 69 // Specifically, we have enough room to always pack the slots perfectly into |
70 // some number of system pages. The only waste is the waste associated with | 70 // some number of system pages. The only waste is the waste associated with |
71 // unfaulted pages (i.e. wasted address space). | 71 // unfaulted pages (i.e. wasted address space). |
72 // TODO: we end up using a lot of system pages for very small sizes. For | 72 // TODO: we end up using a lot of system pages for very small sizes. For |
73 // example, we'll use 12 system pages for slot size 24. The slot size is | 73 // example, we'll use 12 system pages for slot size 24. The slot size is |
74 // so small that the waste would be tiny with just 4, or 1, system pages. | 74 // so small that the waste would be tiny with just 4, or 1, system pages. |
75 // Later, we can investigate whether there are anti-fragmentation benefits | 75 // Later, we can investigate whether there are anti-fragmentation benefits |
76 // to using fewer system pages. | 76 // to using fewer system pages. |
77 double bestWasteRatio = 1.0f; | 77 double bestWasteRatio = 1.0f; |
78 uint16_t bestPages = 0; | 78 uint16_t bestPages = 0; |
79 if (size > kMaxSystemPagesPerSlotSpan * kSystemPageSize) { | 79 if (size > kMaxSystemPagesPerSlotSpan * kSystemPageSize) { |
80 ASSERT(!(size % kSystemPageSize)); | 80 ASSERT(!(size % kSystemPageSize)); |
81 return static_cast<uint16_t>(size / kSystemPageSize); | 81 bestPages = static_cast<uint16_t>(size / kSystemPageSize); |
82 RELEASE_ASSERT(bestPages < (1 << 8)); | |
bashi
2016/01/26 23:52:37
RELEASE_ASSERT(bestPages <= kMaxSystemPagesPerSlot
haraken
2016/01/27 01:19:32
No, what I really want to assert here is that the
bashi
2016/01/27 01:34:07
I think it's not the most important thing to ensur
| |
83 return static_cast<uint8_t>(bestPages); | |
82 } | 84 } |
83 ASSERT(size <= kMaxSystemPagesPerSlotSpan * kSystemPageSize); | 85 ASSERT(size <= kMaxSystemPagesPerSlotSpan * kSystemPageSize); |
84 for (uint16_t i = kNumSystemPagesPerPartitionPage - 1; i <= kMaxSystemPagesP erSlotSpan; ++i) { | 86 for (uint16_t i = kNumSystemPagesPerPartitionPage - 1; i <= kMaxSystemPagesP erSlotSpan; ++i) { |
85 size_t pageSize = kSystemPageSize * i; | 87 size_t pageSize = kSystemPageSize * i; |
86 size_t numSlots = pageSize / size; | 88 size_t numSlots = pageSize / size; |
87 size_t waste = pageSize - (numSlots * size); | 89 size_t waste = pageSize - (numSlots * size); |
88 // Leaving a page unfaulted is not free; the page will occupy an empty p age table entry. | 90 // Leaving a page unfaulted is not free; the page will occupy an empty p age table entry. |
89 // Make a simple attempt to account for that. | 91 // Make a simple attempt to account for that. |
90 size_t numRemainderPages = i & (kNumSystemPagesPerPartitionPage - 1); | 92 size_t numRemainderPages = i & (kNumSystemPagesPerPartitionPage - 1); |
91 size_t numUnfaultedPages = numRemainderPages ? (kNumSystemPagesPerPartit ionPage - numRemainderPages) : 0; | 93 size_t numUnfaultedPages = numRemainderPages ? (kNumSystemPagesPerPartit ionPage - numRemainderPages) : 0; |
92 waste += sizeof(void*) * numUnfaultedPages; | 94 waste += sizeof(void*) * numUnfaultedPages; |
93 double wasteRatio = (double) waste / (double) pageSize; | 95 double wasteRatio = (double) waste / (double) pageSize; |
94 if (wasteRatio < bestWasteRatio) { | 96 if (wasteRatio < bestWasteRatio) { |
95 bestWasteRatio = wasteRatio; | 97 bestWasteRatio = wasteRatio; |
96 bestPages = i; | 98 bestPages = i; |
97 } | 99 } |
98 } | 100 } |
99 ASSERT(bestPages > 0); | 101 ASSERT(bestPages > 0); |
100 return bestPages; | 102 RELEASE_ASSERT(bestPages < (1 << 8)); |
bashi
2016/01/26 23:52:37
ditto.
| |
103 return static_cast<uint8_t>(bestPages); | |
101 } | 104 } |
102 | 105 |
103 static void partitionAllocBaseInit(PartitionRootBase* root) | 106 static void partitionAllocBaseInit(PartitionRootBase* root) |
104 { | 107 { |
105 ASSERT(!root->initialized); | 108 ASSERT(!root->initialized); |
106 { | 109 { |
107 SpinLock::Guard guard(PartitionRootBase::gInitializedLock); | 110 SpinLock::Guard guard(PartitionRootBase::gInitializedLock); |
108 if (!PartitionRootBase::gInitialized) { | 111 if (!PartitionRootBase::gInitialized) { |
109 PartitionRootBase::gInitialized = true; | 112 PartitionRootBase::gInitialized = true; |
110 // We mark the seed page as free to make sure it is skipped by our | 113 // We mark the seed page as free to make sure it is skipped by our |
(...skipping 1297 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1408 partitionStats.totalDiscardableBytes += memoryStats[i].discardableBy tes; | 1411 partitionStats.totalDiscardableBytes += memoryStats[i].discardableBy tes; |
1409 if (!isLightDump) | 1412 if (!isLightDump) |
1410 partitionStatsDumper->partitionsDumpBucketStats(partitionName, & memoryStats[i]); | 1413 partitionStatsDumper->partitionsDumpBucketStats(partitionName, & memoryStats[i]); |
1411 } | 1414 } |
1412 } | 1415 } |
1413 partitionStatsDumper->partitionDumpTotals(partitionName, &partitionStats); | 1416 partitionStatsDumper->partitionDumpTotals(partitionName, &partitionStats); |
1414 } | 1417 } |
1415 | 1418 |
1416 } // namespace WTF | 1419 } // namespace WTF |
1417 | 1420 |
OLD | NEW |