Add zram field trial.

This adds a field trial for compressed swap.  Chrome OS picks the trial
group to be used, based on the HW address of the wifi controller.  Chrome
assigns a 100% probability to the group picked by Chrome OS.

BUG=chromium-os:37583
TEST=manually tested


Review URL: https://chromiumcodereview.appspot.com/11744024

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@175704 0039d316-1c4b-4281-b951-d872f2087c98
parent 33b12f1b
...@@ -12,6 +12,7 @@ ...@@ -12,6 +12,7 @@
#include "base/callback.h" #include "base/callback.h"
#include "base/chromeos/chromeos_version.h" #include "base/chromeos/chromeos_version.h"
#include "base/command_line.h" #include "base/command_line.h"
#include "base/file_util.h"
#include "base/lazy_instance.h" #include "base/lazy_instance.h"
#include "base/linux_util.h" #include "base/linux_util.h"
#include "base/message_loop.h" #include "base/message_loop.h"
...@@ -717,6 +718,7 @@ void ChromeBrowserMainPartsChromeos::PostMainMessageLoopRun() { ...@@ -717,6 +718,7 @@ void ChromeBrowserMainPartsChromeos::PostMainMessageLoopRun() {
void ChromeBrowserMainPartsChromeos::SetupPlatformFieldTrials() { void ChromeBrowserMainPartsChromeos::SetupPlatformFieldTrials() {
SetupLowMemoryHeadroomFieldTrial(); SetupLowMemoryHeadroomFieldTrial();
SetupZramFieldTrial();
} }
void ChromeBrowserMainPartsChromeos::SetupLowMemoryHeadroomFieldTrial() { void ChromeBrowserMainPartsChromeos::SetupLowMemoryHeadroomFieldTrial() {
...@@ -765,4 +767,40 @@ void ChromeBrowserMainPartsChromeos::SetupLowMemoryHeadroomFieldTrial() { ...@@ -765,4 +767,40 @@ void ChromeBrowserMainPartsChromeos::SetupLowMemoryHeadroomFieldTrial() {
} }
} }
void ChromeBrowserMainPartsChromeos::SetupZramFieldTrial() {
// The dice for this experiment have been thrown at boot. The selected group
// number is stored in a file.
const FilePath kZramGroupPath("/home/chronos/.swap_exp_enrolled");
std::string zram_file_content;
// If the file does not exist, the experiment has not started.
if (!file_util::ReadFileToString(kZramGroupPath, &zram_file_content))
return;
// The file contains a single significant character, possibly followed by
// newline. "x" means the user has opted out. "0" through "8" are the valid
// group names. (See src/platform/init/swap-exp.conf in chromiumos repo for
// group meanings.)
std::string zram_group = zram_file_content.substr(0, 1);
if (zram_group.compare("x") == 0)
return;
const base::FieldTrial::Probability kDivisor = 1; // on/off only
scoped_refptr<base::FieldTrial> trial =
base::FieldTrialList::FactoryGetFieldTrial(
"ZRAM", kDivisor, "default", 2013, 12, 31, NULL);
// Assign probability of 1 to the group Chrome OS has picked. Assign 0 to
// all other choices.
const char* const kGroups[] = { "0", "1", "2", "3", "4", "5", "6", "7", "8" };
bool matched = false;
for (size_t i = 0; i < arraysize(kGroups); ++i) {
bool match = zram_group.compare(kGroups[i]) == 0;
trial->AppendGroup(kGroups[i], match ? 1 : 0);
if (match) {
matched = true;
LOG(WARNING) << "zram field trial: group " << kGroups[i];
}
}
if (!matched)
LOG(WARNING) << "zram field trial: invalid group \"" << zram_group << "\"";
}
} // namespace chromeos } // namespace chromeos
...@@ -64,6 +64,7 @@ class ChromeBrowserMainPartsChromeos : public ChromeBrowserMainPartsLinux { ...@@ -64,6 +64,7 @@ class ChromeBrowserMainPartsChromeos : public ChromeBrowserMainPartsLinux {
private: private:
// Set up field trial for low memory headroom settings. // Set up field trial for low memory headroom settings.
void SetupLowMemoryHeadroomFieldTrial(); void SetupLowMemoryHeadroomFieldTrial();
void SetupZramFieldTrial();
scoped_ptr<contacts::ContactManager> contact_manager_; scoped_ptr<contacts::ContactManager> contact_manager_;
scoped_ptr<BrightnessObserver> brightness_observer_; scoped_ptr<BrightnessObserver> brightness_observer_;
......
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