Commit bff00c7a authored by Kuo-Hsin Yang's avatar Kuo-Hsin Yang Committed by Commit Bot

Set proper OOM score adj for utility process forked from zygote

Utility process might be forked from zygote process, set proper OOM
score adj in this case.

Move oom score constants to content/public/common/content_constants.h.

Bug: 1051360
Change-Id: Ia0750d5f7aafe10580acdcb5d88c717da131d569
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2051796Reviewed-by: default avatarJohn Abd-El-Malek <jam@chromium.org>
Commit-Queue: Kuo-Hsin Yang <vovoy@chromium.org>
Cr-Commit-Position: refs/heads/master@{#741362}
parent 6eb660ae
...@@ -29,7 +29,6 @@ ...@@ -29,7 +29,6 @@
#include "chrome/browser/defaults.h" #include "chrome/browser/defaults.h"
#include "chrome/common/buildflags.h" #include "chrome/common/buildflags.h"
#include "chrome/common/channel_info.h" #include "chrome/common/channel_info.h"
#include "chrome/common/chrome_constants.h"
#include "chrome/common/chrome_content_client.h" #include "chrome/common/chrome_content_client.h"
#include "chrome/common/chrome_features.h" #include "chrome/common/chrome_features.h"
#include "chrome/common/chrome_paths.h" #include "chrome/common/chrome_paths.h"
...@@ -53,6 +52,7 @@ ...@@ -53,6 +52,7 @@
#include "components/services/heap_profiling/public/cpp/profiling_client.h" #include "components/services/heap_profiling/public/cpp/profiling_client.h"
#include "components/version_info/version_info.h" #include "components/version_info/version_info.h"
#include "content/public/common/content_client.h" #include "content/public/common/content_client.h"
#include "content/public/common/content_constants.h"
#include "content/public/common/content_paths.h" #include "content/public/common/content_paths.h"
#include "content/public/common/content_switches.h" #include "content/public/common/content_switches.h"
#include "content/public/common/profiling.h" #include "content/public/common/profiling.h"
...@@ -275,39 +275,20 @@ void SetUpExtendedCrashReporting(bool is_browser_process) { ...@@ -275,39 +275,20 @@ void SetUpExtendedCrashReporting(bool is_browser_process) {
#if defined(OS_LINUX) #if defined(OS_LINUX)
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
// even if it's translated into the old values, it will still go up
// by at least one.
const int kScoreBump = 100;
// This is the lowest score that renderers and extensions start with
// in the OomPriorityManager.
const int kRendererScore = chrome::kLowestRendererOomScore;
// For "miscellaneous" things, we want them after renderers,
// but before plugins.
const int kMiscScore = kRendererScore - kScoreBump;
// We want plugins to die after the renderers.
const int kPluginScore = kMiscScore - kScoreBump;
int score = -1; int score = -1;
DCHECK_GT(kMiscScore, 0);
DCHECK_GT(kPluginScore, 0);
if (process_type == switches::kPpapiPluginProcess) { if (process_type == switches::kPpapiPluginProcess) {
score = kPluginScore; score = content::kPluginOomScore;
} else if (process_type == switches::kPpapiBrokerProcess) {
// The broker should be killed before the PPAPI plugin.
score = kPluginScore + kScoreBump;
} else if (process_type == switches::kUtilityProcess || } else if (process_type == switches::kUtilityProcess ||
process_type == switches::kGpuProcess || process_type == switches::kGpuProcess ||
process_type == switches::kCloudPrintServiceProcess || process_type == switches::kCloudPrintServiceProcess ||
process_type == service_manager::switches::kProcessTypeService) { process_type == service_manager::switches::kProcessTypeService ||
score = kMiscScore; process_type == switches::kPpapiBrokerProcess) {
score = content::kMiscOomScore;
#if BUILDFLAG(ENABLE_NACL) #if BUILDFLAG(ENABLE_NACL)
} else if (process_type == switches::kNaClLoaderProcess || } else if (process_type == switches::kNaClLoaderProcess ||
process_type == switches::kNaClLoaderNonSfiProcess) { process_type == switches::kNaClLoaderNonSfiProcess) {
score = kPluginScore; score = content::kPluginOomScore;
#endif #endif
} else if (process_type == service_manager::switches::kZygoteProcess || } else if (process_type == service_manager::switches::kZygoteProcess ||
process_type == process_type ==
...@@ -315,14 +296,14 @@ void AdjustLinuxOOMScore(const std::string& process_type) { ...@@ -315,14 +296,14 @@ void AdjustLinuxOOMScore(const std::string& process_type) {
process_type.empty()) { process_type.empty()) {
// For zygotes and unlabeled process types, we want to still make // For zygotes and unlabeled process types, we want to still make
// them killable by the OOM killer. // them killable by the OOM killer.
score = kZygoteScore; score = content::kZygoteOomScore;
} else if (process_type == switches::kRendererProcess) { } else if (process_type == switches::kRendererProcess) {
LOG(WARNING) << "process type 'renderer' " LOG(WARNING) << "process type 'renderer' "
<< "should be created through the zygote."; << "should be created through the zygote.";
// When debugging, this process type can end up being run directly, but // When debugging, this process type can end up being run directly, but
// this isn't the typical path for assigning the OOM score for it. Still, // this isn't the typical path for assigning the OOM score for it. Still,
// we want to assign a score that is somewhat representative for debugging. // we want to assign a score that is somewhat representative for debugging.
score = kRendererScore; score = content::kLowestRendererOomScore;
} else { } else {
NOTREACHED() << "Unknown process type"; NOTREACHED() << "Unknown process type";
} }
......
...@@ -37,7 +37,6 @@ ...@@ -37,7 +37,6 @@
#include "chrome/browser/ui/browser_list.h" #include "chrome/browser/ui/browser_list.h"
#include "chrome/browser/ui/browser_window.h" #include "chrome/browser/ui/browser_window.h"
#include "chrome/browser/ui/tabs/tab_strip_model.h" #include "chrome/browser/ui/tabs/tab_strip_model.h"
#include "chrome/common/chrome_constants.h"
#include "chromeos/dbus/dbus_thread_manager.h" #include "chromeos/dbus/dbus_thread_manager.h"
#include "components/arc/arc_service_manager.h" #include "components/arc/arc_service_manager.h"
#include "components/arc/arc_util.h" #include "components/arc/arc_util.h"
...@@ -49,6 +48,7 @@ ...@@ -49,6 +48,7 @@
#include "content/public/browser/render_frame_host.h" #include "content/public/browser/render_frame_host.h"
#include "content/public/browser/render_process_host.h" #include "content/public/browser/render_process_host.h"
#include "content/public/browser/render_widget_host.h" #include "content/public/browser/render_widget_host.h"
#include "content/public/common/content_constants.h"
#include "services/service_manager/zygote/zygote_host_linux.h" #include "services/service_manager/zygote/zygote_host_linux.h"
#include "ui/wm/public/activation_client.h" #include "ui/wm/public/activation_client.h"
...@@ -391,14 +391,14 @@ void TabManagerDelegate::OnFocusTabScoreAdjustmentTimeout() { ...@@ -391,14 +391,14 @@ void TabManagerDelegate::OnFocusTabScoreAdjustmentTimeout() {
return; return;
// Update the OOM score cache. // Update the OOM score cache.
oom_score_map_[pid] = chrome::kLowestRendererOomScore; oom_score_map_[pid] = content::kLowestRendererOomScore;
// Sets OOM score. // Sets OOM score.
VLOG(3) << "Set OOM score " << chrome::kLowestRendererOomScore VLOG(3) << "Set OOM score " << content::kLowestRendererOomScore
<< " for focused tab " << pid; << " for focused tab " << pid;
if (!base::AdjustOOMScore(pid, chrome::kLowestRendererOomScore)) if (!base::AdjustOOMScore(pid, content::kLowestRendererOomScore))
LOG(ERROR) << "Failed to set oom_score_adj to " LOG(ERROR) << "Failed to set oom_score_adj to "
<< chrome::kLowestRendererOomScore << content::kLowestRendererOomScore
<< " for focused tab, pid: " << pid; << " for focused tab, pid: " << pid;
} }
...@@ -414,8 +414,9 @@ void TabManagerDelegate::AdjustFocusedTabScore(base::ProcessHandle pid) { ...@@ -414,8 +414,9 @@ void TabManagerDelegate::AdjustFocusedTabScore(base::ProcessHandle pid) {
// set it. This can happen in case the newly focused tab is script // set it. This can happen in case the newly focused tab is script
// connected to the previous tab. // connected to the previous tab.
ProcessScoreMap::iterator it = oom_score_map_.find(pid); ProcessScoreMap::iterator it = oom_score_map_.find(pid);
const bool not_lowest_score = (it == oom_score_map_.end() || const bool not_lowest_score =
it->second != chrome::kLowestRendererOomScore); (it == oom_score_map_.end() ||
it->second != content::kLowestRendererOomScore);
if (not_lowest_score) { if (not_lowest_score) {
// By starting a timer we guarantee that the tab is focused for // By starting a timer we guarantee that the tab is focused for
...@@ -763,7 +764,8 @@ void TabManagerDelegate::AdjustOomPrioritiesImpl( ...@@ -763,7 +764,8 @@ void TabManagerDelegate::AdjustOomPrioritiesImpl(
// Break the processes into 2 parts. This is to help lower the chance of // Break the processes into 2 parts. This is to help lower the chance of
// altering OOM score for many processes on any small change. // altering OOM score for many processes on any small change.
int range_middle = int range_middle =
(chrome::kLowestRendererOomScore + chrome::kHighestRendererOomScore) / 2; (content::kLowestRendererOomScore + content::kHighestRendererOomScore) /
2;
// Find some pivot point. FOCUSED_TAB, FOCUSED_APP, and PROTECTED_BACKGROUND // Find some pivot point. FOCUSED_TAB, FOCUSED_APP, and PROTECTED_BACKGROUND
// processes are in the first half and BACKGROUND and CACHED_APP processes // processes are in the first half and BACKGROUND and CACHED_APP processes
...@@ -786,11 +788,11 @@ void TabManagerDelegate::AdjustOomPrioritiesImpl( ...@@ -786,11 +788,11 @@ void TabManagerDelegate::AdjustOomPrioritiesImpl(
// Higher priority part. // Higher priority part.
DistributeOomScoreInRange(candidates.begin(), lower_priority_part, DistributeOomScoreInRange(candidates.begin(), lower_priority_part,
chrome::kLowestRendererOomScore, range_middle, content::kLowestRendererOomScore, range_middle,
&new_map); &new_map);
// Lower priority part. // Lower priority part.
DistributeOomScoreInRange(lower_priority_part, candidates.end(), range_middle, DistributeOomScoreInRange(lower_priority_part, candidates.end(), range_middle,
chrome::kHighestRendererOomScore, &new_map); content::kHighestRendererOomScore, &new_map);
oom_score_map_.swap(new_map); oom_score_map_.swap(new_map);
} }
......
...@@ -209,11 +209,6 @@ const wchar_t kUserDataDirname[] = L"User Data"; ...@@ -209,11 +209,6 @@ const wchar_t kUserDataDirname[] = L"User Data";
const float kMaxShareOfExtensionProcesses = 0.30f; const float kMaxShareOfExtensionProcesses = 0.30f;
#if defined(OS_LINUX)
const int kLowestRendererOomScore = 300;
const int kHighestRendererOomScore = 1000;
#endif
#if defined(OS_CHROMEOS) #if defined(OS_CHROMEOS)
const char kProfileDirPrefix[] = "u-"; const char kProfileDirPrefix[] = "u-";
const char kLegacyProfileDir[] = "user"; const char kLegacyProfileDir[] = "user";
......
...@@ -95,13 +95,6 @@ extern const wchar_t kUserDataDirname[]; ...@@ -95,13 +95,6 @@ extern const wchar_t kUserDataDirname[];
// installed. // installed.
extern const float kMaxShareOfExtensionProcesses; extern const float kMaxShareOfExtensionProcesses;
#if defined(OS_LINUX)
// The highest and lowest assigned OOM score adjustment
// (oom_score_adj) used by the OomPriority Manager.
extern const int kLowestRendererOomScore;
extern const int kHighestRendererOomScore;
#endif
#if defined(OS_CHROMEOS) #if defined(OS_CHROMEOS)
// Chrome OS profile directories have custom prefix. // Chrome OS profile directories have custom prefix.
// Profile path format: [user_data_dir]/u-[$hash] // Profile path format: [user_data_dir]/u-[$hash]
......
...@@ -12,6 +12,7 @@ ...@@ -12,6 +12,7 @@
#include "content/public/browser/child_process_launcher_utils.h" #include "content/public/browser/child_process_launcher_utils.h"
#include "content/public/browser/content_browser_client.h" #include "content/public/browser/content_browser_client.h"
#include "content/public/common/content_client.h" #include "content/public/common/content_client.h"
#include "content/public/common/content_constants.h"
#include "content/public/common/content_switches.h" #include "content/public/common/content_switches.h"
#include "content/public/common/result_codes.h" #include "content/public/common/result_codes.h"
#include "content/public/common/sandboxed_process_launcher_delegate.h" #include "content/public/common/sandboxed_process_launcher_delegate.h"
...@@ -83,14 +84,13 @@ ChildProcessLauncherHelper::LaunchProcessOnLauncherThread( ...@@ -83,14 +84,13 @@ ChildProcessLauncherHelper::LaunchProcessOnLauncherThread(
#if !defined(OS_OPENBSD) #if !defined(OS_OPENBSD)
if (handle) { if (handle) {
// This is just a starting score for a renderer or extension (the // It could be a renderer process or an utility process.
// only types of processes that will be started this way). It will int oom_score = content::kMiscOomScore;
// get adjusted as time goes on. (This is the same value as if (command_line()->GetSwitchValueASCII(switches::kProcessType) ==
// chrome::kLowestRendererOomScore in chrome/chrome_constants.h, but switches::kRendererProcess)
// that's not something we can include here.) oom_score = content::kLowestRendererOomScore;
const int kLowestRendererOomScore = 300;
service_manager::ZygoteHostImpl::GetInstance()->AdjustRendererOOMScore( service_manager::ZygoteHostImpl::GetInstance()->AdjustRendererOOMScore(
handle, kLowestRendererOomScore); handle, oom_score);
} }
#endif #endif
......
...@@ -47,4 +47,24 @@ const int kDefaultDetachableCancelDelayMs = 30000; ...@@ -47,4 +47,24 @@ const int kDefaultDetachableCancelDelayMs = 30000;
const char kCorsExemptPurposeHeaderName[] = "Purpose"; const char kCorsExemptPurposeHeaderName[] = "Purpose";
const char kCorsExemptRequestedWithHeaderName[] = "X-Requested-With"; const char kCorsExemptRequestedWithHeaderName[] = "X-Requested-With";
#if defined(OS_LINUX)
const int kLowestRendererOomScore = 300;
const int kHighestRendererOomScore = 1000;
// The minimum amount to bump a score by. This is large enough that
// even if it's translated into the old values, it will still go up
// by at least one.
static const int kOomScoreBump = 100;
// Browsers and zygotes should still be killable, but killed last.
const int kZygoteOomScore = 0;
// For "miscellaneous" things, we want them after renderers, but before plugins.
const int kMiscOomScore = kLowestRendererOomScore - kOomScoreBump;
// We want plugins to die after the renderers.
const int kPluginOomScore = kMiscOomScore - kOomScoreBump;
static_assert(kMiscOomScore > 0, "kMiscOomScore should be greater than 0");
static_assert(kPluginOomScore > 0, "kPluginOomScore should be greater than 0");
#endif
} // namespace content } // namespace content
...@@ -10,6 +10,7 @@ ...@@ -10,6 +10,7 @@
#include <stddef.h> // For size_t #include <stddef.h> // For size_t
#include "base/files/file_path.h" #include "base/files/file_path.h"
#include "build/build_config.h"
#include "content/common/content_export.h" #include "content/common/content_export.h"
namespace content { namespace content {
...@@ -68,6 +69,19 @@ CONTENT_EXPORT extern const int kDefaultDetachableCancelDelayMs; ...@@ -68,6 +69,19 @@ CONTENT_EXPORT extern const int kDefaultDetachableCancelDelayMs;
CONTENT_EXPORT extern const char kCorsExemptPurposeHeaderName[]; CONTENT_EXPORT extern const char kCorsExemptPurposeHeaderName[];
CONTENT_EXPORT extern const char kCorsExemptRequestedWithHeaderName[]; CONTENT_EXPORT extern const char kCorsExemptRequestedWithHeaderName[];
#if defined(OS_LINUX)
// The OOM score adj constants
// The highest and lowest assigned OOM score adjustment (oom_score_adj) for
// renderers and extensions used by the OomPriority Manager.
CONTENT_EXPORT extern const int kLowestRendererOomScore;
CONTENT_EXPORT extern const int kHighestRendererOomScore;
CONTENT_EXPORT extern const int kZygoteOomScore;
CONTENT_EXPORT extern const int kMiscOomScore;
CONTENT_EXPORT extern const int kPluginOomScore;
#endif
} // namespace content } // namespace content
#endif // CONTENT_PUBLIC_COMMON_CONTENT_CONSTANTS_H_ #endif // CONTENT_PUBLIC_COMMON_CONTENT_CONSTANTS_H_
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