Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(2060)

Unified Diff: Source/wtf/PartitionAlloc.cpp

Issue 1053793004: Add a UseCounter that measures the amount of memory used in PartitionAlloc (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: Created 5 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: Source/wtf/PartitionAlloc.cpp
diff --git a/Source/wtf/PartitionAlloc.cpp b/Source/wtf/PartitionAlloc.cpp
index 43fd01be3a08a82bcb8924c492edd71c1eff0245..02ec08b67d607259fcbf95b09328c853a69fbd53 100644
--- a/Source/wtf/PartitionAlloc.cpp
+++ b/Source/wtf/PartitionAlloc.cpp
@@ -98,7 +98,7 @@ static uint16_t partitionBucketNumSystemPages(size_t size)
return bestPages;
}
-static void parititonAllocBaseInit(PartitionRootBase* root)
+static void parititonAllocBaseInit(PartitionRootBase* root, NotifyCommittedMemoryChangedFunction notifyCommittedMemoryChangedFunction)
{
ASSERT(!root->initialized);
@@ -126,6 +126,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->notifyCommittedMemoryChangedFunction = notifyCommittedMemoryChangedFunction;
}
static void partitionBucketInitBase(PartitionBucket* bucket, PartitionRootBase* root)
@@ -136,9 +138,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, NotifyCommittedMemoryChangedFunction notifyCommittedMemoryChangedFunction)
{
- parititonAllocBaseInit(root);
+ parititonAllocBaseInit(root, notifyCommittedMemoryChangedFunction);
root->numBuckets = numBuckets;
root->maxAllocation = maxAllocation;
@@ -153,9 +155,9 @@ void partitionAllocInit(PartitionRoot* root, size_t numBuckets, size_t maxAlloca
}
}
-void partitionAllocGenericInit(PartitionRootGeneric* root)
+void partitionAllocGenericInit(PartitionRootGeneric* root, NotifyCommittedMemoryChangedFunction notifyCommittedMemoryChangedFunction)
{
- parititonAllocBaseInit(root);
+ parititonAllocBaseInit(root, notifyCommittedMemoryChangedFunction);
root->lock = 0;
@@ -328,18 +330,32 @@ static NEVER_INLINE void partitionOutOfMemory(const PartitionRootBase* root)
IMMEDIATE_CRASH();
}
+static void partitionIncreaseCommittedPages(PartitionRootBase* root, size_t len)
haraken 2015/04/05 15:01:52 I added two separate functions (for increase and d
+{
+ root->totalSizeOfCommittedPages += len;
+ ASSERT(root->totalSizeOfCommittedPages <= root->totalSizeOfSuperPages + root->totalSizeOfDirectMappedPages);
+ if (root->notifyCommittedMemoryChangedFunction)
+ root->notifyCommittedMemoryChangedFunction();
+}
+
+static void partitionDecreaseCommittedPages(PartitionRootBase* root, size_t len)
+{
+ root->totalSizeOfCommittedPages -= len;
+ ASSERT(root->totalSizeOfCommittedPages <= root->totalSizeOfSuperPages + root->totalSizeOfDirectMappedPages);
+ if (root->notifyCommittedMemoryChangedFunction)
+ root->notifyCommittedMemoryChangedFunction();
+}
+
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;

Powered by Google App Engine
This is Rietveld 408576698