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

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

Issue 2424393002: Constrain the zone segment pool size (Closed)
Patch Set: Used proper constants and categories 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 class V8_EXPORT_PRIVATE AccountingAllocator { 20 class V8_EXPORT_PRIVATE AccountingAllocator {
21 public: 21 public:
22 static const size_t kMaxPoolSizeLowMemoryDevice = 8ul * KB;
23 static const size_t kMaxPoolSizeMediumMemoryDevice = 1ul * MB;
24 static const size_t kMaxPoolSizeHighMemoryDevice = 2ul * MB;
25 static const size_t kMaxPoolSizeHugeMemoryDevice = 3ul * MB;
26
22 AccountingAllocator(); 27 AccountingAllocator();
23 virtual ~AccountingAllocator(); 28 virtual ~AccountingAllocator();
24 29
25 // Gets an empty segment from the pool or creates a new one. 30 // Gets an empty segment from the pool or creates a new one.
26 virtual Segment* GetSegment(size_t bytes); 31 virtual Segment* GetSegment(size_t bytes);
27 // Return unneeded segments to either insert them into the pool or release 32 // 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. 33 // them if the pool is already full or memory pressure is high.
29 virtual void ReturnSegment(Segment* memory); 34 virtual void ReturnSegment(Segment* memory);
30 35
31 size_t GetCurrentMemoryUsage() const; 36 size_t GetCurrentMemoryUsage() const;
32 size_t GetMaxMemoryUsage() const; 37 size_t GetMaxMemoryUsage() const;
33 38
34 size_t GetCurrentPoolSize() const; 39 size_t GetCurrentPoolSize() const;
35 40
36 void MemoryPressureNotification(MemoryPressureLevel level); 41 void MemoryPressureNotification(MemoryPressureLevel level);
42 void ConfigureSegmentPool(const size_t max_pool_size);
37 43
38 virtual void ZoneCreation(const Zone* zone) {} 44 virtual void ZoneCreation(const Zone* zone) {}
39 virtual void ZoneDestruction(const Zone* zone) {} 45 virtual void ZoneDestruction(const Zone* zone) {}
40 46
41 private: 47 private:
42 static const uint8_t kMinSegmentSizePower = 13; 48 static const uint8_t kMinSegmentSizePower = 13;
43 static const uint8_t kMaxSegmentSizePower = 18; 49 static const uint8_t kMaxSegmentSizePower = 18;
44 static const uint8_t kMaxSegmentsPerBucket = 5;
45 50
46 STATIC_ASSERT(kMinSegmentSizePower <= kMaxSegmentSizePower); 51 STATIC_ASSERT(kMinSegmentSizePower <= kMaxSegmentSizePower);
47 52
53 static const uint8_t kNumberBuckets =
54 1 + kMaxSegmentSizePower - kMinSegmentSizePower;
55
48 // Allocates a new segment. Returns nullptr on failed allocation. 56 // Allocates a new segment. Returns nullptr on failed allocation.
49 Segment* AllocateSegment(size_t bytes); 57 Segment* AllocateSegment(size_t bytes);
50 void FreeSegment(Segment* memory); 58 void FreeSegment(Segment* memory);
51 59
52 // Returns a segment from the pool of at least the requested size. 60 // Returns a segment from the pool of at least the requested size.
53 Segment* GetSegmentFromPool(size_t requested_size); 61 Segment* GetSegmentFromPool(size_t requested_size);
54 // Trys to add a segment to the pool. Returns false if the pool is full. 62 // Trys to add a segment to the pool. Returns false if the pool is full.
55 bool AddSegmentToPool(Segment* segment); 63 bool AddSegmentToPool(Segment* segment);
56 64
57 // Empties the pool and puts all its contents onto the garbage stack. 65 // Empties the pool and puts all its contents onto the garbage stack.
58 void ClearPool(); 66 void ClearPool();
59 67
60 Segment* 68 Segment* unused_segments_heads_[kNumberBuckets];
61 unused_segments_heads_[1 + kMaxSegmentSizePower - kMinSegmentSizePower];
62 69
63 size_t unused_segments_sizes[1 + kMaxSegmentSizePower - kMinSegmentSizePower]; 70 uint8_t unused_segments_sizes[kNumberBuckets];
71 uint8_t unused_segments_max_sizes[kNumberBuckets];
64 72
65 base::Mutex unused_segments_mutex_; 73 base::Mutex unused_segments_mutex_;
66 74
67 base::AtomicWord current_memory_usage_ = 0; 75 base::AtomicWord current_memory_usage_ = 0;
68 base::AtomicWord max_memory_usage_ = 0; 76 base::AtomicWord max_memory_usage_ = 0;
69 base::AtomicWord current_pool_size_ = 0; 77 base::AtomicWord current_pool_size_ = 0;
70 78
71 base::AtomicValue<MemoryPressureLevel> memory_pressure_level_; 79 base::AtomicValue<MemoryPressureLevel> memory_pressure_level_;
72 80
73 DISALLOW_COPY_AND_ASSIGN(AccountingAllocator); 81 DISALLOW_COPY_AND_ASSIGN(AccountingAllocator);
74 }; 82 };
75 83
76 } // namespace internal 84 } // namespace internal
77 } // namespace v8 85 } // namespace v8
78 86
79 #endif // V8_ZONE_ACCOUNTING_ALLOCATOR_H_ 87 #endif // V8_ZONE_ACCOUNTING_ALLOCATOR_H_
OLDNEW
« src/api.cc ('K') | « src/api.cc ('k') | src/zone/accounting-allocator.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698