]> git.ipfire.org Git - thirdparty/haproxy.git/commitdiff
MEDIUM: pollers: Only allow epoll when each tgroup has its fd table
authorOlivier Houchard <ohouchard@haproxy.com>
Wed, 8 Jul 2026 14:01:36 +0000 (16:01 +0200)
committerOlivier Houchard <cognet@ci0.org>
Thu, 30 Jul 2026 11:35:22 +0000 (13:35 +0200)
Getting pollers such as select and poll to work when thread groups
unshared their file descriptors would require to have per-thread groups
arrays of file descriptors. Given making each thread group its own file
descriptor table is done for performance reasons, and those pollers will
never perform very well, this does not seem to be worth it.
kqueue and evports would work, except that they are only implemented on
OSes that do not provide the equivalent of the unshare() system call.
So effectively, only epoll can be used as a poller when fds are not
shared across thread groups.

include/haproxy/fd-t.h
src/ev_epoll.c
src/fd.c

index a57fd6e8fab893c3242d8520e365c1d7aeb6056e..fcd71405adaaeaf81bb15ea11e8038d8d57889ce 100644 (file)
@@ -231,6 +231,7 @@ struct polled_mask {
 
 #define HAP_POLL_F_RDHUP        0x00000001                   /* the poller notifies of HUP with reads */
 #define HAP_POLL_F_ERRHUP       0x00000002                   /* the poller reports ERR and HUP */
+#define HAP_POLL_F_NO_FD_SHARING 0x00000004                  /* the poller supports not sharing fds across thread groups */
 
 struct poller {
        void   *private;                                     /* any private data for the poller */
index 1f99e7cebc2c4d0b31f45d2f58ea505408ed9143..5e205fe6917050a820f4b3094f30cfe395e9142d 100644 (file)
@@ -470,7 +470,7 @@ static void _do_register(void)
 
        p->name = "epoll";
        p->pref = 300;
-       p->flags = HAP_POLL_F_ERRHUP; // note: RDHUP might be dynamically added
+       p->flags = HAP_POLL_F_ERRHUP | HAP_POLL_F_NO_FD_SHARING; // note: RDHUP might be dynamically added
        p->private = NULL;
 
        p->clo  = __fd_clo;
index c1f72502928a643d38c0afebbecac947111bfa65..7e106654e871c0a805e4f510864c3cc4888ed8cf 100644 (file)
--- a/src/fd.c
+++ b/src/fd.c
@@ -1273,6 +1273,7 @@ int init_pollers()
 
        do {
                bp = NULL;
+redo:
                for (p = 0; p < nbpollers; p++)
                        if (!bp || (pollers[p].pref > bp->pref))
                                bp = &pollers[p];
@@ -1280,6 +1281,13 @@ int init_pollers()
                if (!bp || bp->pref == 0)
                        break;
 
+               if ((global.tune.options & GTUNE_NO_TG_FD_SHARING) &&
+                   !(bp->flags & HAP_POLL_F_NO_FD_SHARING)) {
+                       ha_alert("Can't use poller '%s' with per-thread-group FD tables\n", bp->name);
+                       bp->pref = 0;
+                       goto redo;
+               }
+
                if (bp->init(bp)) {
                        memcpy(&cur_poller, bp, sizeof(*bp));
                        return 1;