summaryrefslogtreecommitdiffstats
path: root/content/browser/zygote_host_impl_linux.cc
diff options
context:
space:
mode:
authorgspencer@chromium.org <gspencer@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2012-05-03 20:30:43 +0000
committergspencer@chromium.org <gspencer@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2012-05-03 20:30:43 +0000
commit232ed4691df490e376c74ecf04f2f6092f03427f (patch)
tree3dd09707acccf9eb175e592b4f0fbade06a5015b /content/browser/zygote_host_impl_linux.cc
parent9a4fd693db2ee9e383f7a826d50bc63bc5bf7db0 (diff)
downloadchromium_src-232ed4691df490e376c74ecf04f2f6092f03427f.zip
chromium_src-232ed4691df490e376c74ecf04f2f6092f03427f.tar.gz
chromium_src-232ed4691df490e376c74ecf04f2f6092f03427f.tar.bz2
This creates a field trial to determine the best level for low memory
notification. It creates a field trial with 7 groups: default (kernel default value), turning notification off (relying on OOM killer only), 0MB, 25MB, 50MB margin, 100MB margin, and 200MB margin. Also, in order to set parameters for the trial, this CL creates an API for setting the low memory margin. BUG=chromium-os:20080 TEST=Ran on device several times, checked that the memory margin was set correctly when the session started, and that different trial groups were selected. Review URL: http://codereview.chromium.org/10206029 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@135205 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'content/browser/zygote_host_impl_linux.cc')
-rw-r--r--content/browser/zygote_host_impl_linux.cc42
1 files changed, 37 insertions, 5 deletions
diff --git a/content/browser/zygote_host_impl_linux.cc b/content/browser/zygote_host_impl_linux.cc
index 519fa12..40dcc6a 100644
--- a/content/browser/zygote_host_impl_linux.cc
+++ b/content/browser/zygote_host_impl_linux.cc
@@ -30,6 +30,7 @@
#include "content/public/browser/content_browser_client.h"
#include "content/public/common/content_switches.h"
#include "content/public/common/result_codes.h"
+#include "sandbox/linux/suid/sandbox.h"
#include "sandbox/linux/suid/suid_unsafe_environment_variables.h"
#if defined(USE_TCMALLOC)
@@ -371,13 +372,9 @@ void ZygoteHostImpl::AdjustRendererOOMScore(base::ProcessHandle pid,
if (IsHeapProfilerRunning())
return;
#endif
- // The command line switch used for supplying the OOM adjustment score
- // to the setuid sandbox.
- static const char kAdjustOOMScoreSwitch[] = "--adjust-oom-score";
-
std::vector<std::string> adj_oom_score_cmdline;
adj_oom_score_cmdline.push_back(sandbox_binary_);
- adj_oom_score_cmdline.push_back(kAdjustOOMScoreSwitch);
+ adj_oom_score_cmdline.push_back(sandbox::kAdjustOOMScoreSwitch);
adj_oom_score_cmdline.push_back(base::Int64ToString(pid));
adj_oom_score_cmdline.push_back(base::IntToString(score));
@@ -393,6 +390,41 @@ void ZygoteHostImpl::AdjustRendererOOMScore(base::ProcessHandle pid,
}
#endif
+void ZygoteHostImpl::AdjustLowMemoryMargin(int64 margin_mb) {
+#if defined(OS_CHROMEOS)
+ // You can't change the low memory margin unless you're root. Because of this,
+ // we can't set the low memory margin from the browser process.
+ // So, we use the SUID binary to change it for us.
+ if (using_suid_sandbox_) {
+#if defined(USE_TCMALLOC)
+ // If heap profiling is running, these processes are not exiting, at least
+ // on ChromeOS. The easiest thing to do is not launch them when profiling.
+ // TODO(stevenjb): Investigate further and fix.
+ if (IsHeapProfilerRunning())
+ return;
+#endif
+ std::vector<std::string> adj_low_mem_commandline;
+ adj_low_mem_commandline.push_back(sandbox_binary_);
+ adj_low_mem_commandline.push_back(sandbox::kAdjustLowMemMarginSwitch);
+ adj_low_mem_commandline.push_back(base::Int64ToString(margin_mb));
+
+ base::ProcessHandle sandbox_helper_process;
+ if (base::LaunchProcess(adj_low_mem_commandline, base::LaunchOptions(),
+ &sandbox_helper_process)) {
+ base::EnsureProcessGetsReaped(sandbox_helper_process);
+ } else {
+ LOG(ERROR) << "Unable to run suid sandbox to set low memory margin.";
+ }
+ }
+ // Don't adjust memory margin if we're not running with the sandbox: this
+ // isn't very common, and not doing it has little impact.
+#else
+ // Low memory notification is currently only implemented on ChromeOS.
+ NOTREACHED() << "AdjustLowMemoryMargin not implemented";
+#endif // defined(OS_CHROMEOS)
+}
+
+
void ZygoteHostImpl::EnsureProcessTerminated(pid_t process) {
DCHECK(init_);
Pickle pickle;