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

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

Issue 2392183004: Added zone pool metrics to gc-trace. (Closed)
Patch Set: Added recent master changes 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
« no previous file with comments | « src/zone/accounting-allocator.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 #include "src/zone/accounting-allocator.h" 5 #include "src/zone/accounting-allocator.h"
6 6
7 #include <cstdlib> 7 #include <cstdlib>
8 8
9 #if V8_LIBC_BIONIC 9 #if V8_LIBC_BIONIC
10 #include <malloc.h> // NOLINT 10 #include <malloc.h> // NOLINT
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after
77 } 77 }
78 78
79 size_t AccountingAllocator::GetCurrentMemoryUsage() const { 79 size_t AccountingAllocator::GetCurrentMemoryUsage() const {
80 return base::NoBarrier_Load(&current_memory_usage_); 80 return base::NoBarrier_Load(&current_memory_usage_);
81 } 81 }
82 82
83 size_t AccountingAllocator::GetMaxMemoryUsage() const { 83 size_t AccountingAllocator::GetMaxMemoryUsage() const {
84 return base::NoBarrier_Load(&max_memory_usage_); 84 return base::NoBarrier_Load(&max_memory_usage_);
85 } 85 }
86 86
87 size_t AccountingAllocator::GetCurrentPoolSize() const {
88 return base::NoBarrier_Load(&current_pool_size_);
89 }
90
87 Segment* AccountingAllocator::GetSegmentFromPool(size_t requested_size) { 91 Segment* AccountingAllocator::GetSegmentFromPool(size_t requested_size) {
88 if (requested_size > (1 << kMaxSegmentSizePower)) { 92 if (requested_size > (1 << kMaxSegmentSizePower)) {
89 return nullptr; 93 return nullptr;
90 } 94 }
91 95
92 uint8_t power = kMinSegmentSizePower; 96 uint8_t power = kMinSegmentSizePower;
93 while (requested_size > static_cast<size_t>(1 << power)) power++; 97 while (requested_size > static_cast<size_t>(1 << power)) power++;
94 98
95 DCHECK_GE(power, kMinSegmentSizePower + 0); 99 DCHECK_GE(power, kMinSegmentSizePower + 0);
96 power -= kMinSegmentSizePower; 100 power -= kMinSegmentSizePower;
97 101
98 Segment* segment; 102 Segment* segment;
99 { 103 {
100 base::LockGuard<base::Mutex> lock_guard(&unused_segments_mutex_); 104 base::LockGuard<base::Mutex> lock_guard(&unused_segments_mutex_);
101 105
102 segment = unused_segments_heads_[power]; 106 segment = unused_segments_heads_[power];
103 107
104 if (segment != nullptr) { 108 if (segment != nullptr) {
105 unused_segments_heads_[power] = segment->next(); 109 unused_segments_heads_[power] = segment->next();
106 segment->set_next(nullptr); 110 segment->set_next(nullptr);
107 111
108 unused_segments_sizes[power]--; 112 unused_segments_sizes[power]--;
109 unused_segments_size_ -= segment->size(); 113 base::NoBarrier_AtomicIncrement(
114 &current_pool_size_, -static_cast<base::AtomicWord>(segment->size()));
110 } 115 }
111 } 116 }
112 117
113 if (segment) { 118 if (segment) {
114 DCHECK_GE(segment->size(), requested_size); 119 DCHECK_GE(segment->size(), requested_size);
115 } 120 }
116 return segment; 121 return segment;
117 } 122 }
118 123
119 bool AccountingAllocator::AddSegmentToPool(Segment* segment) { 124 bool AccountingAllocator::AddSegmentToPool(Segment* segment) {
(...skipping 12 matching lines...) Expand all
132 137
133 { 138 {
134 base::LockGuard<base::Mutex> lock_guard(&unused_segments_mutex_); 139 base::LockGuard<base::Mutex> lock_guard(&unused_segments_mutex_);
135 140
136 if (unused_segments_sizes[power] >= kMaxSegmentsPerBucket) { 141 if (unused_segments_sizes[power] >= kMaxSegmentsPerBucket) {
137 return false; 142 return false;
138 } 143 }
139 144
140 segment->set_next(unused_segments_heads_[power]); 145 segment->set_next(unused_segments_heads_[power]);
141 unused_segments_heads_[power] = segment; 146 unused_segments_heads_[power] = segment;
142 unused_segments_size_ += size; 147 base::NoBarrier_AtomicIncrement(&current_pool_size_, size);
143 unused_segments_sizes[power]++; 148 unused_segments_sizes[power]++;
144 } 149 }
145 150
146 return true; 151 return true;
147 } 152 }
148 153
149 void AccountingAllocator::ClearPool() { 154 void AccountingAllocator::ClearPool() {
150 base::LockGuard<base::Mutex> lock_guard(&unused_segments_mutex_); 155 base::LockGuard<base::Mutex> lock_guard(&unused_segments_mutex_);
151 156
152 for (uint8_t power = 0; power <= kMaxSegmentSizePower - kMinSegmentSizePower; 157 for (uint8_t power = 0; power <= kMaxSegmentSizePower - kMinSegmentSizePower;
153 power++) { 158 power++) {
154 Segment* current = unused_segments_heads_[power]; 159 Segment* current = unused_segments_heads_[power];
155 while (current) { 160 while (current) {
156 Segment* next = current->next(); 161 Segment* next = current->next();
157 FreeSegment(current); 162 FreeSegment(current);
158 current = next; 163 current = next;
159 } 164 }
160 unused_segments_heads_[power] = nullptr; 165 unused_segments_heads_[power] = nullptr;
161 } 166 }
162 } 167 }
163 168
164 } // namespace internal 169 } // namespace internal
165 } // namespace v8 170 } // namespace v8
OLDNEW
« no previous file with comments | « src/zone/accounting-allocator.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698