MINOR: server: align server struct to 64 bytes

Several times recently, it was noticed that some benchmarks would
highly vary depending on the position of certain fields in the server
struct, and this could even vary between runs.

The server struct does have separate areas depending on the user cases
and hot/cold aspect of the members stored there, but the areas are
artificially kept apart using fixed padding instead of real alignment,
which has the first sad effect of artificially inflating the struct,
and the second one of misaligning it.

Now that we have all the necessary tools to keep them aligned, let's
just do it. The struct has shrunk from 4160 to 4032 bytes on 64-bit
systems, 152 of which are still holes or padding.
This commit is contained in:
Willy Tarreau 2025-08-13 15:07:55 +02:00
parent a469356268
commit cfdab917fe
2 changed files with 7 additions and 9 deletions

View File

@ -377,7 +377,7 @@ struct server {
/* The elements below may be changed on every single request by any
* thread, and generally at the same time.
*/
THREAD_PAD(63);
THREAD_ALIGN(64);
struct eb32_node idle_node; /* When to next do cleanup in the idle connections */
unsigned int curr_idle_conns; /* Current number of orphan idling connections, both the idle and the safe lists */
unsigned int curr_idle_nb; /* Current number of connections in the idle list */
@ -392,7 +392,7 @@ struct server {
/* Element below are usd by LB algorithms and must be doable in
* parallel to other threads reusing connections above.
*/
THREAD_PAD(63);
THREAD_ALIGN(64);
__decl_thread(HA_SPINLOCK_T lock); /* may enclose the proxy's lock, must not be taken under */
union {
struct eb32_node lb_node; /* node used for tree-based load balancing */
@ -406,14 +406,14 @@ struct server {
};
/* usually atomically updated by any thread during parsing or on end of request */
THREAD_PAD(63);
THREAD_ALIGN(64);
int cur_sess; /* number of currently active sessions (including syn_sent) */
int served; /* # of active sessions currently being served (ie not pending) */
int consecutive_errors; /* current number of consecutive errors */
struct be_counters counters; /* statistics counters */
/* Below are some relatively stable settings, only changed under the lock */
THREAD_PAD(63);
THREAD_ALIGN(64);
struct eb_root *lb_tree; /* we want to know in what tree the server is */
struct tree_occ *lb_nodes; /* lb_nodes_tot * struct tree_occ */

View File

@ -184,16 +184,14 @@ const struct mux_ops *srv_get_ws_proto(struct server *srv);
*/
static inline struct server *srv_alloc(void)
{
struct server *srv;
srv = calloc(1, sizeof(*srv));
return srv;
return ha_aligned_zalloc_typed(1, struct server);
}
/* free a previously allocated server an nullifies the pointer */
static inline void srv_free(struct server **srv_ptr)
{
ha_free(srv_ptr);
ha_aligned_free(*srv_ptr);
*srv_ptr = NULL;
}
/* increase the number of cumulated streams on the designated server */