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

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

Issue 2365843002: Revert of Pool implementation for zone segments (Closed)
Patch Set: 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
« no previous file with comments | « src/zone/accounting-allocator.h ('k') | src/zone/zone.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: src/zone/accounting-allocator.cc
diff --git a/src/zone/accounting-allocator.cc b/src/zone/accounting-allocator.cc
index b9740f7e6faf4a752a2fad49d1ce70adc61949c0..623cb5718af5148cda57bfd015959bee1b7ff357 100644
--- a/src/zone/accounting-allocator.cc
+++ b/src/zone/accounting-allocator.cc
@@ -13,38 +13,6 @@
namespace v8 {
namespace internal {
-AccountingAllocator::AccountingAllocator() : unused_segments_mutex_() {
- memory_pressure_level_.SetValue(MemoryPressureLevel::kNone);
- std::fill(unused_segments_heads_,
- unused_segments_heads_ +
- (1 + kMaxSegmentSizePower - kMinSegmentSizePower),
- nullptr);
- std::fill(
- unused_segments_sizes,
- unused_segments_sizes + (1 + kMaxSegmentSizePower - kMinSegmentSizePower),
- 0);
-}
-
-AccountingAllocator::~AccountingAllocator() { ClearPool(); }
-
-void AccountingAllocator::MemoryPressureNotification(
- MemoryPressureLevel level) {
- memory_pressure_level_.SetValue(level);
-
- if (level != MemoryPressureLevel::kNone) {
- ClearPool();
- }
-}
-
-Segment* AccountingAllocator::GetSegment(size_t bytes) {
- Segment* result = GetSegmentFromPool(bytes);
- if (result == nullptr) {
- result = AllocateSegment(bytes);
- }
-
- return result;
-}
-
Segment* AccountingAllocator::AllocateSegment(size_t bytes) {
void* memory = malloc(bytes);
if (memory) {
@@ -58,19 +26,9 @@
return reinterpret_cast<Segment*>(memory);
}
-void AccountingAllocator::ReturnSegment(Segment* segment) {
- segment->ZapContents();
- if (memory_pressure_level_.Value() != MemoryPressureLevel::kNone) {
- FreeSegment(segment);
- } else if (!AddSegmentToPool(segment)) {
- FreeSegment(segment);
- }
-}
-
void AccountingAllocator::FreeSegment(Segment* memory) {
base::NoBarrier_AtomicIncrement(
&current_memory_usage_, -static_cast<base::AtomicWord>(memory->size()));
- memory->ZapHeader();
free(memory);
}
@@ -82,82 +40,5 @@
return base::NoBarrier_Load(&max_memory_usage_);
}
-Segment* AccountingAllocator::GetSegmentFromPool(size_t requested_size) {
- if (requested_size > (1 << kMaxSegmentSizePower)) {
- return nullptr;
- }
-
- uint8_t power = kMinSegmentSizePower;
- while (requested_size > static_cast<size_t>(1 << power)) power++;
-
- DCHECK_GE(power, kMinSegmentSizePower + 0);
- power -= kMinSegmentSizePower;
-
- Segment* segment;
- {
- base::LockGuard<base::Mutex> lock_guard(&unused_segments_mutex_);
-
- segment = unused_segments_heads_[power];
-
- if (segment != nullptr) {
- unused_segments_heads_[power] = segment->next();
- segment->set_next(nullptr);
-
- unused_segments_sizes[power]--;
- unused_segments_size_ -= segment->size();
- }
- }
-
- if (segment) {
- DCHECK_GE(segment->size(), requested_size);
- }
- return segment;
-}
-
-bool AccountingAllocator::AddSegmentToPool(Segment* segment) {
- size_t size = segment->size();
-
- if (size >= (1 << (kMaxSegmentSizePower + 1))) return false;
-
- if (size < (1 << kMinSegmentSizePower)) return false;
-
- uint8_t power = kMaxSegmentSizePower;
-
- while (size < static_cast<size_t>(1 << power)) power--;
-
- DCHECK_GE(power, kMinSegmentSizePower + 0);
- power -= kMinSegmentSizePower;
-
- {
- base::LockGuard<base::Mutex> lock_guard(&unused_segments_mutex_);
-
- if (unused_segments_sizes[power] >= kMaxSegmentsPerBucket) {
- return false;
- }
-
- segment->set_next(unused_segments_heads_[power]);
- unused_segments_heads_[power] = segment;
- unused_segments_size_ += size;
- unused_segments_sizes[power]++;
- }
-
- return true;
-}
-
-void AccountingAllocator::ClearPool() {
- base::LockGuard<base::Mutex> lock_guard(&unused_segments_mutex_);
-
- for (uint8_t power = 0; power <= kMaxSegmentSizePower - kMinSegmentSizePower;
- power++) {
- Segment* current = unused_segments_heads_[power];
- while (current) {
- Segment* next = current->next();
- FreeSegment(current);
- current = next;
- }
- unused_segments_heads_[power] = nullptr;
- }
-}
-
} // namespace internal
} // namespace v8
« no previous file with comments | « src/zone/accounting-allocator.h ('k') | src/zone/zone.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698