From: Willy Tarreau Date: Mon, 11 Aug 2025 16:55:09 +0000 (+0200) Subject: CLEANUP: fd: make use of ha_aligned_alloc() for the fdtab X-Git-Tag: v3.3-dev7~41 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=5e2837cfb42cdac6761696276c1c1ecde80b4d72;p=thirdparty%2Fhaproxy.git CLEANUP: fd: make use of ha_aligned_alloc() for the fdtab We've forcefully aligned the fdtab in commit 97ea9c49f1 ("BUG/MEDIUM: fd: always align fdtab[] to 64 bytes"), but now we don't need such hacks anymore thanks to ha_aligned_alloc(). Let's use it and get rid of fdtab_addr. --- diff --git a/src/fd.c b/src/fd.c index cd30b34d4..3d7d198ab 100644 --- a/src/fd.c +++ b/src/fd.c @@ -117,7 +117,6 @@ THREAD_LOCAL int poller_rd_pipe = -1; // Pipe to wake the thread int poller_wr_pipe[MAX_THREADS] __read_mostly; // Pipe to wake the threads volatile int ha_used_fds = 0; // Number of FD we're currently using -static struct fdtab *fdtab_addr; /* address of the allocated area containing fdtab */ /* adds fd to fd list if it was not yet in it */ void fd_add_to_fd_list(volatile struct fdlist *list, int fd) @@ -1166,14 +1165,12 @@ int init_pollers() int p; struct poller *bp; - if ((fdtab_addr = calloc(1, global.maxsock * sizeof(*fdtab) + 64)) == NULL) { + /* always provide an aligned fdtab */ + if ((fdtab = ha_aligned_zalloc(64, global.maxsock * sizeof(*fdtab))) == NULL) { ha_alert("Not enough memory to allocate %d entries for fdtab!\n", global.maxsock); goto fail_tab; } - vma_set_name(fdtab_addr, global.maxsock * sizeof(*fdtab) + 64, "fd", "fdtab_addr"); - - /* always provide an aligned fdtab */ - fdtab = (struct fdtab*)((((size_t)fdtab_addr) + 63) & -(size_t)64); + vma_set_name(fdtab, global.maxsock * sizeof(*fdtab), "fd", "fdtab"); if ((polled_mask = calloc(global.maxsock, sizeof(*polled_mask))) == NULL) { ha_alert("Not enough memory to allocate %d entries for polled_mask!\n", global.maxsock); @@ -1214,7 +1211,7 @@ int init_pollers() fail_info: free(polled_mask); fail_polledmask: - free(fdtab_addr); + ha_aligned_free(fdtab); fail_tab: return 0; } @@ -1235,7 +1232,7 @@ void deinit_pollers() { } ha_free(&fdinfo); - ha_free(&fdtab_addr); + ha_aligned_free(fdtab); ha_free(&polled_mask); }