Commit 0c2124b3 authored by Siddhartha's avatar Siddhartha Committed by Commit Bot

Use thresholds based on RAM size for OOM intervention

This CL does not change behavior of existing experiment on 512 devices.
1. Remove low-end device checks while enabling intervention. This can be
   filtered in Finch config.
2. Set threshold based on percentage of RAM instead of absolute number.
3. Disable intervention if device has more than 512MB RAM and threshold
   was set to absolute number.

BUG=843419


Change-Id: Ib40a038d9d2f111a514b3f41ce7f32a3ea3a156d
Reviewed-on: https://chromium-review.googlesource.com/1066804
Commit-Queue: Siddhartha S <ssid@chromium.org>
Reviewed-by: default avatarKenichi Ishibashi <bashi@chromium.org>
Cr-Commit-Position: refs/heads/master@{#560430}
parent e4d10fd3
...@@ -6,6 +6,7 @@ ...@@ -6,6 +6,7 @@
#include "base/feature_list.h" #include "base/feature_list.h"
#include "base/metrics/field_trial_params.h" #include "base/metrics/field_trial_params.h"
#include "base/strings/string_number_conversions.h"
#include "base/sys_info.h" #include "base/sys_info.h"
#include "base/threading/thread_task_runner_handle.h" #include "base/threading/thread_task_runner_handle.h"
#include "chrome/common/chrome_features.h" #include "chrome/common/chrome_features.h"
...@@ -15,6 +16,10 @@ namespace { ...@@ -15,6 +16,10 @@ namespace {
const char kSwapFreeThresholdRatioParamName[] = "swap_free_threshold_ratio"; const char kSwapFreeThresholdRatioParamName[] = "swap_free_threshold_ratio";
const char kUseComponentCallbacks[] = "use_component_callbacks"; const char kUseComponentCallbacks[] = "use_component_callbacks";
const char kRendererWorkloadThresholdDeprecated[] =
"renderer_workload_threshold";
const char kRendererWorkloadThresholdPercentage[] =
"renderer_workload_threshold_percentage";
// Default SwapFree/SwapTotal ratio for detecting near-OOM situation. // Default SwapFree/SwapTotal ratio for detecting near-OOM situation.
// TODO(bashi): Confirm that this is appropriate. // TODO(bashi): Confirm that this is appropriate.
...@@ -28,14 +33,36 @@ constexpr base::TimeDelta kDefaultMonitoringDelta = ...@@ -28,14 +33,36 @@ constexpr base::TimeDelta kDefaultMonitoringDelta =
constexpr base::TimeDelta kDefaultCooldownDelta = constexpr base::TimeDelta kDefaultCooldownDelta =
base::TimeDelta::FromSeconds(30); base::TimeDelta::FromSeconds(30);
uint64_t GetRendererMemoryWorkloadThreshold() {
// Approximately 80MB for 512MB devices.
const uint64_t kDefaultMemoryWorkloadThresholdPercent = 16;
std::string threshold_str = base::GetFieldTrialParamValueByFeature(
features::kOomIntervention, kRendererWorkloadThresholdPercentage);
uint64_t threshold = 0;
size_t ram_size = base::SysInfo::AmountOfPhysicalMemory();
if (base::StringToUint64(threshold_str, &threshold)) {
return threshold * ram_size / 100;
}
// If the old trigger param is set, then enable intervention only on 512MB
// devices.
threshold_str = base::GetFieldTrialParamValueByFeature(
features::kOomIntervention, kRendererWorkloadThresholdDeprecated);
if (base::StringToUint64(threshold_str, &threshold)) {
if (ram_size > 512 * 1024 * 1024)
return 0;
return threshold;
}
return kDefaultMemoryWorkloadThresholdPercent * ram_size / 100;
}
} // namespace } // namespace
// static // static
NearOomMonitor* NearOomMonitor::Create() { NearOomMonitor* NearOomMonitor::Create() {
if (!base::FeatureList::IsEnabled(features::kOomIntervention)) if (!base::FeatureList::IsEnabled(features::kOomIntervention))
return nullptr; return nullptr;
if (!base::SysInfo::IsLowEndDevice())
return nullptr;
base::SystemMemoryInfoKB memory_info; base::SystemMemoryInfoKB memory_info;
if (!base::GetSystemMemoryInfo(&memory_info)) if (!base::GetSystemMemoryInfo(&memory_info))
...@@ -51,8 +78,12 @@ NearOomMonitor* NearOomMonitor::Create() { ...@@ -51,8 +78,12 @@ NearOomMonitor* NearOomMonitor::Create() {
kDefaultSwapFreeThresholdRatio); kDefaultSwapFreeThresholdRatio);
int64_t swapfree_threshold = int64_t swapfree_threshold =
static_cast<int64_t>(memory_info.swap_total * threshold_ratio); static_cast<int64_t>(memory_info.swap_total * threshold_ratio);
uint64_t renderer_workload_threshold = GetRendererMemoryWorkloadThreshold();
if (!renderer_workload_threshold)
return nullptr;
return new NearOomMonitor(base::ThreadTaskRunnerHandle::Get(), return new NearOomMonitor(base::ThreadTaskRunnerHandle::Get(),
swapfree_threshold); swapfree_threshold, renderer_workload_threshold);
} }
// static // static
...@@ -63,13 +94,15 @@ NearOomMonitor* NearOomMonitor::GetInstance() { ...@@ -63,13 +94,15 @@ NearOomMonitor* NearOomMonitor::GetInstance() {
NearOomMonitor::NearOomMonitor( NearOomMonitor::NearOomMonitor(
scoped_refptr<base::SequencedTaskRunner> task_runner, scoped_refptr<base::SequencedTaskRunner> task_runner,
int64_t swapfree_threshold) int64_t swapfree_threshold,
uint64_t renderer_workload_threshold)
: task_runner_(task_runner), : task_runner_(task_runner),
check_callback_( check_callback_(
base::Bind(&NearOomMonitor::Check, base::Unretained(this))), base::Bind(&NearOomMonitor::Check, base::Unretained(this))),
monitoring_interval_(kDefaultMonitoringDelta), monitoring_interval_(kDefaultMonitoringDelta),
cooldown_interval_(kDefaultCooldownDelta), cooldown_interval_(kDefaultCooldownDelta),
swapfree_threshold_(swapfree_threshold), swapfree_threshold_(swapfree_threshold),
renderer_workload_threshold_(renderer_workload_threshold),
component_callback_is_enabled_( component_callback_is_enabled_(
base::GetFieldTrialParamByFeatureAsBool(features::kOomIntervention, base::GetFieldTrialParamByFeatureAsBool(features::kOomIntervention,
kUseComponentCallbacks, kUseComponentCallbacks,
......
...@@ -39,11 +39,16 @@ class NearOomMonitor { ...@@ -39,11 +39,16 @@ class NearOomMonitor {
void OnLowMemory(JNIEnv* env, void OnLowMemory(JNIEnv* env,
const base::android::JavaParamRef<jobject>& jcaller); const base::android::JavaParamRef<jobject>& jcaller);
uint64_t renderer_workload_threshold() const {
return renderer_workload_threshold_;
}
protected: protected:
static NearOomMonitor* Create(); static NearOomMonitor* Create();
NearOomMonitor(scoped_refptr<base::SequencedTaskRunner> task_runner, NearOomMonitor(scoped_refptr<base::SequencedTaskRunner> task_runner,
int64_t swapfree_threshold); int64_t swapfree_threshold,
uint64_t renderer_workload_threshold);
// Gets system memory info. This is a virtual method so that we can override // Gets system memory info. This is a virtual method so that we can override
// this for testing. // this for testing.
...@@ -72,6 +77,7 @@ class NearOomMonitor { ...@@ -72,6 +77,7 @@ class NearOomMonitor {
base::TimeTicks next_check_time_; base::TimeTicks next_check_time_;
int64_t swapfree_threshold_; int64_t swapfree_threshold_;
uint64_t renderer_workload_threshold_;
CallbackList callbacks_; CallbackList callbacks_;
......
...@@ -12,13 +12,16 @@ ...@@ -12,13 +12,16 @@
namespace { namespace {
const int64_t kTestSwapTotalKB = 128 * 1024; const int64_t kTestSwapTotalKB = 128 * 1024;
const int64_t kTestSwapFreeThreshold = kTestSwapTotalKB / 4; const int64_t kTestSwapFreeThreshold = kTestSwapTotalKB / 4;
const uint64_t kRendererWorkloadThreshold = 10 * 1024;
} // namespace } // namespace
class MockNearOomMonitor : public NearOomMonitor { class MockNearOomMonitor : public NearOomMonitor {
public: public:
explicit MockNearOomMonitor( explicit MockNearOomMonitor(
scoped_refptr<base::SequencedTaskRunner> task_runner) scoped_refptr<base::SequencedTaskRunner> task_runner)
: NearOomMonitor(task_runner, kTestSwapFreeThreshold) { : NearOomMonitor(task_runner,
kTestSwapFreeThreshold,
kRendererWorkloadThreshold) {
// Start with 128MB swap total and 64MB swap free. // Start with 128MB swap total and 64MB swap free.
memory_info_.swap_total = kTestSwapTotalKB; memory_info_.swap_total = kTestSwapTotalKB;
memory_info_.swap_free = kTestSwapTotalKB / 2; memory_info_.swap_free = kTestSwapTotalKB / 2;
......
...@@ -61,7 +61,6 @@ void RecordInterventionStateOnCrash(bool accepted) { ...@@ -61,7 +61,6 @@ 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(
...@@ -75,18 +74,6 @@ bool ShouldDetectInRenderer() { ...@@ -75,18 +74,6 @@ 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
...@@ -100,7 +87,8 @@ OomInterventionTabHelper::OomInterventionTabHelper( ...@@ -100,7 +87,8 @@ OomInterventionTabHelper::OomInterventionTabHelper(
decider_(OomInterventionDecider::GetForBrowserContext( decider_(OomInterventionDecider::GetForBrowserContext(
web_contents->GetBrowserContext())), web_contents->GetBrowserContext())),
binding_(this), binding_(this),
renderer_memory_workload_threshold_(GetRendererMemoryWorkloadThreshold()), renderer_memory_workload_threshold_(
NearOomMonitor::GetInstance()->renderer_workload_threshold()),
weak_ptr_factory_(this) { weak_ptr_factory_(this) {
OutOfMemoryReporter::FromWebContents(web_contents)->AddObserver(this); OutOfMemoryReporter::FromWebContents(web_contents)->AddObserver(this);
shared_metrics_buffer_ = base::UnsafeSharedMemoryRegion::Create( shared_metrics_buffer_ = base::UnsafeSharedMemoryRegion::Create(
......
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