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

Function base_alloc_impl

deps/jemalloc/src/base.c:420–453  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

418}
419
420static void *
421base_alloc_impl(tsdn_t *tsdn, base_t *base, size_t size, size_t alignment,
422 size_t *esn) {
423 alignment = QUANTUM_CEILING(alignment);
424 size_t usize = ALIGNMENT_CEILING(size, alignment);
425 size_t asize = usize + alignment - QUANTUM;
426
427 extent_t *extent = NULL;
428 malloc_mutex_lock(tsdn, &base->mtx);
429 for (szind_t i = sz_size2index(asize); i < SC_NSIZES; i++) {
430 extent = extent_heap_remove_first(&base->avail[i]);
431 if (extent != NULL) {
432 /* Use existing space. */
433 break;
434 }
435 }
436 if (extent == NULL) {
437 /* Try to allocate more space. */
438 extent = base_extent_alloc(tsdn, base, usize, alignment);
439 }
440 void *ret;
441 if (extent == NULL) {
442 ret = NULL;
443 goto label_return;
444 }
445
446 ret = base_extent_bump_alloc(base, extent, usize, alignment);
447 if (esn != NULL) {
448 *esn = extent_sn_get(extent);
449 }
450label_return:
451 malloc_mutex_unlock(tsdn, &base->mtx);
452 return ret;
453}
454
455/*
456 * base_alloc() returns zeroed memory, which is always demand-zeroed for the

Callers 2

base_allocFunction · 0.70
base_alloc_extentFunction · 0.70

Calls 6

base_extent_allocFunction · 0.70
base_extent_bump_allocFunction · 0.70
malloc_mutex_lockFunction · 0.50
sz_size2indexFunction · 0.50
extent_sn_getFunction · 0.50
malloc_mutex_unlockFunction · 0.50

Tested by

no test coverage detected