Hide bin slab-locality query behind arena_locality_hint

bin_t is an arena implementation detail; tcache should not reach into
it. Extract the slab-address lookup into bin.c as bin_current_slab_addr,
and expose it to tcache only through arena_locality_hint(tsdn, arena,
szind), which composes bin_choose + bin_current_slab_addr.
This commit is contained in:
Slobodan Predolac
2026-05-05 10:00:04 -07:00
parent e286fba00a
commit 3c1c6ae419
6 changed files with 71 additions and 23 deletions

View File

@@ -330,3 +330,16 @@ bin_choose(tsdn_t *tsdn, arena_t *arena, szind_t binind,
}
return arena_get_bin(arena, binind, binshard);
}
void *
bin_current_slab_addr(tsdn_t *tsdn, bin_t *bin) {
malloc_mutex_lock(tsdn, &bin->lock);
edata_t *slab = (bin->slabcur != NULL)
? bin->slabcur
: edata_heap_first(&bin->slabs_nonfull);
assert(slab != NULL || edata_heap_empty(&bin->slabs_nonfull));
void *ret = (slab != NULL) ? edata_addr_get(slab) : NULL;
assert(ret != NULL || slab == NULL);
malloc_mutex_unlock(tsdn, &bin->lock);
return ret;
}