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

Unified Diff: src/heap/heap.cc

Issue 2057103002: Tune the memory pressure handler to perform a second GC immediately (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: x Created 4 years, 6 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 | « no previous file | test/cctest/heap/test-heap.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: src/heap/heap.cc
diff --git a/src/heap/heap.cc b/src/heap/heap.cc
index dbb219a51d6b9395e91d10e9cbc044e140879b75..36161ae8eba798f4c4653c179654eacf1deda332 100644
--- a/src/heap/heap.cc
+++ b/src/heap/heap.cc
@@ -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,
« no previous file with comments | « no previous file | test/cctest/heap/test-heap.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698