| 1396 | } |
| 1397 | |
| 1398 | static bool |
| 1399 | malloc_init_narenas(void) { |
| 1400 | assert(ncpus > 0); |
| 1401 | |
| 1402 | if (opt_percpu_arena != percpu_arena_disabled) { |
| 1403 | if (!have_percpu_arena || malloc_getcpu() < 0) { |
| 1404 | opt_percpu_arena = percpu_arena_disabled; |
| 1405 | malloc_printf("<jemalloc>: perCPU arena getcpu() not " |
| 1406 | "available. Setting narenas to %u.\n", opt_narenas ? |
| 1407 | opt_narenas : malloc_narenas_default()); |
| 1408 | if (opt_abort) { |
| 1409 | abort(); |
| 1410 | } |
| 1411 | } else { |
| 1412 | if (ncpus >= MALLOCX_ARENA_LIMIT) { |
| 1413 | malloc_printf("<jemalloc>: narenas w/ percpu" |
| 1414 | "arena beyond limit (%d)\n", ncpus); |
| 1415 | if (opt_abort) { |
| 1416 | abort(); |
| 1417 | } |
| 1418 | return true; |
| 1419 | } |
| 1420 | /* NB: opt_percpu_arena isn't fully initialized yet. */ |
| 1421 | if (percpu_arena_as_initialized(opt_percpu_arena) == |
| 1422 | per_phycpu_arena && ncpus % 2 != 0) { |
| 1423 | malloc_printf("<jemalloc>: invalid " |
| 1424 | "configuration -- per physical CPU arena " |
| 1425 | "with odd number (%u) of CPUs (no hyper " |
| 1426 | "threading?).\n", ncpus); |
| 1427 | if (opt_abort) |
| 1428 | abort(); |
| 1429 | } |
| 1430 | unsigned n = percpu_arena_ind_limit( |
| 1431 | percpu_arena_as_initialized(opt_percpu_arena)); |
| 1432 | if (opt_narenas < n) { |
| 1433 | /* |
| 1434 | * If narenas is specified with percpu_arena |
| 1435 | * enabled, actual narenas is set as the greater |
| 1436 | * of the two. percpu_arena_choose will be free |
| 1437 | * to use any of the arenas based on CPU |
| 1438 | * id. This is conservative (at a small cost) |
| 1439 | * but ensures correctness. |
| 1440 | * |
| 1441 | * If for some reason the ncpus determined at |
| 1442 | * boot is not the actual number (e.g. because |
| 1443 | * of affinity setting from numactl), reserving |
| 1444 | * narenas this way provides a workaround for |
| 1445 | * percpu_arena. |
| 1446 | */ |
| 1447 | opt_narenas = n; |
| 1448 | } |
| 1449 | } |
| 1450 | } |
| 1451 | if (opt_narenas == 0) { |
| 1452 | opt_narenas = malloc_narenas_default(); |
| 1453 | } |
| 1454 | assert(opt_narenas > 0); |
| 1455 |
no test coverage detected