Commit 29b695ef authored by ulan's avatar ulan Committed by Commit bot

Tune the memory pressure handler to perform a second GC immediately

after the first GC if time allows and there is memory to be freed.

BUG=chromium:618958
LOG=NO

Review-Url: https://codereview.chromium.org/2057103002
Cr-Commit-Position: refs/heads/master@{#36894}
parent 102cb061
......@@ -4466,8 +4466,36 @@ void Heap::CheckMemoryPressure() {
}
void Heap::CollectGarbageOnMemoryPressure(const char* source) {
const int kGarbageThresholdInBytes = 8 * MB;
const double kGarbageThresholdAsFractionOfTotalMemory = 0.1;
// This constant is the maximum response time in RAIL performance model.
const double kMaxMemoryPressurePauseMs = 100;
double start = MonotonicallyIncreasingTimeInMs();
CollectAllGarbage(kReduceMemoryFootprintMask | kAbortIncrementalMarkingMask,
source);
source, kGCCallbackFlagCollectAllAvailableGarbage);
double end = MonotonicallyIncreasingTimeInMs();
// Estimate how much memory we can free.
int64_t potential_garbage = (CommittedMemory() - SizeOfObjects()) +
amount_of_external_allocated_memory_;
// If we can potentially free large amount of memory, then start GC right
// away instead of waiting for memory reducer.
if (potential_garbage >= kGarbageThresholdInBytes &&
potential_garbage >=
CommittedMemory() * kGarbageThresholdAsFractionOfTotalMemory) {
// If we spent less than half of the time budget, then perform full GC
// Otherwise, start incremental marking.
if (end - start < kMaxMemoryPressurePauseMs / 2) {
CollectAllGarbage(
kReduceMemoryFootprintMask | kAbortIncrementalMarkingMask, source,
kGCCallbackFlagCollectAllAvailableGarbage);
} else {
if (FLAG_incremental_marking && incremental_marking()->IsStopped()) {
StartIdleIncrementalMarking();
}
}
}
}
void Heap::MemoryPressureNotification(MemoryPressureLevel level,
......
......@@ -6761,5 +6761,23 @@ TEST(Regress615489) {
CHECK_LE(size_after, size_before);
}
TEST(Regress618958) {
CcTest::InitializeVM();
v8::HandleScope scope(CcTest::isolate());
Heap* heap = CcTest::heap();
bool isolate_is_locked = true;
heap->update_amount_of_external_allocated_memory(100 * MB);
int mark_sweep_count_before = heap->ms_count();
heap->MemoryPressureNotification(MemoryPressureLevel::kCritical,
isolate_is_locked);
int mark_sweep_count_after = heap->ms_count();
int mark_sweeps_performed = mark_sweep_count_after - mark_sweep_count_before;
// The memory pressuer handler either performed two GCs or performed one and
// started incremental marking.
CHECK(mark_sweeps_performed == 2 ||
(mark_sweeps_performed == 1 &&
!heap->incremental_marking()->IsStopped()));
}
} // 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