diff --git a/include/haproxy/global-t.h b/include/haproxy/global-t.h index 2e74859ae..d7a1ff5ee 100644 --- a/include/haproxy/global-t.h +++ b/include/haproxy/global-t.h @@ -233,6 +233,7 @@ struct global { * than 255 arguments */ /* 2-bytes hole */ + int est_fd_usage; /* rough estimate of reserved FDs (listeners, pollers etc) */ int cfg_curr_line; /* line number currently being parsed */ const char *cfg_curr_file; /* config file currently being parsed or NULL */ char *cfg_curr_section; /* config section name currently being parsed or NULL */ diff --git a/src/haproxy.c b/src/haproxy.c index 52e60d39c..cc26c6447 100644 --- a/src/haproxy.c +++ b/src/haproxy.c @@ -2304,6 +2304,9 @@ static void step_init_2(int argc, char** argv) global.maxsock += p->peers_fe->maxconn; } + /* count listeners, checks, plus 1 poller and one wake-up pipe (2fd) per thread */ + global.est_fd_usage = global.maxsock + 3 * global.nbthread; + /* Compute the global.maxconn and possibly global.maxsslconn values */ set_global_maxconn(); global.maxsock = compute_ideal_maxsock(global.maxconn); diff --git a/src/limits.c b/src/limits.c index f4dacfc56..d2aa3cffc 100644 --- a/src/limits.c +++ b/src/limits.c @@ -105,9 +105,9 @@ int compute_ideal_maxpipes() /* considers global.maxsocks, global.maxpipes, async engines, SSL frontends and * rlimits and computes an ideal maxconn. It's meant to be called only when - * maxsock contains the sum of listening FDs, before it is updated based on - * maxconn and pipes. If there are not enough FDs left, DEFAULT_MAXCONN (by - * default 100) is returned as it is expected that it will even run on tight + * global.est_fd_usage contains the sum of listening FDs, before it is updated + * based on maxconn and pipes. If there are not enough FDs left, DEFAULT_MAXCONN + * (by default 100) is returned as it is expected that it will even run on tight * environments, and will maintain compatibility with previous packages that * used to rely on this value as the default one. The system will emit a * warning indicating how many FDs are missing anyway if needed. @@ -162,13 +162,7 @@ static int compute_ideal_maxconn() } /* subtract listeners and checks */ - remain -= global.maxsock; - - /* one epoll_fd/kqueue_fd per thread */ - remain -= global.nbthread; - - /* one wake-up pipe (2 fd) per thread */ - remain -= 2 * global.nbthread; + remain -= global.est_fd_usage; /* Fixed pipes values : we only subtract them if they're not larger * than the remaining FDs because pipes are optional.