From 24a38e4313b9abfe632cc61a458f705e31f83ef6 Mon Sep 17 00:00:00 2001 From: Arran Cudbard-Bell Date: Sun, 28 Sep 2025 19:02:35 -0400 Subject: [PATCH] size also needs to be on a separate line --- src/lib/io/atomic_queue.c | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/src/lib/io/atomic_queue.c b/src/lib/io/atomic_queue.c index 75f31d4eb4..7a4d7837f6 100644 --- a/src/lib/io/atomic_queue.c +++ b/src/lib/io/atomic_queue.c @@ -68,6 +68,10 @@ typedef struct CC_HINT(packed, aligned(CACHE_LINE_SIZE)) { /** Structure to hold the atomic queue * + * @note DO NOT redorder these fields without understanding how alignas works + * and maintaining separation. The head and tail must be in different cache lines + * to reduce contention between producers and consumers. Cold data (size, chunk) + * can share a line, but must be separated from head and tail and entry. */ struct fr_atomic_queue_s { alignas(CACHE_LINE_SIZE) atomic_int64_t head; //!< Position of the producer. @@ -82,7 +86,10 @@ struct fr_atomic_queue_s { ///< Reads may still need to occur from size ///< whilst the producer is writing to tail. - size_t size; //!< The length of the queue. This is static. + alignas(CACHE_LINE_SIZE) size_t size; //!< The length of the queue. This is static. + ///< Also needs to be cache aligned, otherwise + ///< it can end up directly after tail in memory + ///< and share a cache line. void *chunk; //!< The start of the talloc chunk to pass to free. ///< We need to play tricks to get aligned memory -- 2.47.3