Skip to content

Commit 77bd1f6

Browse files
committed
Fix maximum number of arenas in op_initialize()
Number of arenas greater than 253 causes the "Resource temporarily unavailable" error on a machine with 96 cores. Signed-off-by: Lukasz Dorau <[email protected]>
1 parent 0a63bbd commit 77bd1f6

File tree

1 file changed

+20
-2
lines changed

1 file changed

+20
-2
lines changed

src/pool/pool_jemalloc.c

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
*/
77

88
#include <assert.h>
9+
#include <errno.h>
910
#include <stdio.h>
1011
#include <stdlib.h>
1112
#include <string.h>
@@ -440,9 +441,14 @@ static umf_result_t op_initialize(umf_memory_provider_handle_t provider,
440441

441442
if (n_arenas == 0) {
442443
n_arenas = utils_get_num_cores() * 4;
444+
if (n_arenas > MALLOCX_ARENA_MAX) {
445+
n_arenas = MALLOCX_ARENA_MAX;
446+
}
443447
}
448+
444449
if (n_arenas > MALLOCX_ARENA_MAX) {
445-
LOG_ERR("Number of arenas exceeds the limit.");
450+
LOG_ERR("Number of arenas %zu exceeds the limit (%i).", n_arenas,
451+
MALLOCX_ARENA_MAX);
446452
return UMF_RESULT_ERROR_INVALID_ARGUMENT;
447453
}
448454

@@ -461,7 +467,19 @@ static umf_result_t op_initialize(umf_memory_provider_handle_t provider,
461467
err = je_mallctl("arenas.create", (void *)&arena_index, &unsigned_size,
462468
NULL, 0);
463469
if (err) {
464-
LOG_ERR("Could not create arena.");
470+
// EAGAIN - means that a memory allocation failure occurred
471+
// (2 * utils_get_num_cores()) is the required minimum number of arenas
472+
if (err == EAGAIN && (i >= (2 * utils_get_num_cores()))) {
473+
LOG_WARN("Could not create the #%zu jemalloc arena (%s), "
474+
"setting n_arenas = %zu",
475+
i + 1, strerror(err), i);
476+
n_arenas = i;
477+
break;
478+
}
479+
480+
LOG_ERR("Could not create a jemalloc arena (n_arenas = %zu, i = "
481+
"%zu, arena_index = %u, unsigned_size = %zu): %s",
482+
n_arenas, i, arena_index, unsigned_size, strerror(err));
465483
goto err_cleanup;
466484
}
467485

0 commit comments

Comments
 (0)