Chromium Code Reviews| Index: Source/wtf/PartitionAlloc.cpp |
| diff --git a/Source/wtf/PartitionAlloc.cpp b/Source/wtf/PartitionAlloc.cpp |
| index 43fd01be3a08a82bcb8924c492edd71c1eff0245..d4a9d01161f8eadf6539093717c30e206638a183 100644 |
| --- a/Source/wtf/PartitionAlloc.cpp |
| +++ b/Source/wtf/PartitionAlloc.cpp |
| @@ -30,6 +30,7 @@ |
| #include "config.h" |
| #include "wtf/PartitionAlloc.h" |
| +#include "wtf/Partitions.h" |
|
Chris Evans
2015/04/03 22:14:21
Nit: we can get rid of this include now, right?
|
| #include <string.h> |
| @@ -98,7 +99,7 @@ static uint16_t partitionBucketNumSystemPages(size_t size) |
| return bestPages; |
| } |
| -static void parititonAllocBaseInit(PartitionRootBase* root) |
| +static void parititonAllocBaseInit(PartitionRootBase* root, ReportMemoryUsageFunction reportMemoryUsageFunction) |
| { |
| ASSERT(!root->initialized); |
| @@ -126,6 +127,8 @@ static void parititonAllocBaseInit(PartitionRootBase* root) |
| // This is a "magic" value so we can test if a root pointer is valid. |
| root->invertedSelf = ~reinterpret_cast<uintptr_t>(root); |
| + |
| + root->reportMemoryUsageFunction = reportMemoryUsageFunction; |
| } |
| static void partitionBucketInitBase(PartitionBucket* bucket, PartitionRootBase* root) |
| @@ -136,9 +139,9 @@ static void partitionBucketInitBase(PartitionBucket* bucket, PartitionRootBase* |
| bucket->numSystemPagesPerSlotSpan = partitionBucketNumSystemPages(bucket->slotSize); |
| } |
| -void partitionAllocInit(PartitionRoot* root, size_t numBuckets, size_t maxAllocation) |
| +void partitionAllocInit(PartitionRoot* root, size_t numBuckets, size_t maxAllocation, ReportMemoryUsageFunction reportMemoryUsageFunction) |
| { |
| - parititonAllocBaseInit(root); |
| + parititonAllocBaseInit(root, reportMemoryUsageFunction); |
| root->numBuckets = numBuckets; |
| root->maxAllocation = maxAllocation; |
| @@ -153,9 +156,9 @@ void partitionAllocInit(PartitionRoot* root, size_t numBuckets, size_t maxAlloca |
| } |
| } |
| -void partitionAllocGenericInit(PartitionRootGeneric* root) |
| +void partitionAllocGenericInit(PartitionRootGeneric* root, ReportMemoryUsageFunction reportMemoryUsageFunction) |
| { |
| - parititonAllocBaseInit(root); |
| + parititonAllocBaseInit(root, reportMemoryUsageFunction); |
| root->lock = 0; |
| @@ -328,18 +331,31 @@ static NEVER_INLINE void partitionOutOfMemory(const PartitionRootBase* root) |
| IMMEDIATE_CRASH(); |
| } |
| +static void partitionIncreaseCommittedPages(PartitionRootBase* root, size_t len) |
| +{ |
| + root->totalSizeOfCommittedPages += len; |
| + ASSERT(root->totalSizeOfCommittedPages <= root->totalSizeOfSuperPages + root->totalSizeOfDirectMappedPages); |
| + root->reportMemoryUsageFunction(); |
|
Chris Evans
2015/04/03 22:14:21
Crash? We don't want to force the client to provid
|
| +} |
| + |
| +static void partitionDecreaseCommittedPages(PartitionRootBase* root, size_t len) |
| +{ |
| + root->totalSizeOfCommittedPages -= len; |
| + ASSERT(root->totalSizeOfCommittedPages <= root->totalSizeOfSuperPages + root->totalSizeOfDirectMappedPages); |
|
Chris Evans
2015/04/03 22:14:21
I think we should still fire the callback here. Th
|
| + // We don't need to report memory usage here because we send a UseCounter |
| + // only when we see the highest memory usage we've ever seen. |
|
Chris Evans
2015/04/03 22:14:21
Layering violation: mention of UseCounter here. Pa
|
| +} |
| + |
| static ALWAYS_INLINE void partitionDecommitSystemPages(PartitionRootBase* root, void* addr, size_t len) |
| { |
| decommitSystemPages(addr, len); |
| - ASSERT(root->totalSizeOfCommittedPages >= len); |
| - root->totalSizeOfCommittedPages -= len; |
| + partitionDecreaseCommittedPages(root, len); |
| } |
| static ALWAYS_INLINE void partitionRecommitSystemPages(PartitionRootBase* root, void* addr, size_t len) |
| { |
| recommitSystemPages(addr, len); |
| - root->totalSizeOfCommittedPages += len; |
| - ASSERT(root->totalSizeOfCommittedPages <= root->totalSizeOfSuperPages + root->totalSizeOfDirectMappedPages); |
| + partitionIncreaseCommittedPages(root, len); |
| } |
| static ALWAYS_INLINE void* partitionAllocPartitionPages(PartitionRootBase* root, int flags, uint16_t numPartitionPages) |
| @@ -354,8 +370,7 @@ static ALWAYS_INLINE void* partitionAllocPartitionPages(PartitionRootBase* root, |
| // allocation. |
| char* ret = root->nextPartitionPage; |
| root->nextPartitionPage += totalSize; |
| - root->totalSizeOfCommittedPages += totalSize; |
| - ASSERT(root->totalSizeOfCommittedPages <= root->totalSizeOfSuperPages + root->totalSizeOfDirectMappedPages); |
| + partitionIncreaseCommittedPages(root, totalSize); |
| return ret; |
| } |
| @@ -368,8 +383,7 @@ static ALWAYS_INLINE void* partitionAllocPartitionPages(PartitionRootBase* root, |
| return 0; |
| root->totalSizeOfSuperPages += kSuperPageSize; |
| - root->totalSizeOfCommittedPages += totalSize; |
| - ASSERT(root->totalSizeOfCommittedPages <= root->totalSizeOfSuperPages + root->totalSizeOfDirectMappedPages); |
| + partitionIncreaseCommittedPages(root, totalSize); |
| root->nextSuperPage = superPage + kSuperPageSize; |
| char* ret = superPage + kPartitionPageSize; |
| @@ -612,9 +626,8 @@ static ALWAYS_INLINE void* partitionDirectMap(PartitionRootBase* root, int flags |
| mapSize &= kPageAllocationGranularityBaseMask; |
| size_t committedPageSize = size + kSystemPageSize; |
| - root->totalSizeOfCommittedPages += committedPageSize; |
| root->totalSizeOfDirectMappedPages += committedPageSize; |
| - ASSERT(root->totalSizeOfCommittedPages <= root->totalSizeOfSuperPages + root->totalSizeOfDirectMappedPages); |
| + partitionIncreaseCommittedPages(root, committedPageSize); |
| // TODO: we may want to let the operating system place these allocations |
| // where it pleases. On 32-bit, this might limit address space |
| @@ -677,8 +690,7 @@ static ALWAYS_INLINE void partitionDirectUnmap(PartitionPage* page) |
| PartitionRootBase* root = partitionPageToRoot(page); |
| size_t uncommittedPageSize = page->bucket->slotSize + kSystemPageSize; |
| - ASSERT(root->totalSizeOfCommittedPages >= uncommittedPageSize); |
| - root->totalSizeOfCommittedPages -= uncommittedPageSize; |
| + partitionDecreaseCommittedPages(root, uncommittedPageSize); |
| ASSERT(root->totalSizeOfDirectMappedPages >= uncommittedPageSize); |
| root->totalSizeOfDirectMappedPages -= uncommittedPageSize; |