Commit f735c7a3 authored by xdai's avatar xdai Committed by Commit bot

Add a finch experiment for different memory pressure management strategies in ChromeOS.

BUG=455885,447280

Review URL: https://codereview.chromium.org/897413002

Cr-Commit-Position: refs/heads/master@{#315907}
parent e86588ab
......@@ -308,15 +308,19 @@ const Experiment::Choice kEnableGpuRasterizationChoices[] = {
#if defined(OS_CHROMEOS)
const Experiment::Choice kMemoryPressureThresholdChoices[] = {
{ IDS_GENERIC_EXPERIMENT_CHOICE_DEFAULT, "", "" },
{ IDS_FLAGS_CONSERVATIVE_THRESHOLDS,
chromeos::switches::kMemoryPressureThresholds, "1" },
{ IDS_FLAGS_AGGRESSIVE_CACHE_DISCARD_THRESHOLDS,
chromeos::switches::kMemoryPressureThresholds, "2" },
{ IDS_FLAGS_AGGRESSIVE_TAB_DISCARD_THRESHOLDS,
chromeos::switches::kMemoryPressureThresholds, "3" },
{ IDS_FLAGS_AGGRESSIVE_THRESHOLDS,
chromeos::switches::kMemoryPressureThresholds, "4" },
{ IDS_GENERIC_EXPERIMENT_CHOICE_DEFAULT, "", "" },
{ IDS_FLAGS_CONSERVATIVE_THRESHOLDS,
chromeos::switches::kMemoryPressureThresholds,
chromeos::switches::kConservativeThreshold },
{ IDS_FLAGS_AGGRESSIVE_CACHE_DISCARD_THRESHOLDS,
chromeos::switches::kMemoryPressureThresholds,
chromeos::switches::kAggressiveCacheDiscardThreshold },
{ IDS_FLAGS_AGGRESSIVE_TAB_DISCARD_THRESHOLDS,
chromeos::switches::kMemoryPressureThresholds,
chromeos::switches::kAggressiveTabDiscardThreshold },
{ IDS_FLAGS_AGGRESSIVE_THRESHOLDS,
chromeos::switches::kMemoryPressureThresholds,
chromeos::switches::kAggressiveThreshold },
};
#endif
......
......@@ -5,6 +5,7 @@
#include "chromeos/chromeos_switches.h"
#include "base/command_line.h"
#include "base/metrics/field_trial.h"
// TODO(rsorokin): alphabetize all of these switches so they
// match the order from the .h file
......@@ -221,9 +222,14 @@ const char kLoginProfile[] = "login-profile";
// Specifies the user which is already logged in.
const char kLoginUser[] = "login-user";
// The memory pressure thresholds selection which is used to decide when a
// memory pressure event needs to get fired.
// The memory pressure thresholds selection which is used to decide whether and
// when a memory pressure event needs to get fired.
const char kMemoryPressureHandlingOff[] = "memory-pressure-off";
const char kMemoryPressureThresholds[] = "memory-pressure-thresholds";
const char kConservativeThreshold[] = "conservative";
const char kAggressiveCacheDiscardThreshold[] = "aggressive-cache-discard";
const char kAggressiveTabDiscardThreshold[] = "aggressive-tab-discard";
const char kAggressiveThreshold[] = "aggressive";
// Enables natural scroll by default.
const char kNaturalScrollDefault[] = "enable-natural-scroll-default";
......@@ -312,27 +318,49 @@ bool WakeOnWifiEnabled() {
return !base::CommandLine::ForCurrentProcess()->HasSwitch(kDisableWakeOnWifi);
}
bool MemoryPressureHandlingEnabled() {
if ((base::CommandLine::ForCurrentProcess()->HasSwitch(
chromeos::switches::kDisableMemoryPressureSystemChromeOS)) ||
(base::FieldTrialList::FindFullName(kMemoryPressureThresholds) ==
kMemoryPressureHandlingOff))
return false;
return true;
}
base::MemoryPressureObserverChromeOS::MemoryPressureThresholds
GetMemoryPressureThresholds() {
if (!base::CommandLine::ForCurrentProcess()->HasSwitch(
kMemoryPressureThresholds)) {
const std::string group_name =
base::FieldTrialList::FindFullName(kMemoryPressureThresholds);
if (group_name == kConservativeThreshold)
return base::MemoryPressureObserverChromeOS::THRESHOLD_CONSERVATIVE;
if (group_name == kAggressiveCacheDiscardThreshold)
return base::MemoryPressureObserverChromeOS::
THRESHOLD_AGGRESSIVE_CACHE_DISCARD;
if (group_name == kAggressiveTabDiscardThreshold)
return base::MemoryPressureObserverChromeOS::
THRESHOLD_AGGRESSIVE_TAB_DISCARD;
if (group_name == kAggressiveThreshold)
return base::MemoryPressureObserverChromeOS::THRESHOLD_AGGRESSIVE;
return base::MemoryPressureObserverChromeOS::THRESHOLD_DEFAULT;
}
const std::string option =
base::CommandLine::ForCurrentProcess()->GetSwitchValueASCII(
kMemoryPressureThresholds);
if (option == "1") {
if (option == kConservativeThreshold)
return base::MemoryPressureObserverChromeOS::THRESHOLD_CONSERVATIVE;
}
if (option == "2") {
if (option == kAggressiveCacheDiscardThreshold)
return base::MemoryPressureObserverChromeOS::
THRESHOLD_AGGRESSIVE_CACHE_DISCARD;
}
if (option == "3") {
if (option == kAggressiveTabDiscardThreshold)
return base::MemoryPressureObserverChromeOS::
THRESHOLD_AGGRESSIVE_TAB_DISCARD;
}
return base::MemoryPressureObserverChromeOS::THRESHOLD_AGGRESSIVE;
if (option == kAggressiveThreshold)
return base::MemoryPressureObserverChromeOS::THRESHOLD_AGGRESSIVE;
return base::MemoryPressureObserverChromeOS::THRESHOLD_DEFAULT;
}
} // namespace switches
......
......@@ -88,6 +88,10 @@ CHROMEOS_EXPORT extern const char kLoginManager[];
CHROMEOS_EXPORT extern const char kLoginProfile[];
CHROMEOS_EXPORT extern const char kLoginUser[];
CHROMEOS_EXPORT extern const char kMemoryPressureThresholds[];
CHROMEOS_EXPORT extern const char kConservativeThreshold[];
CHROMEOS_EXPORT extern const char kAggressiveCacheDiscardThreshold[];
CHROMEOS_EXPORT extern const char kAggressiveTabDiscardThreshold[];
CHROMEOS_EXPORT extern const char kAggressiveThreshold[];
CHROMEOS_EXPORT extern const char kNaturalScrollDefault[];
CHROMEOS_EXPORT extern const char kOobeGuestSession[];
CHROMEOS_EXPORT extern const char kOobeSkipPostLogin[];
......@@ -104,6 +108,7 @@ CHROMEOS_EXPORT extern const char kDisableTimeZoneTrackingOption[];
CHROMEOS_EXPORT bool WakeOnWifiEnabled();
CHROMEOS_EXPORT bool MemoryPressureHandlingEnabled();
CHROMEOS_EXPORT base::MemoryPressureObserverChromeOS::MemoryPressureThresholds
GetMemoryPressureThresholds();
......
......@@ -488,8 +488,7 @@ void BrowserMainLoop::MainMessageLoopStart() {
InitializeMainThread();
#if defined(OS_CHROMEOS)
if (!base::CommandLine::ForCurrentProcess()->HasSwitch(
chromeos::switches::kDisableMemoryPressureSystemChromeOS)) {
if (chromeos::switches::MemoryPressureHandlingEnabled()) {
memory_pressure_observer_.reset(new base::MemoryPressureObserverChromeOS(
chromeos::switches::GetMemoryPressureThresholds()));
}
......
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