Skip to content

Commit 51e2172

Browse files
committed
libchafa: Limit max auto threads to 24
1 parent 97d62a0 commit 51e2172

File tree

1 file changed

+12
-0
lines changed

1 file changed

+12
-0
lines changed

chafa/chafa-features.c

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,13 @@
4141
* @CHAFA_FEATURE_AVX2: Flag indicating AVX2 support.
4242
**/
4343

44+
/* The detected CPU count can approach 200 in realistic environments (64 on
45+
* UltraSparc T2, 192 on Ryzen Threadripper Pro), and mapped memory may be
46+
* limited to as little as 1.5GB (default RLIMIT_DATA on OpenBSD 7.8/sparc64 -
47+
* malloc's MAXDSIZ is set to 8GB). Keep a sensible thread limit to avoid
48+
* running out of memory. */
49+
#define AUTO_THREAD_COUNT_MAX 24
50+
4451
static gboolean chafa_initialized;
4552

4653
static gboolean have_mmx;
@@ -261,8 +268,13 @@ chafa_get_n_actual_threads (void)
261268
gint n_actual_threads;
262269

263270
n_actual_threads = chafa_get_n_threads ();
271+
264272
if (n_actual_threads < 0)
273+
{
265274
n_actual_threads = g_get_num_processors ();
275+
n_actual_threads = MIN (n_actual_threads, AUTO_THREAD_COUNT_MAX);
276+
}
277+
266278
if (n_actual_threads <= 0)
267279
n_actual_threads = 1;
268280

0 commit comments

Comments
 (0)