From 1bb975464815eea709eeaa75942b4536a2ed202d Mon Sep 17 00:00:00 2001 From: Willy Tarreau Date: Mon, 11 Aug 2025 17:43:51 +0200 Subject: [PATCH] OPTIM: server: start to use aligned allocs in server This is currently for per-thread arrays like idle conns etc. We're now cache-aligning the per-thread arrays so as to put an end to false sharing. A comparative test between no alignment and alignment on a simple config with round robin between 4 servers showed an average rate of 1.75M/s vs 1.72M/s before for 100M requests. The gain seems to be more commonly less than 1% however. This should mostly help make measurements more reproducible across multiple runs. --- src/server.c | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/src/server.c b/src/server.c index e53d4847c..c299d202b 100644 --- a/src/server.c +++ b/src/server.c @@ -3122,9 +3122,9 @@ void srv_free_params(struct server *srv) free(srv->hostname); free(srv->hostname_dn); free((char*)srv->conf.file); - free(srv->per_thr); - free(srv->per_tgrp); - free(srv->curr_idle_thr); + ha_aligned_free(srv->per_thr); + ha_aligned_free(srv->per_tgrp); + ha_aligned_free(srv->curr_idle_thr); free(srv->pool_conn_name); release_sample_expr(srv->pool_conn_name_expr); free(srv->resolvers_id); @@ -3482,7 +3482,7 @@ int srv_init(struct server *srv) /* initialize idle conns lists */ if (srv->max_idle_conns != 0) { - srv->curr_idle_thr = calloc(global.nbthread, sizeof(*srv->curr_idle_thr)); + srv->curr_idle_thr = ha_aligned_zalloc(64, global.nbthread * sizeof(*srv->curr_idle_thr)); if (!srv->curr_idle_thr) { ha_alert("memory error during idle conn list init for %s/%s server\n", srv->proxy->id, srv->id); @@ -5918,8 +5918,8 @@ static int srv_init_per_thr(struct server *srv) { int i; - srv->per_thr = calloc(global.nbthread, sizeof(*srv->per_thr)); - srv->per_tgrp = calloc(global.nbtgroups, sizeof(*srv->per_tgrp)); + srv->per_thr = ha_aligned_zalloc(64, global.nbthread * sizeof(*srv->per_thr)); + srv->per_tgrp = ha_aligned_zalloc(64, global.nbtgroups * sizeof(*srv->per_tgrp)); if (!srv->per_thr || !srv->per_tgrp) return -1;