mirror of
https://github.com/jemalloc/jemalloc.git
synced 2026-07-08 14:57:21 +03:00
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:
parent
e286fba00a
commit
3c1c6ae419
6 changed files with 71 additions and 23 deletions
|
|
@ -683,6 +683,48 @@ TEST_BEGIN(test_bin_stats_nrequests_add) {
|
|||
}
|
||||
TEST_END
|
||||
|
||||
/*
|
||||
* Test bin_current_slab_addr returns slabcur first, then falls back to the
|
||||
* first nonfull slab, and NULL when both are empty.
|
||||
*/
|
||||
TEST_BEGIN(test_bin_current_slab_addr) {
|
||||
tsdn_t *tsdn = tsdn_fetch();
|
||||
bin_t bin;
|
||||
szind_t binind = 0;
|
||||
edata_t slab1, slab2;
|
||||
|
||||
bin_init(&bin);
|
||||
|
||||
/* Empty bin: returns NULL. */
|
||||
expect_ptr_null(bin_current_slab_addr(tsdn, &bin),
|
||||
"Empty bin should return NULL");
|
||||
|
||||
create_mock_slab(&slab1, binind, 0);
|
||||
create_mock_slab(&slab2, binind, 1);
|
||||
|
||||
/* Only nonfull set: returns first-of-nonfull addr. */
|
||||
bin_slabs_nonfull_insert(&bin, &slab1);
|
||||
expect_ptr_eq(bin_current_slab_addr(tsdn, &bin),
|
||||
edata_addr_get(&slab1),
|
||||
"Should return nonfull-first addr when slabcur is NULL");
|
||||
|
||||
/* slabcur takes precedence over nonfull. */
|
||||
bin.slabcur = &slab2;
|
||||
expect_ptr_eq(bin_current_slab_addr(tsdn, &bin),
|
||||
edata_addr_get(&slab2),
|
||||
"Should return slabcur addr when set");
|
||||
|
||||
/* Only slabcur set, no nonfull. */
|
||||
bin_slabs_nonfull_remove(&bin, &slab1);
|
||||
expect_ptr_eq(bin_current_slab_addr(tsdn, &bin),
|
||||
edata_addr_get(&slab2),
|
||||
"Should still return slabcur addr after nonfull cleared");
|
||||
|
||||
free(edata_addr_get(&slab1));
|
||||
free(edata_addr_get(&slab2));
|
||||
}
|
||||
TEST_END
|
||||
|
||||
/*
|
||||
* Test bin_shard_sizes_boot and bin_update_shard_size.
|
||||
*/
|
||||
|
|
@ -856,6 +898,7 @@ main(void) {
|
|||
test_bin_lower_slab_inserts_nonfull,
|
||||
test_bin_dalloc_slab_prepare,
|
||||
test_bin_stats_nrequests_add,
|
||||
test_bin_current_slab_addr,
|
||||
test_bin_shard_sizes,
|
||||
test_bin_alloc_free_cycle,
|
||||
test_bin_multi_size_class);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue