]> git.ipfire.org Git - thirdparty/haproxy.git/commitdiff
CLEANUP: fd: make use of ha_aligned_alloc() for the fdtab
authorWilly Tarreau <w@1wt.eu>
Mon, 11 Aug 2025 16:55:09 +0000 (18:55 +0200)
committerWilly Tarreau <w@1wt.eu>
Mon, 11 Aug 2025 17:55:30 +0000 (19:55 +0200)
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.

src/fd.c

index cd30b34d4a8ab3903eea155d480440e9025ae98f..3d7d198ab7c62d9c036770975f51468208b683cd 100644 (file)
--- 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 <fd> to fd list <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);
 }