From a1090a5b61247da206dd6aad2508345af2b0412f Mon Sep 17 00:00:00 2001 From: Willy Tarreau Date: Sat, 10 Apr 2021 16:58:13 +0200 Subject: [PATCH] MINOR: fd: move a few read-mostly variables to their own section Some pointer to arrays such as fdtab, fdinfo, polled_mask etc are never written to at run time but are used a lot. fdtab accesses appear a lot in perf top because ha_used_fds is in the same cache line and is modified all the time. This patch moves all these read-mostly variables to the read_mostly section when defined. This way their cache lines will be able to remain in shared state in all CPU caches. --- src/fd.c | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/src/fd.c b/src/fd.c index 4675373c7..f4a28cd3a 100644 --- a/src/fd.c +++ b/src/fd.c @@ -95,14 +95,14 @@ #include -struct fdtab *fdtab = NULL; /* array of all the file descriptors */ -struct polled_mask *polled_mask = NULL; /* Array for the polled_mask of each fd */ -struct fdinfo *fdinfo = NULL; /* less-often used infos for file descriptors */ +struct fdtab *fdtab __read_mostly = NULL; /* array of all the file descriptors */ +struct polled_mask *polled_mask __read_mostly = NULL; /* Array for the polled_mask of each fd */ +struct fdinfo *fdinfo __read_mostly = NULL; /* less-often used infos for file descriptors */ int totalconn; /* total # of terminated sessions */ int actconn; /* # of active sessions */ -struct poller pollers[MAX_POLLERS]; -struct poller cur_poller; +struct poller pollers[MAX_POLLERS] __read_mostly; +struct poller cur_poller __read_mostly; int nbpollers = 0; volatile struct fdlist update_list; // Global update list @@ -110,7 +110,7 @@ volatile struct fdlist update_list; // Global update list THREAD_LOCAL int *fd_updt = NULL; // FD updates list THREAD_LOCAL int fd_nbupdt = 0; // number of updates in the list THREAD_LOCAL int poller_rd_pipe = -1; // Pipe to wake the thread -int poller_wr_pipe[MAX_THREADS]; // Pipe to wake the threads +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