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

Function arena_bin_malloc_hard

deps/jemalloc/src/arena.c:1308–1361  ·  view source on GitHub ↗

Re-fill bin->slabcur, then call arena_slab_reg_alloc(). */

Source from the content-addressed store, hash-verified

1306
1307/* Re-fill bin->slabcur, then call arena_slab_reg_alloc(). */
1308static void *
1309arena_bin_malloc_hard(tsdn_t *tsdn, arena_t *arena, bin_t *bin,
1310 szind_t binind, unsigned binshard) {
1311 const bin_info_t *bin_info;
1312 extent_t *slab;
1313
1314 bin_info = &bin_infos[binind];
1315 if (!arena_is_auto(arena) && bin->slabcur != NULL) {
1316 arena_bin_slabs_full_insert(arena, bin, bin->slabcur);
1317 bin->slabcur = NULL;
1318 }
1319 slab = arena_bin_nonfull_slab_get(tsdn, arena, bin, binind, binshard);
1320 if (bin->slabcur != NULL) {
1321 /*
1322 * Another thread updated slabcur while this one ran without the
1323 * bin lock in arena_bin_nonfull_slab_get().
1324 */
1325 if (extent_nfree_get(bin->slabcur) > 0) {
1326 void *ret = arena_slab_reg_alloc(bin->slabcur,
1327 bin_info);
1328 if (slab != NULL) {
1329 /*
1330 * arena_slab_alloc() may have allocated slab,
1331 * or it may have been pulled from
1332 * slabs_nonfull. Therefore it is unsafe to
1333 * make any assumptions about how slab has
1334 * previously been used, and
1335 * arena_bin_lower_slab() must be called, as if
1336 * a region were just deallocated from the slab.
1337 */
1338 if (extent_nfree_get(slab) == bin_info->nregs) {
1339 arena_dalloc_bin_slab(tsdn, arena, slab,
1340 bin);
1341 } else {
1342 arena_bin_lower_slab(tsdn, arena, slab,
1343 bin);
1344 }
1345 }
1346 return ret;
1347 }
1348
1349 arena_bin_slabs_full_insert(arena, bin, bin->slabcur);
1350 bin->slabcur = NULL;
1351 }
1352
1353 if (slab == NULL) {
1354 return NULL;
1355 }
1356 bin->slabcur = slab;
1357
1358 assert(extent_nfree_get(bin->slabcur) > 0);
1359
1360 return arena_slab_reg_alloc(slab, bin_info);
1361}
1362
1363/* Choose a bin shard and return the locked bin. */
1364bin_t *

Callers 2

arena_tcache_fill_smallFunction · 0.70
arena_malloc_smallFunction · 0.70

Calls 7

arena_slab_reg_allocFunction · 0.70
arena_dalloc_bin_slabFunction · 0.70
arena_bin_lower_slabFunction · 0.70
arena_is_autoFunction · 0.50
extent_nfree_getFunction · 0.50

Tested by

no test coverage detected