From 74d36d78efdea846d577dea933e4bb06a18efa10 Mon Sep 17 00:00:00 2001 From: David Goldblatt Date: Wed, 26 Feb 2020 17:23:47 -0800 Subject: [PATCH] Cache bin: Make ncached_max a query on the info_t. --- include/jemalloc/internal/cache_bin.h | 10 +++++----- include/jemalloc/internal/tcache_inlines.h | 8 ++++---- src/arena.c | 4 ++-- src/tcache.c | 5 +++-- test/unit/cache_bin.c | 4 ++-- 5 files changed, 16 insertions(+), 15 deletions(-) diff --git a/include/jemalloc/internal/cache_bin.h b/include/jemalloc/internal/cache_bin.h index 23092040..3f0524ea 100644 --- a/include/jemalloc/internal/cache_bin.h +++ b/include/jemalloc/internal/cache_bin.h @@ -114,15 +114,15 @@ struct cache_bin_array_descriptor_s { /* Returns ncached_max: Upper limit on ncached. */ static inline cache_bin_sz_t -cache_bin_ncached_max_get(szind_t ind, cache_bin_info_t *infos) { - return infos[ind].stack_size / sizeof(void *); +cache_bin_info_ncached_max(cache_bin_info_t *info) { + return info->stack_size / sizeof(void *); } static inline cache_bin_sz_t cache_bin_ncached_get(cache_bin_t *bin, szind_t ind, cache_bin_info_t *infos) { cache_bin_sz_t n = (cache_bin_sz_t)((infos[ind].stack_size + bin->full_position - bin->cur_ptr.lowbits) / sizeof(void *)); - assert(n <= cache_bin_ncached_max_get(ind, infos)); + assert(n <= cache_bin_info_ncached_max(&infos[ind])); assert(n == 0 || *(bin->cur_ptr.ptr) != NULL); return n; @@ -148,7 +148,7 @@ cache_bin_empty_position_get(cache_bin_t *bin, szind_t ind, static inline cache_bin_sz_t cache_bin_low_water_get(cache_bin_t *bin, szind_t ind, cache_bin_info_t *infos) { - cache_bin_sz_t ncached_max = cache_bin_ncached_max_get(ind, infos); + cache_bin_sz_t ncached_max = cache_bin_info_ncached_max(&infos[ind]); cache_bin_sz_t low_water = ncached_max - (cache_bin_sz_t)((bin->low_water_position - bin->full_position) / sizeof(void *)); @@ -164,7 +164,7 @@ cache_bin_ncached_set(cache_bin_t *bin, szind_t ind, cache_bin_sz_t n, cache_bin_info_t *infos) { bin->cur_ptr.lowbits = bin->full_position + infos[ind].stack_size - n * sizeof(void *); - assert(n <= cache_bin_ncached_max_get(ind, infos)); + assert(n <= cache_bin_info_ncached_max(&infos[ind])); assert(n == 0 || *bin->cur_ptr.ptr != NULL); } diff --git a/include/jemalloc/internal/tcache_inlines.h b/include/jemalloc/internal/tcache_inlines.h index dc6da949..28d6e3c8 100644 --- a/include/jemalloc/internal/tcache_inlines.h +++ b/include/jemalloc/internal/tcache_inlines.h @@ -129,8 +129,8 @@ tcache_dalloc_small(tsd_t *tsd, tcache_t *tcache, void *ptr, szind_t binind, bin = tcache_small_bin_get(tcache, binind); if (unlikely(!cache_bin_dalloc_easy(bin, ptr))) { - unsigned remain = cache_bin_ncached_max_get(binind, - tcache_bin_info) >> 1; + unsigned remain = cache_bin_info_ncached_max( + &tcache_bin_info[binind]) >> 1; tcache_bin_flush_small(tsd, tcache, bin, binind, remain); bool ret = cache_bin_dalloc_easy(bin, ptr); assert(ret); @@ -148,8 +148,8 @@ tcache_dalloc_large(tsd_t *tsd, tcache_t *tcache, void *ptr, szind_t binind, bin = tcache_large_bin_get(tcache, binind); if (unlikely(!cache_bin_dalloc_easy(bin, ptr))) { - unsigned remain = cache_bin_ncached_max_get(binind, - tcache_bin_info) >> 1; + unsigned remain = cache_bin_info_ncached_max( + &tcache_bin_info[binind]) >> 1; tcache_bin_flush_large(tsd, tcache, bin, binind, remain); bool ret = cache_bin_dalloc_easy(bin, ptr); assert(ret); diff --git a/src/arena.c b/src/arena.c index 5ca884b7..2f8a03c0 100644 --- a/src/arena.c +++ b/src/arena.c @@ -1325,8 +1325,8 @@ arena_tcache_fill_small(tsdn_t *tsdn, arena_t *arena, tcache_t *tcache, tcache->bin_refilled[binind] = true; const bin_info_t *bin_info = &bin_infos[binind]; - const unsigned nfill = cache_bin_ncached_max_get(binind, - tcache_bin_info) >> tcache->lg_fill_div[binind]; + const unsigned nfill = cache_bin_info_ncached_max( + &tcache_bin_info[binind]) >> tcache->lg_fill_div[binind]; void **empty_position = cache_bin_empty_position_get(tbin, binind, tcache_bin_info); diff --git a/src/tcache.c b/src/tcache.c index 4096b05a..d2442ef5 100644 --- a/src/tcache.c +++ b/src/tcache.c @@ -75,8 +75,9 @@ tcache_event_hard(tsd_t *tsd, tcache_t *tcache) { * Reduce fill count by 2X. Limit lg_fill_div such that * the fill count is always at least 1. */ - if ((cache_bin_ncached_max_get(binind, tcache_bin_info) - >> (tcache->lg_fill_div[binind] + 1)) >= 1) { + if ((cache_bin_info_ncached_max( + &tcache_bin_info[binind]) >> + (tcache->lg_fill_div[binind] + 1)) >= 1) { tcache->lg_fill_div[binind]++; } } else { diff --git a/test/unit/cache_bin.c b/test/unit/cache_bin.c index 5ef108d0..ab36a3a1 100644 --- a/test/unit/cache_bin.c +++ b/test/unit/cache_bin.c @@ -10,8 +10,8 @@ TEST_BEGIN(test_cache_bin) { expect_ptr_not_null(stack, "Unexpected mallocx failure"); /* Initialize to empty; bin 0. */ - cache_bin_sz_t ncached_max = cache_bin_ncached_max_get(0, - tcache_bin_info); + cache_bin_sz_t ncached_max = cache_bin_info_ncached_max( + &tcache_bin_info[0]); void **empty_position = stack + ncached_max; bin->cur_ptr.ptr = empty_position; bin->low_water_position = bin->cur_ptr.lowbits;