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

Function base_alloc_impl

deps/memkind/src/jemalloc/src/base.c:299–332  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

297}
298
299static void *
300base_alloc_impl(tsdn_t *tsdn, base_t *base, size_t size, size_t alignment,
301 size_t *esn) {
302 alignment = QUANTUM_CEILING(alignment);
303 size_t usize = ALIGNMENT_CEILING(size, alignment);
304 size_t asize = usize + alignment - QUANTUM;
305
306 extent_t *extent = NULL;
307 malloc_mutex_lock(tsdn, &base->mtx);
308 for (szind_t i = sz_size2index(asize); i < NSIZES; i++) {
309 extent = extent_heap_remove_first(&base->avail[i]);
310 if (extent != NULL) {
311 /* Use existing space. */
312 break;
313 }
314 }
315 if (extent == NULL) {
316 /* Try to allocate more space. */
317 extent = base_extent_alloc(tsdn, base, usize, alignment);
318 }
319 void *ret;
320 if (extent == NULL) {
321 ret = NULL;
322 goto label_return;
323 }
324
325 ret = base_extent_bump_alloc(tsdn, base, extent, usize, alignment);
326 if (esn != NULL) {
327 *esn = extent_sn_get(extent);
328 }
329label_return:
330 malloc_mutex_unlock(tsdn, &base->mtx);
331 return ret;
332}
333
334/*
335 * 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