Changeset View
Changeset View
Standalone View
Standalone View
head/contrib/jemalloc/src/base.c
Show First 20 Lines • Show All 256 Lines • ▼ Show 20 Lines | base_block_alloc(tsdn_t *tsdn, base_t *base, extent_hooks_t *extent_hooks, | ||||
* Create increasingly larger blocks in order to limit the total number | * Create increasingly larger blocks in order to limit the total number | ||||
* of disjoint virtual memory ranges. Choose the next size in the page | * of disjoint virtual memory ranges. Choose the next size in the page | ||||
* size class series (skipping size classes that are not a multiple of | * size class series (skipping size classes that are not a multiple of | ||||
* HUGEPAGE), or a size large enough to satisfy the requested size and | * HUGEPAGE), or a size large enough to satisfy the requested size and | ||||
* alignment, whichever is larger. | * alignment, whichever is larger. | ||||
*/ | */ | ||||
size_t min_block_size = HUGEPAGE_CEILING(sz_psz2u(header_size + gap_size | size_t min_block_size = HUGEPAGE_CEILING(sz_psz2u(header_size + gap_size | ||||
+ usize)); | + usize)); | ||||
pszind_t pind_next = (*pind_last + 1 < NPSIZES) ? *pind_last + 1 : | pszind_t pind_next = (*pind_last + 1 < sz_psz2ind(SC_LARGE_MAXCLASS)) ? | ||||
*pind_last; | *pind_last + 1 : *pind_last; | ||||
size_t next_block_size = HUGEPAGE_CEILING(sz_pind2sz(pind_next)); | size_t next_block_size = HUGEPAGE_CEILING(sz_pind2sz(pind_next)); | ||||
size_t block_size = (min_block_size > next_block_size) ? min_block_size | size_t block_size = (min_block_size > next_block_size) ? min_block_size | ||||
: next_block_size; | : next_block_size; | ||||
base_block_t *block = (base_block_t *)base_map(tsdn, extent_hooks, ind, | base_block_t *block = (base_block_t *)base_map(tsdn, extent_hooks, ind, | ||||
block_size); | block_size); | ||||
if (block == NULL) { | if (block == NULL) { | ||||
return NULL; | return NULL; | ||||
} | } | ||||
▲ Show 20 Lines • Show All 92 Lines • ▼ Show 20 Lines | if (malloc_mutex_init(&base->mtx, "base", WITNESS_RANK_BASE, | ||||
malloc_mutex_rank_exclusive)) { | malloc_mutex_rank_exclusive)) { | ||||
base_unmap(tsdn, extent_hooks, ind, block, block->size); | base_unmap(tsdn, extent_hooks, ind, block, block->size); | ||||
return NULL; | return NULL; | ||||
} | } | ||||
base->pind_last = pind_last; | base->pind_last = pind_last; | ||||
base->extent_sn_next = extent_sn_next; | base->extent_sn_next = extent_sn_next; | ||||
base->blocks = block; | base->blocks = block; | ||||
base->auto_thp_switched = false; | base->auto_thp_switched = false; | ||||
for (szind_t i = 0; i < NSIZES; i++) { | for (szind_t i = 0; i < SC_NSIZES; i++) { | ||||
extent_heap_new(&base->avail[i]); | extent_heap_new(&base->avail[i]); | ||||
} | } | ||||
if (config_stats) { | if (config_stats) { | ||||
base->allocated = sizeof(base_block_t); | base->allocated = sizeof(base_block_t); | ||||
base->resident = PAGE_CEILING(sizeof(base_block_t)); | base->resident = PAGE_CEILING(sizeof(base_block_t)); | ||||
base->mapped = block->size; | base->mapped = block->size; | ||||
base->n_thp = (opt_metadata_thp == metadata_thp_always) && | base->n_thp = (opt_metadata_thp == metadata_thp_always) && | ||||
metadata_thp_madvise() ? HUGEPAGE_CEILING(sizeof(base_block_t)) | metadata_thp_madvise() ? HUGEPAGE_CEILING(sizeof(base_block_t)) | ||||
Show All 37 Lines | |||||
base_alloc_impl(tsdn_t *tsdn, base_t *base, size_t size, size_t alignment, | base_alloc_impl(tsdn_t *tsdn, base_t *base, size_t size, size_t alignment, | ||||
size_t *esn) { | size_t *esn) { | ||||
alignment = QUANTUM_CEILING(alignment); | alignment = QUANTUM_CEILING(alignment); | ||||
size_t usize = ALIGNMENT_CEILING(size, alignment); | size_t usize = ALIGNMENT_CEILING(size, alignment); | ||||
size_t asize = usize + alignment - QUANTUM; | size_t asize = usize + alignment - QUANTUM; | ||||
extent_t *extent = NULL; | extent_t *extent = NULL; | ||||
malloc_mutex_lock(tsdn, &base->mtx); | malloc_mutex_lock(tsdn, &base->mtx); | ||||
for (szind_t i = sz_size2index(asize); i < NSIZES; i++) { | for (szind_t i = sz_size2index(asize); i < SC_NSIZES; i++) { | ||||
extent = extent_heap_remove_first(&base->avail[i]); | extent = extent_heap_remove_first(&base->avail[i]); | ||||
if (extent != NULL) { | if (extent != NULL) { | ||||
/* Use existing space. */ | /* Use existing space. */ | ||||
break; | break; | ||||
} | } | ||||
} | } | ||||
if (extent == NULL) { | if (extent == NULL) { | ||||
/* Try to allocate more space. */ | /* Try to allocate more space. */ | ||||
▲ Show 20 Lines • Show All 77 Lines • Show Last 20 Lines |