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) {
// Field trial parameter names.
const char kRendererPauseParamName[] = "pause_renderer";
const char kShouldDetectInRenderer[] = "detect_in_renderer";
const char kRendererWorkloadThreshold[] = "renderer_workload_threshold";
bool RendererPauseIsEnabled() {
static bool enabled = base::GetFieldTrialParamByFeatureAsBool(
......@@ -73,6 +74,18 @@ bool ShouldDetectInRenderer() {
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
// static
......@@ -86,6 +99,7 @@ OomInterventionTabHelper::OomInterventionTabHelper(
decider_(OomInterventionDecider::GetForBrowserContext(
web_contents->GetBrowserContext())),
binding_(this),
renderer_memory_workload_threshold_(GetRendererMemoryWorkloadThreshold()),
weak_ptr_factory_(this) {
OutOfMemoryReporter::FromWebContents(web_contents)->AddObserver(this);
}
......@@ -282,7 +296,9 @@ void OomInterventionTabHelper::StartDetectionInRenderer() {
DCHECK(!binding_.is_bound());
blink::mojom::OomInterventionHostPtr 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() {
......
......@@ -104,6 +104,10 @@ class OomInterventionTabHelper
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_;
};
......
......@@ -24,7 +24,11 @@ interface OomInterventionHost {
// will be created when the browser gets a high memory pressure signal.
// It monitors memory usage in renderer side to detect near-OOM situation.
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,
uint64 memory_workload_threshold,
bool trigger_intervention);
};
......@@ -16,7 +16,7 @@ namespace blink {
namespace {
// Roughly caclculates amount of memory which is used to execute pages.
size_t BlinkMemoryWorkloadCaculator() {
uint64_t BlinkMemoryWorkloadCaculator() {
v8::Isolate* isolate = V8PerIsolateData::MainThreadIsolate();
DCHECK(isolate);
v8::HeapStatistics heap_statistics;
......@@ -32,10 +32,6 @@ size_t BlinkMemoryWorkloadCaculator() {
} // 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
void OomInterventionImpl::Create(mojom::blink::OomInterventionRequest request) {
mojo::MakeStrongBinding(
......@@ -57,8 +53,10 @@ OomInterventionImpl::~OomInterventionImpl() = default;
void OomInterventionImpl::StartDetection(
mojom::blink::OomInterventionHostPtr host,
uint64_t memory_workload_threshold,
bool trigger_intervention) {
host_ = std::move(host);
memory_workload_threshold_ = memory_workload_threshold;
trigger_intervention_ = trigger_intervention;
timer_.Start(TimeDelta(), TimeDelta::FromSeconds(1), FROM_HERE);
......@@ -66,9 +64,10 @@ void OomInterventionImpl::StartDetection(
void OomInterventionImpl::Check(TimerBase*) {
DCHECK(host_);
DCHECK_GT(memory_workload_threshold_, 0UL);
size_t workload = workload_calculator_.Run();
if (workload > kMemoryWorkloadThreshold) {
uint64_t workload = workload_calculator_.Run();
if (workload > memory_workload_threshold_) {
host_->OnHighMemoryUsage(trigger_intervention_);
if (trigger_intervention_) {
......
......@@ -21,13 +21,14 @@ class CONTROLLER_EXPORT OomInterventionImpl
public:
static void Create(mojom::blink::OomInterventionRequest);
using MemoryWorkloadCaculator = base::RepeatingCallback<size_t()>;
using MemoryWorkloadCaculator = base::RepeatingCallback<uint64_t()>;
explicit OomInterventionImpl(MemoryWorkloadCaculator);
~OomInterventionImpl() override;
// mojom::blink::OomIntervention:
void StartDetection(mojom::blink::OomInterventionHostPtr,
uint64_t memory_workload_threshold,
bool trigger_intervention) override;
private:
......@@ -35,8 +36,7 @@ class CONTROLLER_EXPORT OomInterventionImpl
void Check(TimerBase*);
// This constant is declared here for testing.
static const size_t kMemoryWorkloadThreshold;
uint64_t memory_workload_threshold_ = 0;
MemoryWorkloadCaculator workload_calculator_;
mojom::blink::OomInterventionHostPtr host_;
......
......@@ -35,10 +35,10 @@ class MockOomInterventionHost : public mojom::blink::OomInterventionHost {
class OomInterventionImplTest : public testing::Test {
public:
size_t MockMemoryWorkloadCalculator() { return memory_workload_; }
uint64_t MockMemoryWorkloadCalculator() { return memory_workload_; }
protected:
size_t memory_workload_ = 0;
uint64_t memory_workload_ = 0;
FrameTestHelpers::WebViewHelper web_view_helper_;
};
......@@ -52,10 +52,15 @@ TEST_F(OomInterventionImplTest, DetectedAndDeclined) {
WTF::Unretained(this)));
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;
MockOomInterventionHost mock_host(mojo::MakeRequest(&host_ptr));
intervention->StartDetection(std::move(host_ptr),
intervention->StartDetection(std::move(host_ptr), threshold,
true /*trigger_intervention*/);
test::RunDelayedTasks(TimeDelta::FromSeconds(1));
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