From 693688e734b98d6e661b7effe969c8e9a2f6830c Mon Sep 17 00:00:00 2001 From: Willy Tarreau Date: Sat, 6 Aug 2022 16:37:27 +0200 Subject: [PATCH] MINOR: config: automatically preset MAX_THREADS based on MAX_TGROUPS MAX_THREADS was not changed when setting MAX_TGROUPS, which still limits some possibilities. Let's preset it to 4 * LONGBITS when MAX_TGROUPS is larger than 1, or LONGBITS when it's set to 1. This means that the new default value is 256 threads. The rationale behind this is that the main use of thread groups is mostly to address NUMA issues and that we don't necessarily need large thread counts when using many groups, and 256 threads is already plenty even on quite large systems. For now it's important not to go too far because some internal structs are arrays of MAX_THREADS entries, for example accept_queue_ring, which is around 8kB per thread. Such structures will need to become dynamic before defaulting to large thread counts (at 4096 threads max the accept queues would require 32 MB RAM alone). --- include/haproxy/defaults.h | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/include/haproxy/defaults.h b/include/haproxy/defaults.h index 6dc5167d8..a8e5e5780 100644 --- a/include/haproxy/defaults.h +++ b/include/haproxy/defaults.h @@ -34,10 +34,6 @@ #define MAX_THREADS_PER_GROUP 1 #else -/* threads enabled, max_threads defaults to long bits */ -#ifndef MAX_THREADS -#define MAX_THREADS LONGBITS -#endif /* theoretical limit is 64, though we'd rather not push it too far for now * as some structures might be enlarged to be indexed per group. Let's start @@ -48,9 +44,18 @@ #ifndef MAX_TGROUPS #define MAX_TGROUPS 16 #endif + #define MAX_THREADS_PER_GROUP LONGBITS + +/* threads enabled, max_threads defaults to long bits for 1 tgroup or 4 times + * long bits if more tgroups are enabled. + */ +#ifndef MAX_THREADS +#define MAX_THREADS ((((MAX_TGROUPS) > 1) ? 4 : 1) * (MAX_THREADS_PER_GROUP)) #endif +#endif // USE_THREAD + /* * BUFSIZE defines the size of a read and write buffer. It is the maximum * amount of bytes which can be stored by the proxy for each stream. However,