Commit b3a9dbd9 authored by Takashi Sakamoto's avatar Takashi Sakamoto Committed by Commit Bot

Make UserLevelMemoryPressureSignal feature available on chrome desktop.

We will make UserLevelMemoryPressureSignal feature available on chrome desktop, because MemoryUsageMonitor is available on Linux, Windows and MacOS X now.
The feature is disabled-by-default and is enabled only on Android by using GCL. So this change doesn't enable the feature on chrome desktop.

Bug: 920922
Change-Id: Idbcdef6693ea3956a3f010065f5d21c5fb4594cc
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2015474Reviewed-by: default avatarKentaro Hara <haraken@chromium.org>
Reviewed-by: default avatarErik Chen <erikchen@chromium.org>
Commit-Queue: Takashi Sakamoto <tasak@google.com>
Cr-Commit-Position: refs/heads/master@{#735312}
parent 82459860
......@@ -60,8 +60,6 @@ jumbo_component("controller") {
"memory_usage_monitor_posix.h",
"oom_intervention_impl.cc",
"oom_intervention_impl.h",
"user_level_memory_pressure_signal_generator.cc",
"user_level_memory_pressure_signal_generator.h",
]
}
if (is_win) {
......@@ -80,12 +78,15 @@ jumbo_component("controller") {
"Foundation.framework",
]
}
# HighestPmfReporter depends on MemoryUsageMonitor and MemoryUsageMonitor
# depends on platform specific code. Explicitly specify supported platforms.
if (is_linux || is_win || is_android || is_mac) {
sources += [
"highest_pmf_reporter.cc",
"highest_pmf_reporter.h",
"user_level_memory_pressure_signal_generator.cc",
"user_level_memory_pressure_signal_generator.h",
]
}
......
......@@ -63,7 +63,6 @@
#if defined(OS_ANDROID)
#include "third_party/blink/renderer/controller/crash_memory_metrics_reporter_impl.h"
#include "third_party/blink/renderer/controller/oom_intervention_impl.h"
#include "third_party/blink/renderer/controller/user_level_memory_pressure_signal_generator.h"
#endif
#if defined(OS_LINUX)
......@@ -73,6 +72,7 @@
#if defined(OS_LINUX) || defined(OS_ANDROID) || defined(OS_MACOSX) || \
defined(OS_WIN)
#include "third_party/blink/renderer/controller/highest_pmf_reporter.h"
#include "third_party/blink/renderer/controller/user_level_memory_pressure_signal_generator.h"
#endif
namespace blink {
......@@ -141,9 +141,6 @@ void InitializeCommon(Platform* platform, mojo::BinderMap* binders) {
MemoryAblationExperiment::MaybeStartForRenderer(task_runner);
#if defined(OS_ANDROID)
// Initialize UserLevelMemoryPressureSignalGenerator so it starts monitoring.
UserLevelMemoryPressureSignalGenerator::Instance();
// Initialize CrashMemoryMetricsReporterImpl in order to assure that memory
// allocation does not happen in OnOOMCallback.
CrashMemoryMetricsReporterImpl::Instance();
......@@ -151,6 +148,10 @@ void InitializeCommon(Platform* platform, mojo::BinderMap* binders) {
#if defined(OS_LINUX) || defined(OS_ANDROID) || defined(OS_MACOSX) || \
defined(OS_WIN)
// Initialize UserLevelMemoryPressureSignalGenerator so it starts monitoring.
if (UserLevelMemoryPressureSignalGenerator::Enabled())
UserLevelMemoryPressureSignalGenerator::Instance();
// Start reporting the highest private memory footprint after the first
// navigation.
HighestPmfReporter::Instance();
......
......@@ -23,32 +23,68 @@ namespace {
constexpr double kDefaultMemoryThresholdMB =
std::numeric_limits<double>::infinity();
constexpr base::FeatureParam<double> k512MBDeviceMemoryThresholdParam{
&blink::features::kUserLevelMemoryPressureSignal,
"param_512mb_device_memory_threshold_mb", kDefaultMemoryThresholdMB};
double MemoryThresholdParamOf512MbDevices() {
static const base::FeatureParam<double> k512MBDeviceMemoryThresholdParam{
&blink::features::kUserLevelMemoryPressureSignal,
"param_512mb_device_memory_threshold_mb", kDefaultMemoryThresholdMB};
return k512MBDeviceMemoryThresholdParam.Get();
}
constexpr base::FeatureParam<double> k1GBDeviceMemoryThresholdParam{
&blink::features::kUserLevelMemoryPressureSignal,
"param_1gb_device_memory_threshold_mb", kDefaultMemoryThresholdMB};
double MemoryThresholdParamOf1GbDevices() {
static const base::FeatureParam<double> k1GBDeviceMemoryThresholdParam{
&blink::features::kUserLevelMemoryPressureSignal,
"param_1gb_device_memory_threshold_mb", kDefaultMemoryThresholdMB};
return k1GBDeviceMemoryThresholdParam.Get();
}
constexpr base::FeatureParam<double> k2GBDeviceMemoryThresholdParam{
&blink::features::kUserLevelMemoryPressureSignal,
"param_2gb_device_memory_threshold_mb", kDefaultMemoryThresholdMB};
double MemoryThresholdParamOf2GbDevices() {
static const base::FeatureParam<double> k2GBDeviceMemoryThresholdParam{
&blink::features::kUserLevelMemoryPressureSignal,
"param_2gb_device_memory_threshold_mb", kDefaultMemoryThresholdMB};
return k2GBDeviceMemoryThresholdParam.Get();
}
constexpr base::FeatureParam<double> k3GBDeviceMemoryThresholdParam{
&blink::features::kUserLevelMemoryPressureSignal,
"param_3gb_device_memory_threshold_mb", kDefaultMemoryThresholdMB};
double MemoryThresholdParamOf3GbDevices() {
static const base::FeatureParam<double> k3GBDeviceMemoryThresholdParam{
&blink::features::kUserLevelMemoryPressureSignal,
"param_3gb_device_memory_threshold_mb", kDefaultMemoryThresholdMB};
return k3GBDeviceMemoryThresholdParam.Get();
}
constexpr base::FeatureParam<double> k4GBDeviceMemoryThresholdParam{
&blink::features::kUserLevelMemoryPressureSignal,
"param_4gb_device_memory_threshold_mb", kDefaultMemoryThresholdMB};
double MemoryThresholdParamOf4GbDevices() {
static const base::FeatureParam<double> k4GBDeviceMemoryThresholdParam{
&blink::features::kUserLevelMemoryPressureSignal,
"param_4gb_device_memory_threshold_mb", kDefaultMemoryThresholdMB};
return k4GBDeviceMemoryThresholdParam.Get();
}
// Minimum time interval between generated memory pressure signals.
constexpr double kDefaultMinimumIntervalSeconds = 10 * 60;
constexpr base::FeatureParam<double> kMinimumIntervalSeconds{
&blink::features::kUserLevelMemoryPressureSignal, "minimum_interval_s",
kDefaultMinimumIntervalSeconds};
// Minimum time interval between generated memory pressure signals.
base::TimeDelta MinimumIntervalSeconds() {
static const base::FeatureParam<double> kMinimumIntervalSeconds{
&blink::features::kUserLevelMemoryPressureSignal, "minimum_interval_s",
kDefaultMinimumIntervalSeconds};
return base::TimeDelta::FromSeconds(kMinimumIntervalSeconds.Get());
}
double MemoryThresholdParam() {
int64_t physical_memory = base::SysInfo::AmountOfPhysicalMemory();
double memory_threshold_mb = kDefaultMemoryThresholdMB;
if (physical_memory > 3.1 * 1024 * 1024 * 1024)
memory_threshold_mb = MemoryThresholdParamOf4GbDevices();
else if (physical_memory > 2.1 * 1024 * 1024 * 1024)
memory_threshold_mb = MemoryThresholdParamOf3GbDevices();
else if (physical_memory > 1.1 * 1024 * 1024 * 1024)
memory_threshold_mb = MemoryThresholdParamOf2GbDevices();
else if (physical_memory > 600 * 1024 * 1024)
memory_threshold_mb = MemoryThresholdParamOf1GbDevices();
else
memory_threshold_mb = MemoryThresholdParamOf512MbDevices();
return memory_threshold_mb;
}
} // namespace
......@@ -59,37 +95,31 @@ UserLevelMemoryPressureSignalGenerator::Instance() {
return generator;
}
// static
bool UserLevelMemoryPressureSignalGenerator::Enabled() {
if (!base::FeatureList::IsEnabled(
blink::features::kUserLevelMemoryPressureSignal))
return false;
// Can be disabled for certain device classes by setting the field param to an
// empty string.
return !std::isinf(MemoryThresholdParam());
}
UserLevelMemoryPressureSignalGenerator::UserLevelMemoryPressureSignalGenerator()
: delayed_report_timer_(
: memory_threshold_mb_(MemoryThresholdParam()),
minimum_interval_(MinimumIntervalSeconds()),
delayed_report_timer_(
Thread::MainThread()->GetTaskRunner(),
this,
&UserLevelMemoryPressureSignalGenerator::OnTimerFired),
clock_(base::DefaultTickClock::GetInstance()) {
int64_t physical_memory = base::SysInfo::AmountOfPhysicalMemory();
if (physical_memory > 3.1 * 1024 * 1024 * 1024)
memory_threshold_mb_ = k4GBDeviceMemoryThresholdParam.Get();
else if (physical_memory > 2.1 * 1024 * 1024 * 1024)
memory_threshold_mb_ = k3GBDeviceMemoryThresholdParam.Get();
else if (physical_memory > 1.1 * 1024 * 1024 * 1024)
memory_threshold_mb_ = k2GBDeviceMemoryThresholdParam.Get();
else if (physical_memory > 600 * 1024 * 1024)
memory_threshold_mb_ = k1GBDeviceMemoryThresholdParam.Get();
else
memory_threshold_mb_ = k512MBDeviceMemoryThresholdParam.Get();
minimum_interval_ =
base::TimeDelta::FromSeconds(kMinimumIntervalSeconds.Get());
DCHECK(base::FeatureList::IsEnabled(
blink::features::kUserLevelMemoryPressureSignal));
DCHECK(!std::isinf(memory_threshold_mb_));
// Can be disabled for certain device classes by setting the field param to an
// empty string.
bool enabled = base::FeatureList::IsEnabled(
blink::features::kUserLevelMemoryPressureSignal) &&
!std::isinf(memory_threshold_mb_);
if (enabled) {
monitoring_ = true;
MemoryUsageMonitor::Instance().AddObserver(this);
ThreadScheduler::Current()->AddRAILModeObserver(this);
}
MemoryUsageMonitor::Instance().AddObserver(this);
ThreadScheduler::Current()->AddRAILModeObserver(this);
}
UserLevelMemoryPressureSignalGenerator::
......@@ -116,7 +146,7 @@ void UserLevelMemoryPressureSignalGenerator::OnMemoryPing(MemoryUsage usage) {
if (usage.private_footprint_bytes / 1024 / 1024 < memory_threshold_mb_)
return;
base::TimeDelta elapsed = clock_->NowTicks() - last_generated_;
if (elapsed >= base::TimeDelta::FromSeconds(kMinimumIntervalSeconds.Get()))
if (elapsed >= MinimumIntervalSeconds())
Generate(usage);
}
......
......@@ -31,6 +31,7 @@ class CONTROLLER_EXPORT UserLevelMemoryPressureSignalGenerator
public:
// Returns the shared instance.
static UserLevelMemoryPressureSignalGenerator& Instance();
static bool Enabled();
UserLevelMemoryPressureSignalGenerator();
~UserLevelMemoryPressureSignalGenerator() override;
......@@ -55,7 +56,6 @@ class CONTROLLER_EXPORT UserLevelMemoryPressureSignalGenerator
// MemoryUsageMonitor::Observer:
void OnMemoryPing(MemoryUsage) override;
bool monitoring_ = false;
bool is_loading_ = false;
base::TimeTicks last_generated_;
double memory_threshold_mb_;
......
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