Commit 79ca9100 authored by Kenichi Ishibashi's avatar Kenichi Ishibashi Committed by Commit Bot

OomIntervention: Make memory workload threshold configurable

The current threshold came from my local experiments and it wouldn't be
necessarily an appropriate value. Make the threshold configurable so
that we can run experiments in the real world.

Bug: 776665
Change-Id: I6ae896439eb50985221258b9109f6f06e3aea178
Reviewed-on: https://chromium-review.googlesource.com/1022410
Commit-Queue: Kenichi Ishibashi <bashi@chromium.org>
Reviewed-by: default avatarKinuko Yasuda <kinuko@chromium.org>
Reviewed-by: default avatarKentaro Hara <haraken@chromium.org>
Cr-Commit-Position: refs/heads/master@{#552963}
parent ab08ac5f
...@@ -60,6 +60,7 @@ void RecordInterventionStateOnCrash(bool accepted) { ...@@ -60,6 +60,7 @@ void RecordInterventionStateOnCrash(bool accepted) {
// Field trial parameter names. // Field trial parameter names.
const char kRendererPauseParamName[] = "pause_renderer"; const char kRendererPauseParamName[] = "pause_renderer";
const char kShouldDetectInRenderer[] = "detect_in_renderer"; const char kShouldDetectInRenderer[] = "detect_in_renderer";
const char kRendererWorkloadThreshold[] = "renderer_workload_threshold";
bool RendererPauseIsEnabled() { bool RendererPauseIsEnabled() {
static bool enabled = base::GetFieldTrialParamByFeatureAsBool( static bool enabled = base::GetFieldTrialParamByFeatureAsBool(
...@@ -73,6 +74,18 @@ bool ShouldDetectInRenderer() { ...@@ -73,6 +74,18 @@ bool ShouldDetectInRenderer() {
return enabled; return enabled;
} }
uint64_t GetRendererMemoryWorkloadThreshold() {
const uint64_t kDefaultMemoryWorkloadThreshold = 80 * 1024 * 1024;
std::string threshold_str = base::GetFieldTrialParamValueByFeature(
features::kOomIntervention, kRendererWorkloadThreshold);
uint64_t threshold = 0;
if (!base::StringToUint64(threshold_str, &threshold)) {
return kDefaultMemoryWorkloadThreshold;
}
return threshold;
}
} // namespace } // namespace
// static // static
...@@ -86,6 +99,7 @@ OomInterventionTabHelper::OomInterventionTabHelper( ...@@ -86,6 +99,7 @@ OomInterventionTabHelper::OomInterventionTabHelper(
decider_(OomInterventionDecider::GetForBrowserContext( decider_(OomInterventionDecider::GetForBrowserContext(
web_contents->GetBrowserContext())), web_contents->GetBrowserContext())),
binding_(this), binding_(this),
renderer_memory_workload_threshold_(GetRendererMemoryWorkloadThreshold()),
weak_ptr_factory_(this) { weak_ptr_factory_(this) {
OutOfMemoryReporter::FromWebContents(web_contents)->AddObserver(this); OutOfMemoryReporter::FromWebContents(web_contents)->AddObserver(this);
} }
...@@ -282,7 +296,9 @@ void OomInterventionTabHelper::StartDetectionInRenderer() { ...@@ -282,7 +296,9 @@ void OomInterventionTabHelper::StartDetectionInRenderer() {
DCHECK(!binding_.is_bound()); DCHECK(!binding_.is_bound());
blink::mojom::OomInterventionHostPtr host; blink::mojom::OomInterventionHostPtr host;
binding_.Bind(mojo::MakeRequest(&host)); binding_.Bind(mojo::MakeRequest(&host));
intervention_->StartDetection(std::move(host), trigger_intervention); intervention_->StartDetection(std::move(host),
renderer_memory_workload_threshold_,
trigger_intervention);
} }
void OomInterventionTabHelper::OnNearOomDetected() { void OomInterventionTabHelper::OnNearOomDetected() {
......
...@@ -104,6 +104,10 @@ class OomInterventionTabHelper ...@@ -104,6 +104,10 @@ class OomInterventionTabHelper
mojo::Binding<blink::mojom::OomInterventionHost> binding_; mojo::Binding<blink::mojom::OomInterventionHost> binding_;
// If memory workload in renderer is above this threshold, we assume that we
// are in a near-OOM situation.
uint64_t renderer_memory_workload_threshold_;
base::WeakPtrFactory<OomInterventionTabHelper> weak_ptr_factory_; base::WeakPtrFactory<OomInterventionTabHelper> weak_ptr_factory_;
}; };
......
...@@ -24,7 +24,11 @@ interface OomInterventionHost { ...@@ -24,7 +24,11 @@ interface OomInterventionHost {
// will be created when the browser gets a high memory pressure signal. // will be created when the browser gets a high memory pressure signal.
// It monitors memory usage in renderer side to detect near-OOM situation. // It monitors memory usage in renderer side to detect near-OOM situation.
interface OomIntervention { interface OomIntervention {
// Starts monitoring memory usage in renderer side. // Starts monitoring memory usage in renderer side. When the renderer's
// memory usage exceeds |memory_workload_threshold| (in bytes) the renderer
// calls host->OnHighMemoryUsage(). The renderer also triggers OOM
// intervention when |trigger_intervention| is true.
StartDetection(OomInterventionHost host, StartDetection(OomInterventionHost host,
uint64 memory_workload_threshold,
bool trigger_intervention); bool trigger_intervention);
}; };
...@@ -16,7 +16,7 @@ namespace blink { ...@@ -16,7 +16,7 @@ namespace blink {
namespace { namespace {
// Roughly caclculates amount of memory which is used to execute pages. // Roughly caclculates amount of memory which is used to execute pages.
size_t BlinkMemoryWorkloadCaculator() { uint64_t BlinkMemoryWorkloadCaculator() {
v8::Isolate* isolate = V8PerIsolateData::MainThreadIsolate(); v8::Isolate* isolate = V8PerIsolateData::MainThreadIsolate();
DCHECK(isolate); DCHECK(isolate);
v8::HeapStatistics heap_statistics; v8::HeapStatistics heap_statistics;
...@@ -32,10 +32,6 @@ size_t BlinkMemoryWorkloadCaculator() { ...@@ -32,10 +32,6 @@ size_t BlinkMemoryWorkloadCaculator() {
} // namespace } // namespace
// If memory workload is above this threshold, we assume that we are in a
// near-OOM situation.
const size_t OomInterventionImpl::kMemoryWorkloadThreshold = 80 * 1024 * 1024;
// static // static
void OomInterventionImpl::Create(mojom::blink::OomInterventionRequest request) { void OomInterventionImpl::Create(mojom::blink::OomInterventionRequest request) {
mojo::MakeStrongBinding( mojo::MakeStrongBinding(
...@@ -57,8 +53,10 @@ OomInterventionImpl::~OomInterventionImpl() = default; ...@@ -57,8 +53,10 @@ OomInterventionImpl::~OomInterventionImpl() = default;
void OomInterventionImpl::StartDetection( void OomInterventionImpl::StartDetection(
mojom::blink::OomInterventionHostPtr host, mojom::blink::OomInterventionHostPtr host,
uint64_t memory_workload_threshold,
bool trigger_intervention) { bool trigger_intervention) {
host_ = std::move(host); host_ = std::move(host);
memory_workload_threshold_ = memory_workload_threshold;
trigger_intervention_ = trigger_intervention; trigger_intervention_ = trigger_intervention;
timer_.Start(TimeDelta(), TimeDelta::FromSeconds(1), FROM_HERE); timer_.Start(TimeDelta(), TimeDelta::FromSeconds(1), FROM_HERE);
...@@ -66,9 +64,10 @@ void OomInterventionImpl::StartDetection( ...@@ -66,9 +64,10 @@ void OomInterventionImpl::StartDetection(
void OomInterventionImpl::Check(TimerBase*) { void OomInterventionImpl::Check(TimerBase*) {
DCHECK(host_); DCHECK(host_);
DCHECK_GT(memory_workload_threshold_, 0UL);
size_t workload = workload_calculator_.Run(); uint64_t workload = workload_calculator_.Run();
if (workload > kMemoryWorkloadThreshold) { if (workload > memory_workload_threshold_) {
host_->OnHighMemoryUsage(trigger_intervention_); host_->OnHighMemoryUsage(trigger_intervention_);
if (trigger_intervention_) { if (trigger_intervention_) {
......
...@@ -21,13 +21,14 @@ class CONTROLLER_EXPORT OomInterventionImpl ...@@ -21,13 +21,14 @@ class CONTROLLER_EXPORT OomInterventionImpl
public: public:
static void Create(mojom::blink::OomInterventionRequest); static void Create(mojom::blink::OomInterventionRequest);
using MemoryWorkloadCaculator = base::RepeatingCallback<size_t()>; using MemoryWorkloadCaculator = base::RepeatingCallback<uint64_t()>;
explicit OomInterventionImpl(MemoryWorkloadCaculator); explicit OomInterventionImpl(MemoryWorkloadCaculator);
~OomInterventionImpl() override; ~OomInterventionImpl() override;
// mojom::blink::OomIntervention: // mojom::blink::OomIntervention:
void StartDetection(mojom::blink::OomInterventionHostPtr, void StartDetection(mojom::blink::OomInterventionHostPtr,
uint64_t memory_workload_threshold,
bool trigger_intervention) override; bool trigger_intervention) override;
private: private:
...@@ -35,8 +36,7 @@ class CONTROLLER_EXPORT OomInterventionImpl ...@@ -35,8 +36,7 @@ class CONTROLLER_EXPORT OomInterventionImpl
void Check(TimerBase*); void Check(TimerBase*);
// This constant is declared here for testing. uint64_t memory_workload_threshold_ = 0;
static const size_t kMemoryWorkloadThreshold;
MemoryWorkloadCaculator workload_calculator_; MemoryWorkloadCaculator workload_calculator_;
mojom::blink::OomInterventionHostPtr host_; mojom::blink::OomInterventionHostPtr host_;
......
...@@ -35,10 +35,10 @@ class MockOomInterventionHost : public mojom::blink::OomInterventionHost { ...@@ -35,10 +35,10 @@ class MockOomInterventionHost : public mojom::blink::OomInterventionHost {
class OomInterventionImplTest : public testing::Test { class OomInterventionImplTest : public testing::Test {
public: public:
size_t MockMemoryWorkloadCalculator() { return memory_workload_; } uint64_t MockMemoryWorkloadCalculator() { return memory_workload_; }
protected: protected:
size_t memory_workload_ = 0; uint64_t memory_workload_ = 0;
FrameTestHelpers::WebViewHelper web_view_helper_; FrameTestHelpers::WebViewHelper web_view_helper_;
}; };
...@@ -52,10 +52,15 @@ TEST_F(OomInterventionImplTest, DetectedAndDeclined) { ...@@ -52,10 +52,15 @@ TEST_F(OomInterventionImplTest, DetectedAndDeclined) {
WTF::Unretained(this))); WTF::Unretained(this)));
EXPECT_FALSE(page->Paused()); EXPECT_FALSE(page->Paused());
memory_workload_ = OomInterventionImpl::kMemoryWorkloadThreshold + 1; // Assign an arbitrary threshold and report workload bigger than the
// threshold.
uint64_t threshold = 80;
intervention->memory_workload_threshold_ = threshold;
memory_workload_ = threshold + 1;
mojom::blink::OomInterventionHostPtr host_ptr; mojom::blink::OomInterventionHostPtr host_ptr;
MockOomInterventionHost mock_host(mojo::MakeRequest(&host_ptr)); MockOomInterventionHost mock_host(mojo::MakeRequest(&host_ptr));
intervention->StartDetection(std::move(host_ptr), intervention->StartDetection(std::move(host_ptr), threshold,
true /*trigger_intervention*/); true /*trigger_intervention*/);
test::RunDelayedTasks(TimeDelta::FromSeconds(1)); test::RunDelayedTasks(TimeDelta::FromSeconds(1));
EXPECT_TRUE(page->Paused()); EXPECT_TRUE(page->Paused());
......
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