Commit 07443d87 authored by thestig's avatar thestig Committed by Commit bot

Cleanup Linux OOM adjustment code.

Review-Url: https://codereview.chromium.org/2744783002
Cr-Commit-Position: refs/heads/master@{#456205}
parent 9d2ce527
......@@ -62,12 +62,13 @@
#if defined(OS_WIN)
#include <atlbase.h>
#include <malloc.h>
#include <algorithm>
#include "base/debug/close_handle_hook_win.h"
#include "chrome/browser/downgrade/user_data_downgrade.h"
#include "chrome/child/v8_breakpad_support_win.h"
#include "chrome/common/child_process_logging.h"
#include "components/crash/content/app/crashpad.h"
#include "sandbox/win/src/sandbox.h"
#include "ui/base/resource/resource_bundle_win.h"
#endif
......@@ -78,7 +79,6 @@
#include "chrome/browser/mac/relauncher.h"
#include "chrome/browser/shell_integration.h"
#include "chrome/common/mac/cfbundle_blocker.h"
#include "components/crash/content/app/crashpad.h"
#include "components/crash/core/common/objc_zombie.h"
#include "ui/base/l10n/l10n_util_mac.h"
#endif
......@@ -127,6 +127,7 @@
#if defined(OS_MACOSX) || defined(OS_WIN)
#include "chrome/browser/policy/policy_path_parser.h"
#include "components/crash/content/app/crashpad.h"
#endif
#if defined(OS_CHROMEOS)
......@@ -222,7 +223,7 @@ bool UseHooks() {
#endif // defined(OS_WIN)
#if defined(OS_LINUX)
static void AdjustLinuxOOMScore(const std::string& process_type) {
void AdjustLinuxOOMScore(const std::string& process_type) {
// Browsers and zygotes should still be killable, but killed last.
const int kZygoteScore = 0;
// The minimum amount to bump a score by. This is large enough that
......@@ -271,6 +272,9 @@ static void AdjustLinuxOOMScore(const std::string& process_type) {
} else {
NOTREACHED() << "Unknown process type";
}
// In the case of a 0 score, still try to adjust it. Most likely the score is
// 0 already, but it may not be if this process inherited a higher score from
// its parent process.
if (score > -1)
base::AdjustOOMScore(base::GetCurrentProcId(), score);
}
......
......@@ -244,38 +244,40 @@ void ZygoteHostImpl::AdjustRendererOOMScore(base::ProcessHandle pid,
base::FileEnumerator en(kSelinuxPath, false, base::FileEnumerator::FILES);
bool has_selinux_files = !en.Next().empty();
selinux = access(kSelinuxPath.value().c_str(), X_OK) == 0 &&
has_selinux_files;
selinux =
has_selinux_files && access(kSelinuxPath.value().c_str(), X_OK) == 0;
selinux_valid = true;
}
if (use_suid_sandbox_for_adj_oom_score_ && !selinux) {
// 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 (base::allocator::IsHeapProfilerRunning())
return;
std::vector<std::string> adj_oom_score_cmdline;
adj_oom_score_cmdline.push_back(sandbox_binary_);
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));
base::Process sandbox_helper_process;
base::LaunchOptions options;
// sandbox_helper_process is a setuid binary.
options.allow_new_privs = true;
sandbox_helper_process =
base::LaunchProcess(adj_oom_score_cmdline, options);
if (sandbox_helper_process.IsValid())
base::EnsureProcessGetsReaped(sandbox_helper_process.Pid());
} else if (!use_suid_sandbox_for_adj_oom_score_) {
if (!use_suid_sandbox_for_adj_oom_score_) {
if (!base::AdjustOOMScore(pid, score))
PLOG(ERROR) << "Failed to adjust OOM score of renderer with pid " << pid;
return;
}
if (selinux)
return;
// 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 (base::allocator::IsHeapProfilerRunning())
return;
std::vector<std::string> adj_oom_score_cmdline;
adj_oom_score_cmdline.push_back(sandbox_binary_);
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));
// sandbox_helper_process is a setuid binary.
base::LaunchOptions options;
options.allow_new_privs = true;
base::Process sandbox_helper_process =
base::LaunchProcess(adj_oom_score_cmdline, options);
if (sandbox_helper_process.IsValid())
base::EnsureProcessGetsReaped(sandbox_helper_process.Pid());
}
#endif
......
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