Chromium Code Reviews| Index: Source/wtf/PartitionAlloc.cpp |
| diff --git a/Source/wtf/PartitionAlloc.cpp b/Source/wtf/PartitionAlloc.cpp |
| index 4a83b0efbb9b9ee3cab607f11140755856b73ad5..523d02bb488d91af4d55b824b504f4f8ca777a5a 100644 |
| --- a/Source/wtf/PartitionAlloc.cpp |
| +++ b/Source/wtf/PartitionAlloc.cpp |
| @@ -31,6 +31,8 @@ |
| #include "config.h" |
| #include "wtf/PartitionAlloc.h" |
| +#include "wtf/Atomics.h" |
| + |
| #include <string.h> |
| #ifndef NDEBUG |
| @@ -55,6 +57,11 @@ COMPILE_ASSERT(WTF::kGenericMaxBucketed == 983040, generic_max_bucketed); |
| namespace WTF { |
| +enum PartitionAllocFlagsInternal { |
| + // Flags after to start after all flags in PartitionAllocFlags. |
| + PartitionAllocRetry = 1 << 1, |
| +}; |
| + |
| int PartitionRootBase::gInitializedLock = 0; |
| bool PartitionRootBase::gInitialized = false; |
| PartitionPage PartitionRootBase::gSeedPage; |
| @@ -301,6 +308,23 @@ static NEVER_INLINE void partitionOutOfMemory() |
| IMMEDIATE_CRASH(); |
| } |
| +static PartitionFreeUpMemoryCallback s_partitionFreeUpMemoryCallback = nullptr; |
| +static volatile int s_partitionFreeUpMemoryRecusionCount = 0; |
| + |
| +void partitionSetFreeUpMemoryCallback(PartitionFreeUpMemoryCallback callback) |
| +{ |
| + s_partitionFreeUpMemoryCallback = callback; |
| +} |
| + |
| +static void partitionFreeUpMemory() |
| +{ |
|
Chris Evans
2014/11/06 21:45:34
One more thing. Can we add here a // TODO comment
|
| + if (atomicTestAndSetToOne(&s_partitionFreeUpMemoryRecusionCount)) |
| + return; |
| + if (s_partitionFreeUpMemoryCallback) |
| + s_partitionFreeUpMemoryCallback(); |
|
Chris Evans
2014/11/06 21:43:51
Ah, so s_partitionFreeUpMemoryCallback() is going
|
| + atomicSetOneToZero(&s_partitionFreeUpMemoryRecusionCount); |
| +} |
| + |
| static ALWAYS_INLINE void partitionDecommitSystemPages(PartitionRootBase* root, void* addr, size_t len) |
| { |
| decommitSystemPages(addr, len); |
| @@ -694,6 +718,13 @@ void* partitionAllocSlowPath(PartitionRootBase* root, int flags, size_t size, Pa |
| return partitionPageAllocAndFillFreelist(newPage); |
| partitionAllocSlowPathFailed: |
| + if (!(flags & PartitionAllocRetry)) { |
| + partitionFreeUpMemory(); |
|
Chris Evans
2014/11/06 21:43:51
Nit: I wonder if we want a comment here to say tha
|
| + void* ptr = partitionAllocSlowPath(root, flags | PartitionAllocRetry, size, bucket); |
|
Jens Widell
2014/10/22 11:24:05
Wouldn't it be better to retry partitionBucketAllo
Chris Evans
2014/11/06 21:43:51
I agree that partitionBucketAlloc() is the correct
|
| + if (ptr) |
| + return ptr; |
| + } |
| + |
| if (returnNull) |
| return nullptr; |
| partitionOutOfMemory(); |