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

Side by Side Diff: src/zone/accounting-allocator.h

Issue 2424393002: Constrain the zone segment pool size (Closed)
Patch Set: Added unittest for segment pool size constraints Created 4 years, 2 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 unified diff | Download patch
OLDNEW
1 // Copyright 2016 the V8 project authors. All rights reserved. 1 // Copyright 2016 the V8 project authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #ifndef V8_ZONE_ACCOUNTING_ALLOCATOR_H_ 5 #ifndef V8_ZONE_ACCOUNTING_ALLOCATOR_H_
6 #define V8_ZONE_ACCOUNTING_ALLOCATOR_H_ 6 #define V8_ZONE_ACCOUNTING_ALLOCATOR_H_
7 7
8 #include "include/v8-platform.h" 8 #include "include/v8-platform.h"
9 #include "src/base/atomic-utils.h" 9 #include "src/base/atomic-utils.h"
10 #include "src/base/atomicops.h" 10 #include "src/base/atomicops.h"
11 #include "src/base/macros.h" 11 #include "src/base/macros.h"
12 #include "src/base/platform/mutex.h" 12 #include "src/base/platform/mutex.h"
13 #include "src/base/platform/semaphore.h" 13 #include "src/base/platform/semaphore.h"
14 #include "src/base/platform/time.h" 14 #include "src/base/platform/time.h"
15 #include "src/zone/zone-segment.h" 15 #include "src/zone/zone-segment.h"
16 16
17 namespace v8 { 17 namespace v8 {
18 namespace internal { 18 namespace internal {
19 19
20 // forward declaration
21 class SegmentPoolTests;
22
20 class V8_EXPORT_PRIVATE AccountingAllocator { 23 class V8_EXPORT_PRIVATE AccountingAllocator {
21 public: 24 public:
25 static const size_t kMaxPoolSizeLowMemoryDevice = 8ul * KB;
26 static const size_t kMaxPoolSizeMediumMemoryDevice = 1ul * MB;
27 static const size_t kMaxPoolSizeHighMemoryDevice = 2ul * MB;
28 static const size_t kMaxPoolSizeHugeMemoryDevice = 3ul * MB;
29
22 AccountingAllocator(); 30 AccountingAllocator();
23 virtual ~AccountingAllocator(); 31 virtual ~AccountingAllocator();
24 32
25 // Gets an empty segment from the pool or creates a new one. 33 // Gets an empty segment from the pool or creates a new one.
26 virtual Segment* GetSegment(size_t bytes); 34 virtual Segment* GetSegment(size_t bytes);
27 // Return unneeded segments to either insert them into the pool or release 35 // Return unneeded segments to either insert them into the pool or release
28 // them if the pool is already full or memory pressure is high. 36 // them if the pool is already full or memory pressure is high.
29 virtual void ReturnSegment(Segment* memory); 37 virtual void ReturnSegment(Segment* memory);
30 38
31 size_t GetCurrentMemoryUsage() const; 39 size_t GetCurrentMemoryUsage() const;
32 size_t GetMaxMemoryUsage() const; 40 size_t GetMaxMemoryUsage() const;
33 41
34 size_t GetCurrentPoolSize() const; 42 size_t GetCurrentPoolSize() const;
35 43
36 void MemoryPressureNotification(MemoryPressureLevel level); 44 void MemoryPressureNotification(MemoryPressureLevel level);
45 // Configures the zone segment pool size limits so the pool does not
46 // grow bigger than max_pool_size.
47 // TODO(heimbuef): Do not accept segments to pool that are larger than
48 // their size class requires. Sometimes the zones generate weird segments.
49 void ConfigureSegmentPool(const size_t max_pool_size);
37 50
38 virtual void ZoneCreation(const Zone* zone) {} 51 virtual void ZoneCreation(const Zone* zone) {}
39 virtual void ZoneDestruction(const Zone* zone) {} 52 virtual void ZoneDestruction(const Zone* zone) {}
40 53
41 private: 54 private:
42 static const uint8_t kMinSegmentSizePower = 13; 55 static const size_t kMinSegmentSizePower = 13;
43 static const uint8_t kMaxSegmentSizePower = 18; 56 static const size_t kMaxSegmentSizePower = 18;
44 static const uint8_t kMaxSegmentsPerBucket = 5;
45 57
46 STATIC_ASSERT(kMinSegmentSizePower <= kMaxSegmentSizePower); 58 STATIC_ASSERT(kMinSegmentSizePower <= kMaxSegmentSizePower);
47 59
60 static const size_t kNumberBuckets =
61 1 + kMaxSegmentSizePower - kMinSegmentSizePower;
62
48 // Allocates a new segment. Returns nullptr on failed allocation. 63 // Allocates a new segment. Returns nullptr on failed allocation.
49 Segment* AllocateSegment(size_t bytes); 64 Segment* AllocateSegment(size_t bytes);
50 void FreeSegment(Segment* memory); 65 void FreeSegment(Segment* memory);
51 66
52 // Returns a segment from the pool of at least the requested size. 67 // Returns a segment from the pool of at least the requested size.
53 Segment* GetSegmentFromPool(size_t requested_size); 68 Segment* GetSegmentFromPool(size_t requested_size);
54 // Trys to add a segment to the pool. Returns false if the pool is full. 69 // Trys to add a segment to the pool. Returns false if the pool is full.
55 bool AddSegmentToPool(Segment* segment); 70 bool AddSegmentToPool(Segment* segment);
56 71
57 // Empties the pool and puts all its contents onto the garbage stack. 72 // Empties the pool and puts all its contents onto the garbage stack.
58 void ClearPool(); 73 void ClearPool();
59 74
60 Segment* 75 Segment* unused_segments_heads_[kNumberBuckets];
61 unused_segments_heads_[1 + kMaxSegmentSizePower - kMinSegmentSizePower];
62 76
63 size_t unused_segments_sizes[1 + kMaxSegmentSizePower - kMinSegmentSizePower]; 77 size_t unused_segments_sizes_[kNumberBuckets];
78 size_t unused_segments_max_sizes_[kNumberBuckets];
64 79
65 base::Mutex unused_segments_mutex_; 80 base::Mutex unused_segments_mutex_;
66 81
67 base::AtomicWord current_memory_usage_ = 0; 82 base::AtomicWord current_memory_usage_ = 0;
68 base::AtomicWord max_memory_usage_ = 0; 83 base::AtomicWord max_memory_usage_ = 0;
69 base::AtomicWord current_pool_size_ = 0; 84 base::AtomicWord current_pool_size_ = 0;
70 85
71 base::AtomicValue<MemoryPressureLevel> memory_pressure_level_; 86 base::AtomicValue<MemoryPressureLevel> memory_pressure_level_;
72 87
73 DISALLOW_COPY_AND_ASSIGN(AccountingAllocator); 88 DISALLOW_COPY_AND_ASSIGN(AccountingAllocator);
89
90 friend class SegmentPoolTests;
jochen (gone - plz use gerrit) 2016/10/20 10:29:34 add #include "testing/gtest/include/gtest/gtest_pr
74 }; 91 };
75 92
76 } // namespace internal 93 } // namespace internal
77 } // namespace v8 94 } // namespace v8
78 95
79 #endif // V8_ZONE_ACCOUNTING_ALLOCATOR_H_ 96 #endif // V8_ZONE_ACCOUNTING_ALLOCATOR_H_
OLDNEW
« no previous file with comments | « src/api.cc ('k') | src/zone/accounting-allocator.cc » ('j') | test/unittests/unittests.gyp » ('J')

Powered by Google App Engine
This is Rietveld 408576698