Commit a3be3409 authored by Yuzu Saijo's avatar Yuzu Saijo Committed by Commit Bot

Run page navigation gc when oom intervention is triggered on the previous page

When intervention runs and user navigates away from the page, it is likely that intervention runs
right after the navigation on the new page. This is a bug because it is not the new page's fault
that the memory usage is high, but the previous page's.

This CL makes page navigation gc run when intervention is triggered on the previous page, so that
the memory usage of two pages would not overlap in near-oom situation.

Bug: 887223
Change-Id: I435331410e516d1c87756d84dbd6017d8fff0335
Reviewed-on: https://chromium-review.googlesource.com/1235854
Commit-Queue: Yuzu Saijo <yuzus@chromium.org>
Reviewed-by: default avatarKeishi Hattori <keishi@chromium.org>
Reviewed-by: default avatarKentaro Hara <haraken@chromium.org>
Cr-Commit-Position: refs/heads/master@{#593834}
parent 3cb1137f
...@@ -76,8 +76,9 @@ void V8GCForContextDispose::NotifyContextDisposed( ...@@ -76,8 +76,9 @@ void V8GCForContextDispose::NotifyContextDisposed(
// memory use and trigger a V8+Blink GC. However, on Android, if the frame // memory use and trigger a V8+Blink GC. However, on Android, if the frame
// will not be reused, the process will likely to be killed soon so skip this. // will not be reused, the process will likely to be killed soon so skip this.
if (is_main_frame && frame_reuse_status == WindowProxy::kFrameWillBeReused && if (is_main_frame && frame_reuse_status == WindowProxy::kFrameWillBeReused &&
MemoryCoordinator::IsLowEndDevice() && ((MemoryCoordinator::IsLowEndDevice() &&
MemoryCoordinator::IsCurrentlyLowMemory()) { MemoryCoordinator::IsCurrentlyLowMemory()) ||
force_page_navigation_gc_)) {
size_t pre_gc_memory_usage = GetMemoryUsage(); size_t pre_gc_memory_usage = GetMemoryUsage();
V8PerIsolateData::MainThreadIsolate()->MemoryPressureNotification( V8PerIsolateData::MainThreadIsolate()->MemoryPressureNotification(
v8::MemoryPressureLevel::kCritical); v8::MemoryPressureLevel::kCritical);
...@@ -88,6 +89,8 @@ void V8GCForContextDispose::NotifyContextDisposed( ...@@ -88,6 +89,8 @@ void V8GCForContextDispose::NotifyContextDisposed(
CustomCountHistogram, reduction_histogram, CustomCountHistogram, reduction_histogram,
("BlinkGC.LowMemoryPageNavigationGC.Reduction", 1, 512, 50)); ("BlinkGC.LowMemoryPageNavigationGC.Reduction", 1, 512, 50));
reduction_histogram.Count(reduction / 1024 / 1024); reduction_histogram.Count(reduction / 1024 / 1024);
force_page_navigation_gc_ = false;
} }
#endif #endif
V8PerIsolateData::MainThreadIsolate()->ContextDisposedNotification( V8PerIsolateData::MainThreadIsolate()->ContextDisposedNotification(
...@@ -120,4 +123,8 @@ void V8GCForContextDispose::Reset() { ...@@ -120,4 +123,8 @@ void V8GCForContextDispose::Reset() {
last_context_disposal_time_ = -1; last_context_disposal_time_ = -1;
} }
void V8GCForContextDispose::SetForcePageNavigationGC() {
force_page_navigation_gc_ = true;
}
} // namespace blink } // namespace blink
...@@ -32,6 +32,7 @@ ...@@ -32,6 +32,7 @@
#define THIRD_PARTY_BLINK_RENDERER_BINDINGS_CORE_V8_V8_GC_FOR_CONTEXT_DISPOSE_H_ #define THIRD_PARTY_BLINK_RENDERER_BINDINGS_CORE_V8_V8_GC_FOR_CONTEXT_DISPOSE_H_
#include "third_party/blink/renderer/bindings/core/v8/window_proxy.h" #include "third_party/blink/renderer/bindings/core/v8/window_proxy.h"
#include "third_party/blink/renderer/core/core_export.h"
#include "third_party/blink/renderer/platform/timer.h" #include "third_party/blink/renderer/platform/timer.h"
namespace blink { namespace blink {
...@@ -44,7 +45,12 @@ class V8GCForContextDispose { ...@@ -44,7 +45,12 @@ class V8GCForContextDispose {
void NotifyContextDisposed(bool is_main_frame, WindowProxy::FrameReuseStatus); void NotifyContextDisposed(bool is_main_frame, WindowProxy::FrameReuseStatus);
void NotifyIdle(); void NotifyIdle();
static V8GCForContextDispose& Instance(); CORE_EXPORT static V8GCForContextDispose& Instance();
// Called by OomInterventionImpl. If intervention runs on the previous page,
// it means that the memory usage is high and needs gc during navigation to
// the next page, so that the memory usage of the two pages would not overlap.
CORE_EXPORT void SetForcePageNavigationGC();
private: private:
V8GCForContextDispose(); // Use instance() instead. V8GCForContextDispose(); // Use instance() instead.
...@@ -54,6 +60,7 @@ class V8GCForContextDispose { ...@@ -54,6 +60,7 @@ class V8GCForContextDispose {
TaskRunnerTimer<V8GCForContextDispose> pseudo_idle_timer_; TaskRunnerTimer<V8GCForContextDispose> pseudo_idle_timer_;
bool did_dispose_context_for_main_frame_; bool did_dispose_context_for_main_frame_;
double last_context_disposal_time_; double last_context_disposal_time_;
bool force_page_navigation_gc_;
}; };
} // namespace blink } // namespace blink
......
...@@ -7,6 +7,7 @@ ...@@ -7,6 +7,7 @@
#include "base/metrics/histogram_macros.h" #include "base/metrics/histogram_macros.h"
#include "mojo/public/cpp/bindings/strong_binding.h" #include "mojo/public/cpp/bindings/strong_binding.h"
#include "third_party/blink/public/platform/platform.h" #include "third_party/blink/public/platform/platform.h"
#include "third_party/blink/renderer/bindings/core/v8/v8_gc_for_context_dispose.h"
#include "third_party/blink/renderer/controller/crash_memory_metrics_reporter_impl.h" #include "third_party/blink/renderer/controller/crash_memory_metrics_reporter_impl.h"
#include "third_party/blink/renderer/core/frame/local_frame.h" #include "third_party/blink/renderer/core/frame/local_frame.h"
#include "third_party/blink/renderer/core/page/page.h" #include "third_party/blink/renderer/core/page/page.h"
...@@ -87,6 +88,9 @@ void OomInterventionImpl::Check(TimerBase*) { ...@@ -87,6 +88,9 @@ void OomInterventionImpl::Check(TimerBase*) {
} }
host_->OnHighMemoryUsage(); host_->OnHighMemoryUsage();
timer_.Stop(); timer_.Stop();
// Notify V8GCForContextDispose that page navigation gc is needed when
// intervention runs, as it indicates that memory usage is high.
V8GCForContextDispose::Instance().SetForcePageNavigationGC();
} }
CrashMemoryMetricsReporterImpl::Instance().WriteIntoSharedMemory( CrashMemoryMetricsReporterImpl::Instance().WriteIntoSharedMemory(
current_memory); current_memory);
......
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