Skip to content

Commit bfc90a5

Browse files
committed
Bug 1401776 - Raise fd limit to 4096 on Unix. r=glandium,mcmanus
This is to accommodate non-networking fd usage (IPC transports, various databases, .xpi files, etc.), so it's separate from Necko's existing manipulation of the fd limit, which is tied into Necko's internal limits on how many sockets it will try to poll at once. Note that resource limits are inherited by child processes, so this needs to be done only in the parent. This patch also removes similar code used on Solaris and Mac OS X. The Mac case (bug 1036682) refers to fd use by graphics textures, which shouldn't be consuming fds anymore (even transiently) as of bug 1161166. MozReview-Commit-ID: 2uodrkW5sUn --HG-- extra : rebase_source : 5306f4995000459b89bed048ecafba3c262bbbdf
1 parent 5cf1e74 commit bfc90a5

File tree

3 files changed

+35
-37
lines changed

3 files changed

+35
-37
lines changed

gfx/thebes/gfxPlatformMac.cpp

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -81,18 +81,6 @@ gfxPlatformMac::gfxPlatformMac()
8181

8282
InitBackendPrefs(GetBackendPrefs());
8383

84-
// XXX: Bug 1036682 - we run out of fds on Mac when using tiled layers because
85-
// with 256x256 tiles we can easily hit the soft limit of 800 when using double
86-
// buffered tiles in e10s, so let's bump the soft limit to the hard limit for the OS
87-
// up to a new cap of OPEN_MAX.
88-
struct rlimit limits;
89-
if (getrlimit(RLIMIT_NOFILE, &limits) == 0) {
90-
limits.rlim_cur = std::min(rlim_t(OPEN_MAX), limits.rlim_max);
91-
if (setrlimit(RLIMIT_NOFILE, &limits) != 0) {
92-
NS_WARNING("Unable to bump RLIMIT_NOFILE to the maximum number on this OS");
93-
}
94-
}
95-
9684
MacIOSurfaceLib::LoadLibrary();
9785
}
9886

toolkit/xre/nsAppRunner.cpp

Lines changed: 35 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -153,9 +153,12 @@
153153
#include <locale.h>
154154

155155
#ifdef XP_UNIX
156+
#include <errno.h>
157+
#include <pwd.h>
158+
#include <string.h>
159+
#include <sys/resource.h>
156160
#include <sys/stat.h>
157161
#include <unistd.h>
158-
#include <pwd.h>
159162
#endif
160163

161164
#ifdef XP_WIN
@@ -3084,6 +3087,35 @@ CheckForUserMismatch()
30843087
}
30853088
#endif
30863089

3090+
static void
3091+
IncreaseDescriptorLimits()
3092+
{
3093+
#ifdef XP_UNIX
3094+
// Increase the fd limit to accomodate IPC resources like shared memory.
3095+
static const rlim_t kFDs = 4096;
3096+
struct rlimit rlim;
3097+
3098+
if (getrlimit(RLIMIT_NOFILE, &rlim) != 0) {
3099+
Output(false, "getrlimit: %s\n", strerror(errno));
3100+
return;
3101+
}
3102+
// Don't decrease the limit if it's already high enough, but don't
3103+
// try to go over the hard limit. (RLIM_INFINITY isn't required to
3104+
// be the numerically largest rlim_t, so don't assume that.)
3105+
if (rlim.rlim_cur != RLIM_INFINITY && rlim.rlim_cur < kFDs &&
3106+
rlim.rlim_cur < rlim.rlim_max) {
3107+
if (rlim.rlim_max != RLIM_INFINITY && rlim.rlim_max < kFDs) {
3108+
rlim.rlim_cur = rlim.rlim_max;
3109+
} else {
3110+
rlim.rlim_cur = kFDs;
3111+
}
3112+
if (setrlimit(RLIMIT_NOFILE, &rlim) != 0) {
3113+
Output(false, "setrlimit: %s\n", strerror(errno));
3114+
}
3115+
}
3116+
#endif
3117+
}
3118+
30873119
/*
30883120
* XRE_mainInit - Initial setup and command line parameter processing.
30893121
* Main() will exit early if either return value != 0 or if aExitFlag is
@@ -3154,6 +3186,8 @@ XREMain::XRE_mainInit(bool* aExitFlag)
31543186
NS_BREAK();
31553187
#endif
31563188

3189+
IncreaseDescriptorLimits();
3190+
31573191
#ifdef USE_GLX_TEST
31583192
// bug 639842 - it's very important to fire this process BEFORE we set up
31593193
// error handling. indeed, this process is expected to be crashy, and we

toolkit/xre/nsSigHandlers.cpp

Lines changed: 0 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -287,30 +287,6 @@ void InstallSignalHandlers(const char *aProgname)
287287
}
288288
#endif
289289

290-
#if defined(SOLARIS)
291-
#define NOFILES 512
292-
293-
// Boost Solaris file descriptors
294-
{
295-
struct rlimit rl;
296-
297-
if (getrlimit(RLIMIT_NOFILE, &rl) == 0)
298-
299-
if (rl.rlim_cur < NOFILES) {
300-
rl.rlim_cur = NOFILES;
301-
302-
if (setrlimit(RLIMIT_NOFILE, &rl) < 0) {
303-
perror("setrlimit(RLIMIT_NOFILE)");
304-
fprintf(stderr, "Cannot exceed hard limit for open files");
305-
}
306-
#if defined(DEBUG)
307-
if (getrlimit(RLIMIT_NOFILE, &rl) == 0)
308-
printf("File descriptors set to %d\n", rl.rlim_cur);
309-
#endif //DEBUG
310-
}
311-
}
312-
#endif //SOLARIS
313-
314290
#if defined(MOZ_WIDGET_GTK) && (GLIB_MAJOR_VERSION > 2 || (GLIB_MAJOR_VERSION == 2 && GLIB_MINOR_VERSION >= 6))
315291
const char *assertString = PR_GetEnv("XPCOM_DEBUG_BREAK");
316292
if (assertString &&

0 commit comments

Comments
 (0)