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

Function extents_first_fit_locked

deps/jemalloc/src/extent.c:442–486  ·  view source on GitHub ↗

* Do first-fit extent selection, i.e. select the oldest/lowest extent that is * large enough. */

Source from the content-addressed store, hash-verified

440 * large enough.
441 */
442static extent_t *
443extents_first_fit_locked(tsdn_t *tsdn, arena_t *arena, extents_t *extents,
444 size_t size) {
445 extent_t *ret = NULL;
446
447 pszind_t pind = sz_psz2ind(extent_size_quantize_ceil(size));
448
449 if (!maps_coalesce && !opt_retain) {
450 /*
451 * No split / merge allowed (Windows w/o retain). Try exact fit
452 * only.
453 */
454 return extent_heap_empty(&extents->heaps[pind]) ? NULL :
455 extent_heap_first(&extents->heaps[pind]);
456 }
457
458 for (pszind_t i = (pszind_t)bitmap_ffu(extents->bitmap,
459 &extents_bitmap_info, (size_t)pind);
460 i < SC_NPSIZES + 1;
461 i = (pszind_t)bitmap_ffu(extents->bitmap, &extents_bitmap_info,
462 (size_t)i+1)) {
463 assert(!extent_heap_empty(&extents->heaps[i]));
464 extent_t *extent = extent_heap_first(&extents->heaps[i]);
465 assert(extent_size_get(extent) >= size);
466 /*
467 * In order to reduce fragmentation, avoid reusing and splitting
468 * large extents for much smaller sizes.
469 *
470 * Only do check for dirty extents (delay_coalesce).
471 */
472 if (extents->delay_coalesce &&
473 (sz_pind2sz(i) >> opt_lg_extent_max_active_fit) > size) {
474 break;
475 }
476 if (ret == NULL || extent_snad_comp(extent, ret) < 0) {
477 ret = extent;
478 }
479 if (i == SC_NPSIZES) {
480 break;
481 }
482 assert(i < SC_NPSIZES);
483 }
484
485 return ret;
486}
487
488/*
489 * Do first-fit extent selection, where the selection policy choice is

Callers 1

extents_fit_lockedFunction · 0.70

Calls 6

sz_psz2indFunction · 0.50
bitmap_ffuFunction · 0.50
extent_size_getFunction · 0.50
sz_pind2szFunction · 0.50
extent_snad_compFunction · 0.50

Tested by

no test coverage detected