Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "chrome/app/chrome_main.h" | 5 #include "chrome/app/chrome_main.h" |
| 6 | 6 |
| 7 #include "base/at_exit.h" | 7 #include "base/at_exit.h" |
| 8 #include "base/command_line.h" | 8 #include "base/command_line.h" |
| 9 #include "base/debug/debugger.h" | 9 #include "base/debug/debugger.h" |
| 10 #include "base/i18n/icu_util.h" | 10 #include "base/i18n/icu_util.h" |
| (...skipping 155 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 166 // We are only searching for ASCII characters so this is OK. | 166 // We are only searching for ASCII characters so this is OK. |
| 167 StringToLowerASCII(&command_line_lower); | 167 StringToLowerASCII(&command_line_lower); |
| 168 std::wstring::size_type pos = command_line_lower.find(kChromeHtml); | 168 std::wstring::size_type pos = command_line_lower.find(kChromeHtml); |
| 169 return (pos != std::wstring::npos); | 169 return (pos != std::wstring::npos); |
| 170 } | 170 } |
| 171 | 171 |
| 172 #endif // defined(OS_WIN) | 172 #endif // defined(OS_WIN) |
| 173 | 173 |
| 174 #if defined(OS_LINUX) | 174 #if defined(OS_LINUX) |
| 175 static void AdjustLinuxOOMScore(const std::string& process_type) { | 175 static void AdjustLinuxOOMScore(const std::string& process_type) { |
| 176 const int kMiscScore = 7; | 176 // Browsers and zygotes should still be killable, but killed last. |
| 177 #if defined(OS_CHROMEOS) | 177 const int kZygoteScore = 0; |
| 178 // On ChromeOS, we want plugins to die after the renderers. If this | 178 // This is the lowest score that renderers and extensions start with |
| 179 // works well for ChromeOS, we may do it for Linux as well. | 179 // in the OomPriorityManager. |
| 180 const int kPluginScore = 4; | 180 const int kRendererScore = chrome::kLowestRendererOomScore; |
| 181 #else | 181 // We want plugins to die after the renderers. |
| 182 const int kPluginScore = 10; | 182 const int kPluginScore = 100; |
|
stevenjb
2011/08/18 23:31:05
Really, I'm not trying to be a pain :), but I thin
Greg Spencer (Chromium)
2011/08/18 23:59:32
No worries: good comments are never a pain.
OK, I
stevenjb
2011/08/19 17:25:31
The question is, an average of what? With absolute
| |
| 183 #endif | 183 // For "miscellaneous" things, we want them after renderers, |
| 184 // but before plugins. | |
| 185 const int kMiscScore = 200; | |
| 186 // The minimum amount to bump a score by. This is large enough that | |
| 187 // even if it's translated into the old values, it will still go up | |
| 188 // by at least one. | |
| 189 const int kMinScoreBump = 100; | |
| 184 int score = -1; | 190 int score = -1; |
| 185 | 191 |
| 186 if (process_type == switches::kPluginProcess || | 192 if (process_type == switches::kPluginProcess || |
| 187 process_type == switches::kPpapiPluginProcess) { | 193 process_type == switches::kPpapiPluginProcess) { |
| 188 score = kPluginScore; | 194 score = kPluginScore; |
| 189 } else if (process_type == switches::kPpapiBrokerProcess) { | 195 } else if (process_type == switches::kPpapiBrokerProcess) { |
| 190 // Kill the broker before the plugin. | 196 // The broker should be killed before the PPAPI plugin. |
| 191 score = kPluginScore + 1; | 197 score = kPluginScore + kMinScoreBump; |
| 192 } else if (process_type == switches::kUtilityProcess || | 198 } else if (process_type == switches::kUtilityProcess || |
| 193 process_type == switches::kWorkerProcess || | 199 process_type == switches::kWorkerProcess || |
| 194 process_type == switches::kGpuProcess || | 200 process_type == switches::kGpuProcess || |
| 195 process_type == switches::kServiceProcess) { | 201 process_type == switches::kServiceProcess) { |
| 196 score = kMiscScore; | 202 score = kMiscScore; |
| 197 } else if (process_type == switches::kProfileImportProcess) { | 203 } else if (process_type == switches::kProfileImportProcess) { |
| 198 NOTIMPLEMENTED(); | 204 NOTIMPLEMENTED(); |
| 205 score = kZygoteScore; | |
| 199 #ifndef DISABLE_NACL | 206 #ifndef DISABLE_NACL |
| 200 } else if (process_type == switches::kNaClLoaderProcess) { | 207 } else if (process_type == switches::kNaClLoaderProcess) { |
| 201 score = kPluginScore; | 208 score = kPluginScore; |
| 202 #endif | 209 #endif |
| 203 } else if (process_type == switches::kZygoteProcess || | 210 } else if (process_type == switches::kZygoteProcess || |
| 204 process_type.empty()) { | 211 process_type.empty()) { |
| 205 // Pass - browser / zygote process stays at 0. | 212 // For zygotes and unlabeled process types, we want to still make |
| 213 // them killable by the OOM killer. | |
| 214 score = kZygoteScore; | |
| 206 } else if (process_type == switches::kExtensionProcess || | 215 } else if (process_type == switches::kExtensionProcess || |
| 207 process_type == switches::kRendererProcess) { | 216 process_type == switches::kRendererProcess) { |
| 208 LOG(WARNING) << "process type '" << process_type << "' " | 217 LOG(WARNING) << "process type '" << process_type << "' " |
| 209 << "should go through the zygote."; | 218 << "should be created through the zygote."; |
| 210 // When debugging, these process types can end up being run directly. | 219 // When debugging, these process types can end up being run |
| 211 return; | 220 // directly, but this isn't the typical path for assigning the OOM |
| 221 // score for them. Still, we want to assign a score that is | |
| 222 // somewhat representative for debugging. | |
| 223 score = kRendererScore; | |
| 212 } else { | 224 } else { |
| 213 NOTREACHED() << "Unknown process type"; | 225 NOTREACHED() << "Unknown process type"; |
| 214 } | 226 } |
| 215 if (score > -1) | 227 if (score > -1) |
| 216 base::AdjustOOMScore(base::GetCurrentProcId(), score); | 228 base::AdjustOOMScore(base::GetCurrentProcId(), score); |
| 217 } | 229 } |
| 218 #endif // defined(OS_LINUX) | 230 #endif // defined(OS_LINUX) |
| 219 | 231 |
| 220 void SetupCRT(const CommandLine& command_line) { | 232 void SetupCRT(const CommandLine& command_line) { |
| 221 #if defined(OS_WIN) | 233 #if defined(OS_WIN) |
| 222 #ifdef _CRTDBG_MAP_ALLOC | 234 #if defined(_CRTDBG_MAP_ALLOC) |
| 223 _CrtSetReportFile(_CRT_WARN, _CRTDBG_FILE_STDERR); | 235 _CrtSetReportFile(_CRT_WARN, _CRTDBG_FILE_STDERR); |
| 224 _CrtSetReportMode(_CRT_WARN, _CRTDBG_MODE_FILE); | 236 _CrtSetReportMode(_CRT_WARN, _CRTDBG_MODE_FILE); |
| 225 #else | 237 #else |
| 226 if (!command_line.HasSwitch(switches::kDisableBreakpad)) { | 238 if (!command_line.HasSwitch(switches::kDisableBreakpad)) { |
| 227 _CrtSetReportMode(_CRT_ASSERT, 0); | 239 _CrtSetReportMode(_CRT_ASSERT, 0); |
| 228 } | 240 } |
| 229 #endif | 241 #endif |
| 230 #endif | 242 #endif |
| 231 } | 243 } |
| 232 | 244 |
| (...skipping 294 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 527 { switches::kGpuProcess, GpuMain }, | 539 { switches::kGpuProcess, GpuMain }, |
| 528 { switches::kServiceProcess, ServiceProcessMain }, | 540 { switches::kServiceProcess, ServiceProcessMain }, |
| 529 | 541 |
| 530 #if defined(OS_MACOSX) | 542 #if defined(OS_MACOSX) |
| 531 // TODO(port): Use OOP profile import - http://crbug.com/22142 . | 543 // TODO(port): Use OOP profile import - http://crbug.com/22142 . |
| 532 { switches::kProfileImportProcess, ProfileImportMain }, | 544 { switches::kProfileImportProcess, ProfileImportMain }, |
| 533 { switches::kRelauncherProcess, mac_relauncher::internal::RelauncherMain }, | 545 { switches::kRelauncherProcess, mac_relauncher::internal::RelauncherMain }, |
| 534 #endif | 546 #endif |
| 535 #if !defined(DISABLE_NACL) | 547 #if !defined(DISABLE_NACL) |
| 536 { switches::kNaClLoaderProcess, NaClMain }, | 548 { switches::kNaClLoaderProcess, NaClMain }, |
| 537 #ifdef _WIN64 // The broker process is used only on Win64. | 549 #if defined(_WIN64) // The broker process is used only on Win64. |
| 538 { switches::kNaClBrokerProcess, NaClBrokerMain }, | 550 { switches::kNaClBrokerProcess, NaClBrokerMain }, |
| 539 #endif | 551 #endif |
| 540 #endif // DISABLE_NACL | 552 #endif // DISABLE_NACL |
| 541 #if defined(OS_POSIX) && !defined(OS_MACOSX) | 553 #if defined(OS_POSIX) && !defined(OS_MACOSX) |
| 542 // Zygote startup is special -- see RunZygote comments above | 554 // Zygote startup is special -- see RunZygote comments above |
| 543 // for why we don't use ZygoteMain directly. | 555 // for why we don't use ZygoteMain directly. |
| 544 { switches::kZygoteProcess, RunZygote }, | 556 { switches::kZygoteProcess, RunZygote }, |
| 545 #endif | 557 #endif |
| 546 }; | 558 }; |
| 547 | 559 |
| (...skipping 344 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 892 | 904 |
| 893 if (SubprocessNeedsResourceBundle(process_type)) | 905 if (SubprocessNeedsResourceBundle(process_type)) |
| 894 ResourceBundle::CleanupSharedInstance(); | 906 ResourceBundle::CleanupSharedInstance(); |
| 895 | 907 |
| 896 logging::CleanupChromeLogging(); | 908 logging::CleanupChromeLogging(); |
| 897 | 909 |
| 898 chrome_main::LowLevelShutdown(); | 910 chrome_main::LowLevelShutdown(); |
| 899 | 911 |
| 900 return exit_code; | 912 return exit_code; |
| 901 } | 913 } |
| OLD | NEW |