From b6cfaa4fe2b8d5cb30c1f28ff622d0102a2bf978 Mon Sep 17 00:00:00 2001 From: Slobodan Predolac Date: Fri, 8 May 2026 10:01:00 -0700 Subject: [PATCH] Extract large-cacheable tcache check into tcache_can_cache_large --- include/jemalloc/internal/arena_inlines_b.h | 8 ++------ include/jemalloc/internal/tcache_inlines.h | 7 +++++++ src/arena.c | 4 +--- 3 files changed, 10 insertions(+), 9 deletions(-) diff --git a/include/jemalloc/internal/arena_inlines_b.h b/include/jemalloc/internal/arena_inlines_b.h index 17a92a18..64957c7b 100644 --- a/include/jemalloc/internal/arena_inlines_b.h +++ b/include/jemalloc/internal/arena_inlines_b.h @@ -203,9 +203,7 @@ arena_malloc(tsdn_t *tsdn, arena_t *arena, size_t size, szind_t ind, bool zero, assert(sz_can_use_slab(size)); return tcache_alloc_small(tsdn_tsd(tsdn), arena, tcache, size, ind, zero, slow_path); - } else if (likely(ind < tcache_nbins_get(tcache->tcache_slow) - && !tcache_bin_disabled(ind, &tcache->bins[ind], - tcache->tcache_slow))) { + } else if (likely(tcache_can_cache_large(tcache, ind))) { return tcache_alloc_large(tsdn_tsd(tsdn), arena, tcache, size, ind, zero, slow_path); } @@ -319,9 +317,7 @@ arena_dalloc_large(tsdn_t *tsdn, void *ptr, tcache_t *tcache, szind_t szind, if (unlikely(is_sample_promoted)) { arena_dalloc_promoted(tsdn, ptr, tcache, slow_path); } else { - if (szind < tcache_nbins_get(tcache->tcache_slow) - && !tcache_bin_disabled( - szind, &tcache->bins[szind], tcache->tcache_slow)) { + if (tcache_can_cache_large(tcache, szind)) { tcache_dalloc_large( tsdn_tsd(tsdn), tcache, ptr, szind, slow_path); } else { diff --git a/include/jemalloc/internal/tcache_inlines.h b/include/jemalloc/internal/tcache_inlines.h index a9dba26a..b3ce81bd 100644 --- a/include/jemalloc/internal/tcache_inlines.h +++ b/include/jemalloc/internal/tcache_inlines.h @@ -86,6 +86,13 @@ tcache_bin_disabled(szind_t ind, cache_bin_t *bin, tcache_slow_t *tcache_slow) { return disabled; } +JEMALLOC_ALWAYS_INLINE bool +tcache_can_cache_large(tcache_t *tcache, szind_t ind) { + return ind < tcache_nbins_get(tcache->tcache_slow) + && !tcache_bin_disabled(ind, &tcache->bins[ind], + tcache->tcache_slow); +} + JEMALLOC_ALWAYS_INLINE void * tcache_alloc_small(tsd_t *tsd, arena_t *arena, tcache_t *tcache, size_t size, szind_t binind, bool zero, bool slow_path) { diff --git a/src/arena.c b/src/arena.c index 7c83c465..516791c8 100644 --- a/src/arena.c +++ b/src/arena.c @@ -652,9 +652,7 @@ arena_dalloc_promoted_impl( } szind_t bumped_ind = sz_size2index(bumped_usize); if (bumped_usize >= SC_LARGE_MINCLASS && tcache != NULL - && bumped_ind < TCACHE_NBINS_MAX - && !tcache_bin_disabled( - bumped_ind, &tcache->bins[bumped_ind], tcache->tcache_slow)) { + && tcache_can_cache_large(tcache, bumped_ind)) { tcache_dalloc_large( tsdn_tsd(tsdn), tcache, ptr, bumped_ind, slow_path); } else {