summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorstuartmorgan@chromium.org <stuartmorgan@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2009-06-15 22:23:01 +0000
committerstuartmorgan@chromium.org <stuartmorgan@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2009-06-15 22:23:01 +0000
commit4417ff416797720c2bb1d28de0a8a24f2e631f55 (patch)
tree37cdb20bfd4db4f93cd9c5b282fb24a2585854a2
parent030bdf761f264aa1541a9bf26221fa47e24d5d6e (diff)
downloadchromium_src-4417ff416797720c2bb1d28de0a8a24f2e631f55.zip
chromium_src-4417ff416797720c2bb1d28de0a8a24f2e631f55.tar.gz
chromium_src-4417ff416797720c2bb1d28de0a8a24f2e631f55.tar.bz2
Add a switch for changing the fd limit on Mac/Linux.
Bump up the default fd limit on the Mac; stopgap fix for page cyclers, but something we want long-term to improve performance once we handle fd exhaustion with delays. BUG=none TEST=Launching with --file-descriptor-limit=20 should crash the renderer almost immediately. Review URL: http://codereview.chromium.org/125151 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@18446 0039d316-1c4b-4281-b951-d872f2087c98
-rw-r--r--chrome/browser/browser_main.cc39
-rw-r--r--chrome/common/chrome_switches.cc5
-rw-r--r--chrome/common/chrome_switches.h2
3 files changed, 45 insertions, 1 deletions
diff --git a/chrome/browser/browser_main.cc b/chrome/browser/browser_main.cc
index ee398bf..cfdaa27 100644
--- a/chrome/browser/browser_main.cc
+++ b/chrome/browser/browser_main.cc
@@ -60,7 +60,9 @@
// TODO(port): get rid of this include. It's used just to provide declarations
// and stub definitions for classes we encouter during the porting effort.
#include "chrome/common/temp_scaffolding_stubs.h"
+#include <errno.h>
#include <signal.h>
+#include <sys/resource.h>
#endif
#if defined(OS_LINUX)
@@ -197,6 +199,24 @@ void RunUIMessageLoop(BrowserProcess* browser_process) {
// See comment below, where sigaction is called.
void SIGCHLDHandler(int signal) {
}
+
+// Sets the file descriptor soft limit to |max_descriptors| or the OS hard
+// limit, whichever is lower.
+void SetFileDescriptorLimit(unsigned int max_descriptors) {
+ struct rlimit limits;
+ if (getrlimit(RLIMIT_NOFILE, &limits) == 0) {
+ unsigned int new_limit = max_descriptors;
+ if (limits.rlim_max > 0 && limits.rlim_max < max_descriptors) {
+ new_limit = limits.rlim_max;
+ }
+ limits.rlim_cur = new_limit;
+ if (setrlimit(RLIMIT_NOFILE, &limits) != 0) {
+ LOG(INFO) << "Failed to set file descriptor limit: " << strerror(errno);
+ }
+ } else {
+ LOG(INFO) << "Failed to get file descriptor limit: " << strerror(errno);
+ }
+}
#endif
#if defined(OS_WIN)
@@ -245,7 +265,24 @@ int BrowserMain(const MainFunctionParams& parameters) {
memset(&action, 0, sizeof(action));
action.sa_handler = SIGCHLDHandler;
CHECK(sigaction(SIGCHLD, &action, NULL) == 0);
-#endif
+
+ const std::wstring fd_limit_string =
+ parsed_command_line.GetSwitchValue(switches::kFileDescriptorLimit);
+ int fd_limit = 0;
+ if (!fd_limit_string.empty()) {
+ StringToInt(WideToUTF16Hack(fd_limit_string), &fd_limit);
+ }
+#if defined(OS_MACOSX)
+ // We use quite a few file descriptors for our IPC, and the default limit on
+ // the Mac is low (256), so bump it up if there is no explicit override.
+ if (fd_limit == 0) {
+ fd_limit = 1024;
+ }
+#endif // OS_MACOSX
+ if (fd_limit > 0) {
+ SetFileDescriptorLimit(fd_limit);
+ }
+#endif // OS_POSIX
// Do platform-specific things (such as finishing initializing Cocoa)
// prior to instantiating the message loop. This could be turned into a
diff --git a/chrome/common/chrome_switches.cc b/chrome/common/chrome_switches.cc
index c57b0bb..2b3bf60 100644
--- a/chrome/common/chrome_switches.cc
+++ b/chrome/common/chrome_switches.cc
@@ -504,4 +504,9 @@ const wchar_t kThumbnailStore[] = L"thumbnail-store";
// is to be used only by the upgrade process.
const wchar_t kTryChromeAgain[] = L"try-chrome-again";
+// The file descriptor limit is set to the value of this switch, subject to the
+// OS hard limits. Useful for testing that file descriptor exhaustion is handled
+// gracefully.
+const wchar_t kFileDescriptorLimit[] = L"file-descriptor-limit";
+
} // namespace switches
diff --git a/chrome/common/chrome_switches.h b/chrome/common/chrome_switches.h
index 8d3785a..3b76100 100644
--- a/chrome/common/chrome_switches.h
+++ b/chrome/common/chrome_switches.h
@@ -192,6 +192,8 @@ extern const wchar_t kThumbnailStore[];
extern const wchar_t kTryChromeAgain[];
+extern const wchar_t kFileDescriptorLimit[];
+
} // namespace switches
#endif // CHROME_COMMON_CHROME_SWITCHES_H_