diff options
author | stuartmorgan@chromium.org <stuartmorgan@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-06-15 22:23:01 +0000 |
---|---|---|
committer | stuartmorgan@chromium.org <stuartmorgan@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-06-15 22:23:01 +0000 |
commit | 4417ff416797720c2bb1d28de0a8a24f2e631f55 (patch) | |
tree | 37cdb20bfd4db4f93cd9c5b282fb24a2585854a2 /chrome/browser/browser_main.cc | |
parent | 030bdf761f264aa1541a9bf26221fa47e24d5d6e (diff) | |
download | chromium_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
Diffstat (limited to 'chrome/browser/browser_main.cc')
-rw-r--r-- | chrome/browser/browser_main.cc | 39 |
1 files changed, 38 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 |