MCPcopy Create free account
hub / github.com/Snapchat/KeyDB / malloc_init_narenas

Function malloc_init_narenas

deps/jemalloc/src/jemalloc.c:1627–1701  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1625}
1626
1627static bool
1628malloc_init_narenas(void) {
1629 assert(ncpus > 0);
1630
1631 if (opt_percpu_arena != percpu_arena_disabled) {
1632 if (!have_percpu_arena || malloc_getcpu() < 0) {
1633 opt_percpu_arena = percpu_arena_disabled;
1634 malloc_printf("<jemalloc>: perCPU arena getcpu() not "
1635 "available. Setting narenas to %u.\n", opt_narenas ?
1636 opt_narenas : malloc_narenas_default());
1637 if (opt_abort) {
1638 abort();
1639 }
1640 } else {
1641 if (ncpus >= MALLOCX_ARENA_LIMIT) {
1642 malloc_printf("<jemalloc>: narenas w/ percpu"
1643 "arena beyond limit (%d)\n", ncpus);
1644 if (opt_abort) {
1645 abort();
1646 }
1647 return true;
1648 }
1649 /* NB: opt_percpu_arena isn't fully initialized yet. */
1650 if (percpu_arena_as_initialized(opt_percpu_arena) ==
1651 per_phycpu_arena && ncpus % 2 != 0) {
1652 malloc_printf("<jemalloc>: invalid "
1653 "configuration -- per physical CPU arena "
1654 "with odd number (%u) of CPUs (no hyper "
1655 "threading?).\n", ncpus);
1656 if (opt_abort)
1657 abort();
1658 }
1659 unsigned n = percpu_arena_ind_limit(
1660 percpu_arena_as_initialized(opt_percpu_arena));
1661 if (opt_narenas < n) {
1662 /*
1663 * If narenas is specified with percpu_arena
1664 * enabled, actual narenas is set as the greater
1665 * of the two. percpu_arena_choose will be free
1666 * to use any of the arenas based on CPU
1667 * id. This is conservative (at a small cost)
1668 * but ensures correctness.
1669 *
1670 * If for some reason the ncpus determined at
1671 * boot is not the actual number (e.g. because
1672 * of affinity setting from numactl), reserving
1673 * narenas this way provides a workaround for
1674 * percpu_arena.
1675 */
1676 opt_narenas = n;
1677 }
1678 }
1679 }
1680 if (opt_narenas == 0) {
1681 opt_narenas = malloc_narenas_default();
1682 }
1683 assert(opt_narenas > 0);
1684

Callers 1

malloc_init_hardFunction · 0.70

Calls 8

arena_init_hugeFunction · 0.85
malloc_printfFunction · 0.70
malloc_narenas_defaultFunction · 0.70
narenas_total_setFunction · 0.70
narenas_total_incFunction · 0.70
narenas_total_getFunction · 0.70
percpu_arena_ind_limitFunction · 0.50

Tested by

no test coverage detected