Chromium Code Reviews| Index: src/zone/accounting-allocator.h |
| diff --git a/src/zone/accounting-allocator.h b/src/zone/accounting-allocator.h |
| index 01c38186d6809e44a4f08ebcc287ee1d09dcdc5d..c2ba931eb17e71a3edbb211d3a89b24a83399a5d 100644 |
| --- a/src/zone/accounting-allocator.h |
| +++ b/src/zone/accounting-allocator.h |
| @@ -19,19 +19,55 @@ namespace internal { |
| class AccountingAllocator { |
| public: |
| - AccountingAllocator() = default; |
| - virtual ~AccountingAllocator() = default; |
| + AccountingAllocator(); |
| + virtual ~AccountingAllocator(); |
| - virtual Segment* AllocateSegment(size_t bytes); |
| - virtual void FreeSegment(Segment* memory); |
| + // Gets an empty segment from the pool or creates a new one. |
| + virtual Segment* GetSegment(size_t bytes); |
| + // Return unneeded segments to either insert them into the pool or release |
| + // them if the pool is already full or memory pressure is high. |
| + virtual void ReturnSegment(Segment* memory); |
| size_t GetCurrentMemoryUsage() const; |
| size_t GetMaxMemoryUsage() const; |
| + size_t GetCurrentPoolSize() const; |
| + |
| + void MemoryPressureNotification(MemoryPressureLevel level); |
| + |
| private: |
| + static const uint8_t kMinSegmentSizePower = 13; |
| + static const uint8_t kMaxSegmentSizePower = 18; |
| + static const uint8_t kMaxSegmentsPerBucket = 5; |
| + |
| + STATIC_ASSERT(kMinSegmentSizePower <= kMaxSegmentSizePower); |
| + |
| + // Allocates a new segment. Returns nullptr on failed allocation. |
| + Segment* AllocateSegment(size_t bytes); |
| + void FreeSegment(Segment* memory); |
| + |
| + // Returns a segment from the pool of at least the requested size. |
| + Segment* GetSegmentFromPool(size_t requested_size); |
| + // Trys to add a segment to the pool. Returns false if the pool is full. |
| + bool AddSegmentToPool(Segment* segment); |
| + |
| + // Empties the pool and puts all its contents onto the garbage stack. |
| + void ClearPool(); |
| + |
| + Segment* |
| + unused_segments_heads_[1 + kMaxSegmentSizePower - kMinSegmentSizePower]; |
| + |
| + size_t unused_segments_sizes[1 + kMaxSegmentSizePower - kMinSegmentSizePower]; |
| + |
| + size_t unused_segments_size_ = 0; |
| + |
| + base::Mutex* unused_segments_mutex_ = new base::Mutex(); |
|
Toon Verwaest
2016/09/22 08:41:37
base::Mutex unused_segments_mutex; ?
|
| + |
| base::AtomicWord current_memory_usage_ = 0; |
| base::AtomicWord max_memory_usage_ = 0; |
| + base::AtomicValue<MemoryPressureLevel> memory_pressure_level_; |
| + |
| DISALLOW_COPY_AND_ASSIGN(AccountingAllocator); |
| }; |