]> git.ipfire.org Git - thirdparty/suricata.git/commitdiff
threads: align struct to CLS to avoid false sharing
authorVictor Julien <vjulien@oisf.net>
Wed, 18 Sep 2024 09:50:59 +0000 (11:50 +0200)
committerVictor Julien <victor@inliniac.net>
Fri, 10 Jan 2025 08:16:36 +0000 (09:16 +0100)
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.

src/tm-threads.c

index 42200dbd4325aed67cce1ddbda4bb9dd9b3a3d31..5da183c311bebb9d5b7c80446368b0e29e7e0cef 100644 (file)
@@ -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;