Add REDIS_MIN_RESERVED_FDS define for open fds

Also update the original REDIS_EVENTLOOP_FDSET_INCR to
include REDIS_MIN_RESERVED_FDS. REDIS_EVENTLOOP_FDSET_INCR
exists to make sure more than (maxclients+RESERVED) entries
are allocated, but we can only guarantee that if we include
the current value of REDIS_MIN_RESERVED_FDS as a minimum
for the INCR size.
This commit is contained in:
Matt Stancliff
2014-03-24 13:15:35 -04:00
committed by antirez
parent 3ce742d1d5
commit 771f8ad0e7
2 changed files with 8 additions and 7 deletions

View File

@ -1418,20 +1418,20 @@ void initServerConfig() {
/* This function will try to raise the max number of open files accordingly to
* the configured max number of clients. It also reserves a number of file
* descriptors (REDIS_EVENTLOOP_FDSET_INCR) for extra operations of
* descriptors (REDIS_MIN_RESERVED_FDS) for extra operations of
* persistence, listening sockets, log files and so forth.
*
* If it will not be possible to set the limit accordingly to the configured
* max number of clients, the function will do the reverse setting
* server.maxclients to the value that we can actually handle. */
void adjustOpenFilesLimit(void) {
rlim_t maxfiles = server.maxclients+REDIS_EVENTLOOP_FDSET_INCR;
rlim_t maxfiles = server.maxclients+REDIS_MIN_RESERVED_FDS;
struct rlimit limit;
if (getrlimit(RLIMIT_NOFILE,&limit) == -1) {
redisLog(REDIS_WARNING,"Unable to obtain the current NOFILE limit (%s), assuming 1024 and setting the max clients configuration accordingly.",
strerror(errno));
server.maxclients = 1024-REDIS_EVENTLOOP_FDSET_INCR;
server.maxclients = 1024-REDIS_MIN_RESERVED_FDS;
} else {
rlim_t oldlimit = limit.rlim_cur;
@ -1445,7 +1445,7 @@ void adjustOpenFilesLimit(void) {
limit.rlim_cur = f;
limit.rlim_max = f;
if (setrlimit(RLIMIT_NOFILE,&limit) != -1) break;
f -= REDIS_EVENTLOOP_FDSET_INCR;
f -= REDIS_MIN_RESERVED_FDS;
if (f > limit.rlim_cur) {
/* Instead of getting smaller, f just got bigger.
* That means it wrapped around its unsigned floor
@ -1461,7 +1461,7 @@ void adjustOpenFilesLimit(void) {
if (f < oldlimit) f = oldlimit;
if (f != maxfiles) {
int old_maxclients = server.maxclients;
server.maxclients = f-REDIS_EVENTLOOP_FDSET_INCR;
server.maxclients = f-REDIS_MIN_RESERVED_FDS;
if (server.maxclients < 1) {
redisLog(REDIS_WARNING,"Your current 'ulimit -n' "
"of %llu is not enough for Redis to start. "