Commit 3f25e56f authored by Ulan Degenbaev's avatar Ulan Degenbaev Committed by Commit Bot

[heap] Activate the memory reducer on smaller heaps

Currently the memory reducer is activated only after the first mark-
compact GC, which triggered after the old generation reaches 8 MB.

That threshold is too large for mobile. This patch adds a heuristic
to activate the memory reducer if the old generation expands by more
than 1 MB after the bootstrap.

Change-Id: Ic38bc6e2fe8887677f764246c45e38d237e49a94
Reviewed-on: https://chromium-review.googlesource.com/c/1425898Reviewed-by: 's avatarRoss McIlroy <rmcilroy@chromium.org>
Commit-Queue: Ulan Degenbaev <ulan@chromium.org>
Cr-Commit-Position: refs/heads/master@{#58982}
parent decfb42a
......@@ -342,6 +342,7 @@ Handle<Context> Bootstrapper::CreateEnvironment(
}
}
LogAllMaps();
isolate_->heap()->NotifyBootstrapComplete();
return scope.CloseAndEscape(env);
}
......
......@@ -4588,6 +4588,26 @@ void Heap::NotifyDeserializationComplete() {
deserialization_complete_ = true;
}
void Heap::NotifyBootstrapComplete() {
// This function is invoked for each native context creation. We are
// interested only in the first native context.
if (old_generation_capacity_after_bootstrap_ == 0) {
old_generation_capacity_after_bootstrap_ = OldGenerationCapacity();
}
}
void Heap::NotifyOldGenerationExpansion() {
const size_t kMemoryReducerActivationThreshold = 1 * MB;
if (old_generation_capacity_after_bootstrap_ && ms_count_ == 0 &&
OldGenerationCapacity() >= old_generation_capacity_after_bootstrap_ +
kMemoryReducerActivationThreshold) {
MemoryReducer::Event event;
event.type = MemoryReducer::kPossibleGarbage;
event.time_ms = MonotonicallyIncreasingTimeInMs();
memory_reducer()->NotifyPossibleGarbage(event);
}
}
void Heap::SetEmbedderHeapTracer(EmbedderHeapTracer* tracer) {
DCHECK_EQ(gc_state_, HeapState::NOT_IN_GC);
local_embedder_heap_tracer()->SetRemoteTracer(tracer);
......
......@@ -347,6 +347,10 @@ class Heap {
// should not happen during deserialization.
void NotifyDeserializationComplete();
void NotifyBootstrapComplete();
void NotifyOldGenerationExpansion();
inline Address* NewSpaceAllocationTopAddress();
inline Address* NewSpaceAllocationLimitAddress();
inline Address* OldSpaceAllocationTopAddress();
......@@ -1753,6 +1757,7 @@ class Heap {
size_t initial_old_generation_size_;
bool old_generation_size_configured_ = false;
size_t maximum_committed_ = 0;
size_t old_generation_capacity_after_bootstrap_ = 0;
// Backing store bytes (array buffers and external strings).
std::atomic<size_t> backing_store_bytes_{0};
......
......@@ -13,6 +13,10 @@
namespace v8 {
namespace internal {
namespace heap {
class HeapTester;
} // namespace heap
class Heap;
......@@ -161,7 +165,7 @@ class V8_EXPORT_PRIVATE MemoryReducer {
double js_calls_sample_time_ms_;
// Used in cctest.
friend class HeapTester;
friend class heap::HeapTester;
DISALLOW_COPY_AND_ASSIGN(MemoryReducer);
};
......
......@@ -1713,6 +1713,7 @@ bool PagedSpace::Expand() {
AddPage(page);
Free(page->area_start(), page->area_size(),
SpaceAccountingMode::kSpaceAccounted);
heap()->NotifyOldGenerationExpansion();
return true;
}
......@@ -3462,6 +3463,7 @@ AllocationResult LargeObjectSpace::AllocateRaw(int object_size,
heap()->incremental_marking()->black_allocation(),
heap()->incremental_marking()->marking_state()->IsBlack(object));
page->InitializationMemoryFence();
heap()->NotifyOldGenerationExpansion();
return object;
}
......
......@@ -31,6 +31,7 @@
V(GCFlags) \
V(MarkCompactCollector) \
V(MarkCompactEpochCounter) \
V(MemoryReducerActivationForSmallHeaps) \
V(NoPromotion) \
V(NumberStringCacheSize) \
V(ObjectGroups) \
......
......@@ -6500,6 +6500,22 @@ TEST(Regress8617) {
CompileRun("obj.method()");
}
HEAP_TEST(MemoryReducerActivationForSmallHeaps) {
ManualGCScope manual_gc_scope;
LocalContext env;
Isolate* isolate = CcTest::i_isolate();
Heap* heap = isolate->heap();
CHECK_EQ(heap->memory_reducer()->state_.action, MemoryReducer::Action::kDone);
HandleScope scope(isolate);
const size_t kActivationThreshold = 1 * MB;
size_t initial_capacity = heap->OldGenerationCapacity();
while (heap->OldGenerationCapacity() <
initial_capacity + kActivationThreshold) {
isolate->factory()->NewFixedArray(1 * KB, TENURED);
}
CHECK_EQ(heap->memory_reducer()->state_.action, MemoryReducer::Action::kWait);
}
} // namespace heap
} // namespace internal
} // namespace v8
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment