diff --git a/include/jemalloc/internal/pa.h b/include/jemalloc/internal/pa.h index 05841549..ec6c8048 100644 --- a/include/jemalloc/internal/pa.h +++ b/include/jemalloc/internal/pa.h @@ -230,6 +230,18 @@ bool pa_maybe_decay_purge(tsdn_t *tsdn, pa_shard_t *shard, decay_t *decay, pa_shard_decay_stats_t *decay_stats, ecache_t *ecache, pa_decay_purge_setting_t decay_purge_setting); +/* + * Gets / sets the maximum amount that we'll grow an arena down the + * grow-retained pathways (unless forced to by an allocaction request). + * + * Set new_limit to NULL if it's just a query, or old_limit to NULL if you don't + * care about the previous value. + * + * Returns true on error (if the new limit is not valid). + */ +bool pa_shard_retain_grow_limit_get_set(tsdn_t *tsdn, pa_shard_t *shard, + size_t *old_limit, size_t *new_limit); + /******************************************************************************/ /* * Various bits of "boring" functionality that are still part of this module, diff --git a/src/arena.c b/src/arena.c index e96934a5..178cc9a9 100644 --- a/src/arena.c +++ b/src/arena.c @@ -1411,26 +1411,8 @@ bool arena_retain_grow_limit_get_set(tsd_t *tsd, arena_t *arena, size_t *old_limit, size_t *new_limit) { assert(opt_retain); - - pszind_t new_ind JEMALLOC_CC_SILENCE_INIT(0); - if (new_limit != NULL) { - size_t limit = *new_limit; - /* Grow no more than the new limit. */ - if ((new_ind = sz_psz2ind(limit + 1) - 1) >= SC_NPSIZES) { - return true; - } - } - - malloc_mutex_lock(tsd_tsdn(tsd), &arena->pa_shard.ecache_grow.mtx); - if (old_limit != NULL) { - *old_limit = sz_pind2sz(arena->pa_shard.ecache_grow.limit); - } - if (new_limit != NULL) { - arena->pa_shard.ecache_grow.limit = new_ind; - } - malloc_mutex_unlock(tsd_tsdn(tsd), &arena->pa_shard.ecache_grow.mtx); - - return false; + return pa_shard_retain_grow_limit_get_set(tsd_tsdn(tsd), + &arena->pa_shard, old_limit, new_limit); } unsigned diff --git a/src/pa.c b/src/pa.c index a8aee216..d4949f5e 100644 --- a/src/pa.c +++ b/src/pa.c @@ -395,3 +395,27 @@ pa_maybe_decay_purge(tsdn_t *tsdn, pa_shard_t *shard, decay_t *decay, return epoch_advanced; } + +bool +pa_shard_retain_grow_limit_get_set(tsdn_t *tsdn, pa_shard_t *shard, + size_t *old_limit, size_t *new_limit) { + pszind_t new_ind JEMALLOC_CC_SILENCE_INIT(0); + if (new_limit != NULL) { + size_t limit = *new_limit; + /* Grow no more than the new limit. */ + if ((new_ind = sz_psz2ind(limit + 1) - 1) >= SC_NPSIZES) { + return true; + } + } + + malloc_mutex_lock(tsdn, &shard->ecache_grow.mtx); + if (old_limit != NULL) { + *old_limit = sz_pind2sz(shard->ecache_grow.limit); + } + if (new_limit != NULL) { + shard->ecache_grow.limit = new_ind; + } + malloc_mutex_unlock(tsdn, &shard->ecache_grow.mtx); + + return false; +}