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 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 |
| 1075 // the same size as the one we've already got, so no point in doing | 1079 // the same size as the one we've already got, so no point in doing |
| 1076 // anything here. | 1080 // anything here. |
| 1077 return ptr; | 1081 return ptr; |
| 1078 } | 1082 } |
| 1079 | 1083 |
| 1080 // This realloc cannot be resized in-place. Sadness. | 1084 // This realloc cannot be resized in-place. Sadness. |
| 1081 void* ret = partitionAllocGeneric(root, newSize); | 1085 void* ret = partitionAllocGeneric(root, newSize); |
| 1082 size_t copySize = actualOldSize; | 1086 size_t copySize = actualOldSize; |
| 1083 if (newSize < copySize) | 1087 if (newSize < copySize) |
| 1084 copySize = newSize; | 1088 copySize = newSize; |
| 1085 | 1089 |
| 1086 memcpy(ret, ptr, copySize); | 1090 memcpy(ret, ptr, copySize); |
| 1087 partitionFreeGeneric(root, ptr); | 1091 partitionFreeGeneric(root, ptr); |
| 1092 | |
| 1093 PartitionAllocHooks::reallocHookIfEnabled(ptr, ret, newSize); | |
|
haraken
2015/10/20 12:42:00
I don't think this is needed since the above parti
Ruud van Asseldonk
2015/10/20 13:22:16
You are right, fixed.
| |
| 1094 | |
| 1088 return ret; | 1095 return ret; |
| 1089 #endif | 1096 #endif |
| 1090 } | 1097 } |
| 1091 | 1098 |
| 1092 static size_t partitionPurgePage(PartitionPage* page, bool discard) | 1099 static size_t partitionPurgePage(PartitionPage* page, bool discard) |
| 1093 { | 1100 { |
| 1094 const PartitionBucket* bucket = page->bucket; | 1101 const PartitionBucket* bucket = page->bucket; |
| 1095 size_t slotSize = bucket->slotSize; | 1102 size_t slotSize = bucket->slotSize; |
| 1096 if (slotSize < kSystemPageSize || !page->numAllocatedSlots) | 1103 if (slotSize < kSystemPageSize || !page->numAllocatedSlots) |
| 1097 return 0; | 1104 return 0; |
| (...skipping 307 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1405 partitionStats.totalDiscardableBytes += memoryStats[i].discardableBy tes; | 1412 partitionStats.totalDiscardableBytes += memoryStats[i].discardableBy tes; |
| 1406 if (!isLightDump) | 1413 if (!isLightDump) |
| 1407 partitionStatsDumper->partitionsDumpBucketStats(partitionName, & memoryStats[i]); | 1414 partitionStatsDumper->partitionsDumpBucketStats(partitionName, & memoryStats[i]); |
| 1408 } | 1415 } |
| 1409 } | 1416 } |
| 1410 partitionStatsDumper->partitionDumpTotals(partitionName, &partitionStats); | 1417 partitionStatsDumper->partitionDumpTotals(partitionName, &partitionStats); |
| 1411 } | 1418 } |
| 1412 | 1419 |
| 1413 } // namespace WTF | 1420 } // namespace WTF |
| 1414 | 1421 |
| OLD | NEW |