From f7fb6371c225b30b27c94f72a8003aa786d29371 Mon Sep 17 00:00:00 2001 From: Adam Roben Date: Fri, 31 Jan 2014 10:38:12 -0500 Subject: [PATCH] Increase the open file limit on OS X to 1024 The default (256) is too low for pages that load a lot of resources all at once. See https://codereview.chromium.org/125151 and bugs like https://code.google.com/p/chromium/issues/detail?id=14137 and https://code.google.com/p/chromium/issues/detail?id=151039. The new limit matches what Chrome itself uses. --- brightray/browser/browser_main_parts.h | 1 + brightray/browser/browser_main_parts_mac.mm | 30 +++++++++++++++++++++ 2 files changed, 31 insertions(+) diff --git a/brightray/browser/browser_main_parts.h b/brightray/browser/browser_main_parts.h index 6e2f3531f678..79d343ac608b 100644 --- a/brightray/browser/browser_main_parts.h +++ b/brightray/browser/browser_main_parts.h @@ -27,6 +27,7 @@ class BrowserMainParts : public content::BrowserMainParts { virtual BrowserContext* CreateBrowserContext(); #if defined(OS_MACOSX) + virtual void PreEarlyInitialization() OVERRIDE; virtual void PreMainMessageLoopStart() OVERRIDE; #endif diff --git a/brightray/browser/browser_main_parts_mac.mm b/brightray/browser/browser_main_parts_mac.mm index 373280ca4441..44b9494374ac 100644 --- a/brightray/browser/browser_main_parts_mac.mm +++ b/brightray/browser/browser_main_parts_mac.mm @@ -1,10 +1,40 @@ #import "browser_main_parts.h" +#import "base/logging.h" #import "base/mac/bundle_locations.h" #import namespace brightray { +namespace { + +// Sets the file descriptor soft limit to |max_descriptors| or the OS hard limit, whichever is +// lower. +void SetFileDescriptorLimit(rlim_t max_descriptors) { + rlimit limits; + if (getrlimit(RLIMIT_NOFILE, &limits) != 0) { + PLOG(INFO) << "Failed to get file descriptor limit"; + return; + } + + auto new_limit = max_descriptors; + if (limits.rlim_max > 0) + new_limit = std::min(new_limit, limits.rlim_max); + limits.rlim_cur = new_limit; + if (setrlimit(RLIMIT_NOFILE, &limits) != 0) + PLOG(INFO) << "Failed to set file descriptor limit"; +} + +} // namespace + +void BrowserMainParts::PreEarlyInitialization() { + // We use quite a few file descriptors for our IPC, and the default limit on the Mac is low (256), + // so bump it up. + // See http://src.chromium.org/viewvc/chrome/trunk/src/chrome/browser/chrome_browser_main_posix.cc?revision=244734#l295 + // and https://codereview.chromium.org/125151 + SetFileDescriptorLimit(1024); +} + // Replicates NSApplicationMain, but doesn't start a run loop. void BrowserMainParts::PreMainMessageLoopStart() { auto infoDictionary = base::mac::OuterBundle().infoDictionary;