From: Olivier Houchard Date: Thu, 2 Jul 2026 14:36:23 +0000 (+0200) Subject: MEDIUM: pollers: Allow one polled_mask per thread group X-Git-Url: http://git.ipfire.org/gitweb/?a=commitdiff_plain;h=eef010489a828b85d75f1f1d834a87bd7dff3c4a;p=thirdparty%2Fhaproxy.git MEDIUM: pollers: Allow one polled_mask per thread group Similarly to what's been done for fdtab, create one polled_mask per thread group if GTUNE_NO_TG_FD_SHARING is set. As the flag can't be set yet, this commit should have no impact. --- diff --git a/include/haproxy/fd.h b/include/haproxy/fd.h index 9307cfcf8..f993c6bbc 100644 --- a/include/haproxy/fd.h +++ b/include/haproxy/fd.h @@ -43,7 +43,7 @@ extern int totalconn; /* total # of terminated sessions */ extern int actconn; /* # of active sessions */ extern volatile struct fdlist update_list[MAX_TGROUPS]; -extern struct polled_mask *polled_mask; +extern THREAD_LOCAL struct polled_mask *polled_mask; /* Array for the polled_mask of each fd */ extern THREAD_LOCAL int *fd_updt; // FD updates list extern THREAD_LOCAL int fd_nbupdt; // number of updates in the list diff --git a/include/haproxy/tinfo-t.h b/include/haproxy/tinfo-t.h index 153f506eb..572781732 100644 --- a/include/haproxy/tinfo-t.h +++ b/include/haproxy/tinfo-t.h @@ -139,6 +139,7 @@ struct tgroup_ctx { uint niced_tasks; /* number of niced tasks in this group's run queues */ uint committed_extra_streams; /* sum of extra front streams committed by muxes in this group */ struct fdtab *fdtab; /* fdtab to be used by that thread group */ + struct polled_mask *polled_mask; /* polled_mask to be used by that thread group */ /* pad to cache line (64B) */ char __pad[0]; /* unused except to check remaining room */ diff --git a/src/fd.c b/src/fd.c index 158c2d480..9c851fe07 100644 --- a/src/fd.c +++ b/src/fd.c @@ -100,7 +100,8 @@ THREAD_LOCAL struct fdtab *fdtab = NULL; /* array of all the file descriptors */ static struct fdtab *_fdtab; -struct polled_mask *polled_mask __read_mostly = NULL; /* Array for the polled_mask of each fd */ +THREAD_LOCAL struct polled_mask *polled_mask = NULL; /* Array for the polled_mask of each fd */ +static struct polled_mask *_polled_mask; int totalconn; /* total # of terminated sessions */ int actconn; /* # of active sessions */ @@ -1217,11 +1218,23 @@ int init_pollers() fdtab = ha_tgroup_ctx[0].fdtab; vma_set_name(_fdtab, global.maxsock * sizeof(*fdtab) * nbfdtab, "fd", "fdtab"); - if ((polled_mask = calloc(global.maxsock, sizeof(*polled_mask))) == NULL) { + if ((_polled_mask = calloc(global.maxsock, nbfdtab * sizeof(*polled_mask))) == NULL) { ha_alert("Not enough memory to allocate %d entries for polled_mask!\n", global.maxsock); goto fail_polledmask; } - vma_set_name(polled_mask, global.maxsock * sizeof(*polled_mask), "fd", "polled_mask"); + + /* + * As for fdtab, get on polled_mask per thread group, if needed. + */ + for (p = 0; p < global.nbtgroups; p++) { + if (global.tune.options & GTUNE_NO_TG_FD_SHARING) + ha_tgroup_ctx[p].polled_mask = _polled_mask + p * global.maxsock; + else + ha_tgroup_ctx[p].polled_mask = _polled_mask; + } + /* immediately set it for the boot thread as well */ + polled_mask = ha_tgroup_ctx[0].polled_mask; + vma_set_name(_polled_mask, global.maxsock * sizeof(*polled_mask) * nbfdtab, "fd", "polled_mask"); for (p = 0; p < MAX_TGROUPS; p++) update_list[p].first = update_list[p].last = -1; @@ -1247,9 +1260,11 @@ int init_pollers() } while (!bp || bp->pref == 0); fail_info: - free(polled_mask); + free(_polled_mask); + _polled_mask = polled_mask = NULL; fail_polledmask: - ha_aligned_free(fdtab); + ha_aligned_free(_fdtab); + _fdtab = fdtab = NULL; fail_tab: return 0; } @@ -1269,8 +1284,13 @@ void deinit_pollers() { bp->term(bp); } - ha_aligned_free(fdtab); - ha_free(&polled_mask); + /* free the backing areas, not the (possibly per-group) thread-local + * pointers which may not point to the start of the allocations. + */ + ha_aligned_free(_fdtab); + _fdtab = fdtab = NULL; + ha_free(&_polled_mask); + polled_mask = NULL; } /* diff --git a/src/haproxy.c b/src/haproxy.c index a50baf98d..aecb97a61 100644 --- a/src/haproxy.c +++ b/src/haproxy.c @@ -3122,6 +3122,7 @@ void *run_thread_poll_loop(void *data) ha_set_thread(data); fdtab = tg_ctx->fdtab; + polled_mask = tg_ctx->polled_mask; set_thread_cpu_affinity(); clock_set_local_source(); ha_random_seed_thread();