]> git.ipfire.org Git - thirdparty/haproxy.git/commitdiff
MINOR: limits: keep a copy of the rough estimate of needed FDs in global struct
authorWilly Tarreau <w@1wt.eu>
Thu, 20 Nov 2025 07:29:45 +0000 (08:29 +0100)
committerWilly Tarreau <w@1wt.eu>
Thu, 20 Nov 2025 07:44:52 +0000 (08:44 +0100)
It's always a pain to guess the number of FDs that can be needed by
listeners, checks, threads, pollers etc. We have this estimate in
global.maxsock before calling set_global_maxconn(), but we lose it
the line after. Let's copy it into global.est_fd_usage and keep it.
This will be helpful to try to provide more accurate suggestions for
maxconn.

include/haproxy/global-t.h
src/haproxy.c
src/limits.c

index 2e74859ae1570ad7137575d6a92deff9732555e6..d7a1ff5eedd312253b170559178621ec420cd4ab 100644 (file)
@@ -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 */
index 52e60d39c5a779f60bf2be415467de3f171ca994..cc26c6447472c16ef304d47f73e58a7cb4825cd7 100644 (file)
@@ -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);
index f4dacfc56232abbb943459e4a86ea536ff09abb9..d2aa3cffccac444260b19a9d5254fba52f1aaefe 100644 (file)
@@ -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.