From: Victor Julien Date: Wed, 18 Sep 2024 09:50:59 +0000 (+0200) Subject: threads: align struct to CLS to avoid false sharing X-Git-Tag: suricata-8.0.0-beta1~585 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=2af67e17bc7c3e142abee2957d5597b5d55ea4f8;p=thirdparty%2Fsuricata.git threads: align struct to CLS to avoid false sharing Since `Thread` objects are part of a big allocation, more than one Thread could be on a single cache line, leading to false sharing. Atomic updates to one `Thread` could then lead to poor performance accessing another `Thread`. Align to CLS (cache line size) to avoid this. --- diff --git a/src/tm-threads.c b/src/tm-threads.c index 42200dbd43..5da183c311 100644 --- a/src/tm-threads.c +++ b/src/tm-threads.c @@ -2064,6 +2064,7 @@ static void TmThreadDumpThreads(void) } #endif +/* Aligned to CLS to avoid false sharing between atomic ops. */ typedef struct Thread_ { ThreadVars *tv; /**< threadvars structure */ const char *name; @@ -2075,7 +2076,7 @@ typedef struct Thread_ { SCTime_t sys_sec_stamp; /**< timestamp in real system * time when the pktts was last updated. */ SCSpinlock spin; -} Thread; +} __attribute__((aligned(CLS))) Thread; typedef struct Threads_ { Thread *threads;