| 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 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 53 static_assert(WTF::kGenericSmallestBucket == 8, "generic smallest bucket"); | 53 static_assert(WTF::kGenericSmallestBucket == 8, "generic smallest bucket"); |
| 54 static_assert(WTF::kGenericMaxBucketed == 983040, "generic max bucketed"); | 54 static_assert(WTF::kGenericMaxBucketed == 983040, "generic max bucketed"); |
| 55 | 55 |
| 56 namespace WTF { | 56 namespace WTF { |
| 57 | 57 |
| 58 int PartitionRootBase::gInitializedLock = 0; | 58 int PartitionRootBase::gInitializedLock = 0; |
| 59 bool PartitionRootBase::gInitialized = false; | 59 bool PartitionRootBase::gInitialized = false; |
| 60 PartitionPage PartitionRootBase::gSeedPage; | 60 PartitionPage PartitionRootBase::gSeedPage; |
| 61 PartitionBucket PartitionRootBase::gPagedBucket; | 61 PartitionBucket PartitionRootBase::gPagedBucket; |
| 62 void (*PartitionRootBase::gOomHandlingFunction)() = nullptr; | 62 void (*PartitionRootBase::gOomHandlingFunction)() = nullptr; |
| 63 PartitionAllocHooks::AllocationHook* PartitionAllocHooks::m_allocationHook = nul
lptr; |
| 64 PartitionAllocHooks::FreeHook* PartitionAllocHooks::m_freeHook = nullptr; |
| 63 | 65 |
| 64 static uint16_t partitionBucketNumSystemPages(size_t size) | 66 static uint16_t partitionBucketNumSystemPages(size_t size) |
| 65 { | 67 { |
| 66 // This works out reasonably for the current bucket sizes of the generic | 68 // This works out reasonably for the current bucket sizes of the generic |
| 67 // allocator, and the current values of partition page size and constants. | 69 // allocator, and the current values of partition page size and constants. |
| 68 // Specifically, we have enough room to always pack the slots perfectly into | 70 // Specifically, we have enough room to always pack the slots perfectly into |
| 69 // some number of system pages. The only waste is the waste associated with | 71 // some number of system pages. The only waste is the waste associated with |
| 70 // unfaulted pages (i.e. wasted address space). | 72 // unfaulted pages (i.e. wasted address space). |
| 71 // TODO: we end up using a lot of system pages for very small sizes. For | 73 // TODO: we end up using a lot of system pages for very small sizes. For |
| 72 // example, we'll use 12 system pages for slot size 24. The slot size is | 74 // example, we'll use 12 system pages for slot size 24. The slot size is |
| (...skipping 980 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1053 partitionExcessiveAllocationSize(); | 1055 partitionExcessiveAllocationSize(); |
| 1054 | 1056 |
| 1055 ASSERT(partitionPointerIsValid(partitionCookieFreePointerAdjust(ptr))); | 1057 ASSERT(partitionPointerIsValid(partitionCookieFreePointerAdjust(ptr))); |
| 1056 | 1058 |
| 1057 PartitionPage* page = partitionPointerToPage(partitionCookieFreePointerAdjus
t(ptr)); | 1059 PartitionPage* page = partitionPointerToPage(partitionCookieFreePointerAdjus
t(ptr)); |
| 1058 | 1060 |
| 1059 if (UNLIKELY(partitionBucketIsDirectMapped(page->bucket))) { | 1061 if (UNLIKELY(partitionBucketIsDirectMapped(page->bucket))) { |
| 1060 // We may be able to perform the realloc in place by changing the | 1062 // We may be able to perform the realloc in place by changing the |
| 1061 // accessibility of memory pages and, if reducing the size, decommitting | 1063 // accessibility of memory pages and, if reducing the size, decommitting |
| 1062 // them. | 1064 // them. |
| 1063 if (partitionReallocDirectMappedInPlace(root, page, newSize)) | 1065 if (partitionReallocDirectMappedInPlace(root, page, newSize)) { |
| 1066 PartitionAllocHooks::reallocHookIfEnabled(ptr, ptr, newSize); |
| 1064 return ptr; | 1067 return ptr; |
| 1068 } |
| 1065 } | 1069 } |
| 1066 | 1070 |
| 1067 size_t actualNewSize = partitionAllocActualSize(root, newSize); | 1071 size_t actualNewSize = partitionAllocActualSize(root, newSize); |
| 1068 size_t actualOldSize = partitionAllocGetSize(ptr); | 1072 size_t actualOldSize = partitionAllocGetSize(ptr); |
| 1069 | 1073 |
| 1070 // TODO: note that tcmalloc will "ignore" a downsizing realloc() unless the | 1074 // TODO: note that tcmalloc will "ignore" a downsizing realloc() unless the |
| 1071 // new size is a significant percentage smaller. We could do the same if we | 1075 // new size is a significant percentage smaller. We could do the same if we |
| 1072 // determine it is a win. | 1076 // determine it is a win. |
| 1073 if (actualNewSize == actualOldSize) { | 1077 if (actualNewSize == actualOldSize) { |
| 1074 // Trying to allocate a block of size newSize would give us a block of | 1078 // Trying to allocate a block of size newSize would give us a block of |
| (...skipping 330 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1405 partitionStats.totalDiscardableBytes += memoryStats[i].discardableBy
tes; | 1409 partitionStats.totalDiscardableBytes += memoryStats[i].discardableBy
tes; |
| 1406 if (!isLightDump) | 1410 if (!isLightDump) |
| 1407 partitionStatsDumper->partitionsDumpBucketStats(partitionName, &
memoryStats[i]); | 1411 partitionStatsDumper->partitionsDumpBucketStats(partitionName, &
memoryStats[i]); |
| 1408 } | 1412 } |
| 1409 } | 1413 } |
| 1410 partitionStatsDumper->partitionDumpTotals(partitionName, &partitionStats); | 1414 partitionStatsDumper->partitionDumpTotals(partitionName, &partitionStats); |
| 1411 } | 1415 } |
| 1412 | 1416 |
| 1413 } // namespace WTF | 1417 } // namespace WTF |
| 1414 | 1418 |
| OLD | NEW |