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

Function arena_tdata_get_hard

deps/jemalloc/src/jemalloc.c:421–495  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

419}
420
421arena_tdata_t *
422arena_tdata_get_hard(tsd_t *tsd, unsigned ind) {
423 arena_tdata_t *tdata, *arenas_tdata_old;
424 arena_tdata_t *arenas_tdata = tsd_arenas_tdata_get(tsd);
425 unsigned narenas_tdata_old, i;
426 unsigned narenas_tdata = tsd_narenas_tdata_get(tsd);
427 unsigned narenas_actual = narenas_total_get();
428
429 /*
430 * Dissociate old tdata array (and set up for deallocation upon return)
431 * if it's too small.
432 */
433 if (arenas_tdata != NULL && narenas_tdata < narenas_actual) {
434 arenas_tdata_old = arenas_tdata;
435 narenas_tdata_old = narenas_tdata;
436 arenas_tdata = NULL;
437 narenas_tdata = 0;
438 tsd_arenas_tdata_set(tsd, arenas_tdata);
439 tsd_narenas_tdata_set(tsd, narenas_tdata);
440 } else {
441 arenas_tdata_old = NULL;
442 narenas_tdata_old = 0;
443 }
444
445 /* Allocate tdata array if it's missing. */
446 if (arenas_tdata == NULL) {
447 bool *arenas_tdata_bypassp = tsd_arenas_tdata_bypassp_get(tsd);
448 narenas_tdata = (ind < narenas_actual) ? narenas_actual : ind+1;
449
450 if (tsd_nominal(tsd) && !*arenas_tdata_bypassp) {
451 *arenas_tdata_bypassp = true;
452 arenas_tdata = (arena_tdata_t *)a0malloc(
453 sizeof(arena_tdata_t) * narenas_tdata);
454 *arenas_tdata_bypassp = false;
455 }
456 if (arenas_tdata == NULL) {
457 tdata = NULL;
458 goto label_return;
459 }
460 assert(tsd_nominal(tsd) && !*arenas_tdata_bypassp);
461 tsd_arenas_tdata_set(tsd, arenas_tdata);
462 tsd_narenas_tdata_set(tsd, narenas_tdata);
463 }
464
465 /*
466 * Copy to tdata array. It's possible that the actual number of arenas
467 * has increased since narenas_total_get() was called above, but that
468 * causes no correctness issues unless two threads concurrently execute
469 * the arenas.create mallctl, which we trust mallctl synchronization to
470 * prevent.
471 */
472
473 /* Copy/initialize tickers. */
474 for (i = 0; i < narenas_actual; i++) {
475 if (i < narenas_tdata_old) {
476 ticker_copy(&arenas_tdata[i].decay_ticker,
477 &arenas_tdata_old[i].decay_ticker);
478 } else {

Callers 1

arena_tdata_getFunction · 0.50

Calls 6

narenas_total_getFunction · 0.70
a0mallocFunction · 0.70
a0dallocFunction · 0.70
tsd_nominalFunction · 0.50
ticker_copyFunction · 0.50
ticker_initFunction · 0.50

Tested by

no test coverage detected