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

Unified Diff: src/zone/accounting-allocator.h

Issue 2335343007: Pool implementation for zone segments (Closed)
Patch Set: Remove garbage stack Created 4 years, 3 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: src/zone/accounting-allocator.h
diff --git a/src/zone/accounting-allocator.h b/src/zone/accounting-allocator.h
index 01c38186d6809e44a4f08ebcc287ee1d09dcdc5d..726808192f1e0ea7d10235faccc9166fc699049d 100644
--- a/src/zone/accounting-allocator.h
+++ b/src/zone/accounting-allocator.h
@@ -19,19 +19,58 @@ 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 pool or creates a new one.
Toon Verwaest 2016/09/21 11:14:32 the pool
+ virtual Segment* GetSegment(size_t bytes);
+ // Return non needed segments here to insert them into the pool
Toon Verwaest 2016/09/21 11:14:32 Return unneeded segments to either insert them int
+ // or release them in case the pool is full. Operation may or may
Toon Verwaest 2016/09/21 11:14:32 drop "or may not"
+ // not be asynchronous, depending on memory pressure.
+ 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);
+
+ // Allocated a new segment. Returns nullptr on failed allocation.
+ Segment* AllocateSegment(size_t bytes);
+ // Frees a non needed segment. Blocks the current thread.
Toon Verwaest 2016/09/21 11:14:32 unneeded
+ 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_ =
+ new Segment*[1 + kMaxSegmentSizePower - kMinSegmentSizePower];
+
+ size_t* unused_segments_sizes =
+ new size_t[1 + kMaxSegmentSizePower - kMinSegmentSizePower];
+
+ size_t unused_segments_size_ = 0;
+
+ base::Mutex* unused_segments_mutex_ = new base::Mutex();
+
base::AtomicWord current_memory_usage_ = 0;
base::AtomicWord max_memory_usage_ = 0;
+ base::AtomicValue<MemoryPressureLevel> memory_pressure_level_;
+
DISALLOW_COPY_AND_ASSIGN(AccountingAllocator);
};
« no previous file with comments | « src/v8.gyp ('k') | src/zone/accounting-allocator.cc » ('j') | src/zone/accounting-allocator.cc » ('J')

Powered by Google App Engine
This is Rietveld 408576698