Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(211)

Side by Side Diff: chrome/app/chrome_main.cc

Issue 7708020: Trying again to land OOM priority manager changes. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Moving switch closer to use location Created 9 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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 156 matching lines...) Expand 10 before | Expand all | Expand 10 after
167 // We are only searching for ASCII characters so this is OK. 167 // We are only searching for ASCII characters so this is OK.
168 StringToLowerASCII(&command_line_lower); 168 StringToLowerASCII(&command_line_lower);
169 std::wstring::size_type pos = command_line_lower.find(kChromeHtml); 169 std::wstring::size_type pos = command_line_lower.find(kChromeHtml);
170 return (pos != std::wstring::npos); 170 return (pos != std::wstring::npos);
171 } 171 }
172 172
173 #endif // defined(OS_WIN) 173 #endif // defined(OS_WIN)
174 174
175 #if defined(OS_LINUX) 175 #if defined(OS_LINUX)
176 static void AdjustLinuxOOMScore(const std::string& process_type) { 176 static void AdjustLinuxOOMScore(const std::string& process_type) {
177 const int kMiscScore = 7; 177 // Browsers and zygotes should still be killable, but killed last.
178 #if defined(OS_CHROMEOS) 178 const int kZygoteScore = 0;
179 // On ChromeOS, we want plugins to die after the renderers. If this 179 // The minimum amount to bump a score by. This is large enough that
180 // works well for ChromeOS, we may do it for Linux as well. 180 // even if it's translated into the old values, it will still go up
181 const int kPluginScore = 4; 181 // by at least one.
182 #else 182 const int kScoreBump = 100;
183 const int kPluginScore = 10; 183 // This is the lowest score that renderers and extensions start with
184 #endif 184 // in the OomPriorityManager.
185 const int kRendererScore = chrome::kLowestRendererOomScore;
186 // For "miscellaneous" things, we want them after renderers,
187 // but before plugins.
188 const int kMiscScore = kRendererScore - kScoreBump;
189 // We want plugins to die after the renderers.
190 const int kPluginScore = kMiscScore - kScoreBump;
185 int score = -1; 191 int score = -1;
186 192
193 DCHECK(kMiscScore > 0);
194 DCHECK(kPluginScore > 0);
195
187 if (process_type == switches::kPluginProcess || 196 if (process_type == switches::kPluginProcess ||
188 process_type == switches::kPpapiPluginProcess) { 197 process_type == switches::kPpapiPluginProcess) {
189 score = kPluginScore; 198 score = kPluginScore;
190 } else if (process_type == switches::kPpapiBrokerProcess) { 199 } else if (process_type == switches::kPpapiBrokerProcess) {
191 // Kill the broker before the plugin. 200 // The broker should be killed before the PPAPI plugin.
192 score = kPluginScore + 1; 201 score = kPluginScore + kScoreBump;
193 } else if (process_type == switches::kUtilityProcess || 202 } else if (process_type == switches::kUtilityProcess ||
194 process_type == switches::kWorkerProcess || 203 process_type == switches::kWorkerProcess ||
195 process_type == switches::kGpuProcess || 204 process_type == switches::kGpuProcess ||
196 process_type == switches::kServiceProcess) { 205 process_type == switches::kServiceProcess) {
197 score = kMiscScore; 206 score = kMiscScore;
198 } else if (process_type == switches::kProfileImportProcess) { 207 } else if (process_type == switches::kProfileImportProcess) {
199 NOTIMPLEMENTED(); 208 NOTIMPLEMENTED();
209 score = kZygoteScore;
200 #ifndef DISABLE_NACL 210 #ifndef DISABLE_NACL
201 } else if (process_type == switches::kNaClLoaderProcess) { 211 } else if (process_type == switches::kNaClLoaderProcess) {
202 score = kPluginScore; 212 score = kPluginScore;
203 #endif 213 #endif
204 } else if (process_type == switches::kZygoteProcess || 214 } else if (process_type == switches::kZygoteProcess ||
205 process_type.empty()) { 215 process_type.empty()) {
206 // Pass - browser / zygote process stays at 0. 216 // For zygotes and unlabeled process types, we want to still make
217 // them killable by the OOM killer.
218 score = kZygoteScore;
207 } else if (process_type == switches::kExtensionProcess || 219 } else if (process_type == switches::kExtensionProcess ||
208 process_type == switches::kRendererProcess) { 220 process_type == switches::kRendererProcess) {
209 LOG(WARNING) << "process type '" << process_type << "' " 221 LOG(WARNING) << "process type '" << process_type << "' "
210 << "should go through the zygote."; 222 << "should be created through the zygote.";
211 // When debugging, these process types can end up being run directly. 223 // When debugging, these process types can end up being run
212 return; 224 // directly, but this isn't the typical path for assigning the OOM
225 // score for them. Still, we want to assign a score that is
226 // somewhat representative for debugging.
227 score = kRendererScore;
213 } else { 228 } else {
214 NOTREACHED() << "Unknown process type"; 229 NOTREACHED() << "Unknown process type";
215 } 230 }
216 if (score > -1) 231 if (score > -1)
217 base::AdjustOOMScore(base::GetCurrentProcId(), score); 232 base::AdjustOOMScore(base::GetCurrentProcId(), score);
218 } 233 }
219 #endif // defined(OS_LINUX) 234 #endif // defined(OS_LINUX)
220 235
221 void SetupCRT(const CommandLine& command_line) { 236 void SetupCRT(const CommandLine& command_line) {
222 #if defined(OS_WIN) 237 #if defined(OS_WIN)
223 #ifdef _CRTDBG_MAP_ALLOC 238 #if defined(_CRTDBG_MAP_ALLOC)
224 _CrtSetReportFile(_CRT_WARN, _CRTDBG_FILE_STDERR); 239 _CrtSetReportFile(_CRT_WARN, _CRTDBG_FILE_STDERR);
225 _CrtSetReportMode(_CRT_WARN, _CRTDBG_MODE_FILE); 240 _CrtSetReportMode(_CRT_WARN, _CRTDBG_MODE_FILE);
226 #else 241 #else
227 if (!command_line.HasSwitch(switches::kDisableBreakpad)) { 242 if (!command_line.HasSwitch(switches::kDisableBreakpad)) {
228 _CrtSetReportMode(_CRT_ASSERT, 0); 243 _CrtSetReportMode(_CRT_ASSERT, 0);
229 } 244 }
230 #endif 245 #endif
231 #endif 246 #endif
232 } 247 }
233 248
(...skipping 294 matching lines...) Expand 10 before | Expand all | Expand 10 after
528 { switches::kGpuProcess, GpuMain }, 543 { switches::kGpuProcess, GpuMain },
529 { switches::kServiceProcess, ServiceProcessMain }, 544 { switches::kServiceProcess, ServiceProcessMain },
530 545
531 #if defined(OS_MACOSX) 546 #if defined(OS_MACOSX)
532 // TODO(port): Use OOP profile import - http://crbug.com/22142 . 547 // TODO(port): Use OOP profile import - http://crbug.com/22142 .
533 { switches::kProfileImportProcess, ProfileImportMain }, 548 { switches::kProfileImportProcess, ProfileImportMain },
534 { switches::kRelauncherProcess, mac_relauncher::internal::RelauncherMain }, 549 { switches::kRelauncherProcess, mac_relauncher::internal::RelauncherMain },
535 #endif 550 #endif
536 #if !defined(DISABLE_NACL) 551 #if !defined(DISABLE_NACL)
537 { switches::kNaClLoaderProcess, NaClMain }, 552 { switches::kNaClLoaderProcess, NaClMain },
538 #ifdef _WIN64 // The broker process is used only on Win64. 553 #if defined(_WIN64) // The broker process is used only on Win64.
539 { switches::kNaClBrokerProcess, NaClBrokerMain }, 554 { switches::kNaClBrokerProcess, NaClBrokerMain },
540 #endif 555 #endif
541 #endif // DISABLE_NACL 556 #endif // DISABLE_NACL
542 #if defined(OS_POSIX) && !defined(OS_MACOSX) 557 #if defined(OS_POSIX) && !defined(OS_MACOSX)
543 // Zygote startup is special -- see RunZygote comments above 558 // Zygote startup is special -- see RunZygote comments above
544 // for why we don't use ZygoteMain directly. 559 // for why we don't use ZygoteMain directly.
545 { switches::kZygoteProcess, RunZygote }, 560 { switches::kZygoteProcess, RunZygote },
546 #endif 561 #endif
547 }; 562 };
548 563
(...skipping 345 matching lines...) Expand 10 before | Expand all | Expand 10 after
894 909
895 if (SubprocessNeedsResourceBundle(process_type)) 910 if (SubprocessNeedsResourceBundle(process_type))
896 ResourceBundle::CleanupSharedInstance(); 911 ResourceBundle::CleanupSharedInstance();
897 912
898 logging::CleanupChromeLogging(); 913 logging::CleanupChromeLogging();
899 914
900 chrome_main::LowLevelShutdown(); 915 chrome_main::LowLevelShutdown();
901 916
902 return exit_code; 917 return exit_code;
903 } 918 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698