diff --git a/include/jemalloc/internal/pa.h b/include/jemalloc/internal/pa.h index 4e73f10f..d3f85142 100644 --- a/include/jemalloc/internal/pa.h +++ b/include/jemalloc/internal/pa.h @@ -19,4 +19,7 @@ struct pa_shard_s { ecache_t ecache_retained; }; +/* Returns true on error. */ +bool pa_shard_init(tsdn_t *tsdn, pa_shard_t *shard, unsigned ind); + #endif /* JEMALLOC_INTERNAL_PA_H */ diff --git a/src/arena.c b/src/arena.c index d9932b13..23f19883 100644 --- a/src/arena.c +++ b/src/arena.c @@ -2027,32 +2027,7 @@ arena_new(tsdn_t *tsdn, unsigned ind, extent_hooks_t *extent_hooks) { goto label_error; } - /* - * Delay coalescing for dirty extents despite the disruptive effect on - * memory layout for best-fit extent allocation, since cached extents - * are likely to be reused soon after deallocation, and the cost of - * merging/splitting extents is non-trivial. - */ - if (ecache_init(tsdn, &arena->pa_shard.ecache_dirty, extent_state_dirty, - ind, true)) { - goto label_error; - } - /* - * Coalesce muzzy extents immediately, because operations on them are in - * the critical path much less often than for dirty extents. - */ - if (ecache_init(tsdn, &arena->pa_shard.ecache_muzzy, extent_state_muzzy, - ind, false)) { - goto label_error; - } - /* - * Coalesce retained extents immediately, in part because they will - * never be evicted (and therefore there's no opportunity for delayed - * coalescing), but also because operations on retained extents are not - * in the critical path. - */ - if (ecache_init(tsdn, &arena->pa_shard.ecache_retained, - extent_state_retained, ind, false)) { + if (pa_shard_init(tsdn, &arena->pa_shard, ind)) { goto label_error; } diff --git a/src/pa.c b/src/pa.c index 3a26b393..620bf768 100644 --- a/src/pa.c +++ b/src/pa.c @@ -1,2 +1,35 @@ #include "jemalloc/internal/jemalloc_preamble.h" #include "jemalloc/internal/jemalloc_internal_includes.h" + +bool +pa_shard_init(tsdn_t *tsdn, pa_shard_t *shard, unsigned ind) { + /* + * Delay coalescing for dirty extents despite the disruptive effect on + * memory layout for best-fit extent allocation, since cached extents + * are likely to be reused soon after deallocation, and the cost of + * merging/splitting extents is non-trivial. + */ + if (ecache_init(tsdn, &shard->ecache_dirty, extent_state_dirty, ind, + /* delay_coalesce */ true)) { + return true; + } + /* + * Coalesce muzzy extents immediately, because operations on them are in + * the critical path much less often than for dirty extents. + */ + if (ecache_init(tsdn, &shard->ecache_muzzy, extent_state_muzzy, ind, + /* delay_coalesce */ false)) { + return true; + } + /* + * Coalesce retained extents immediately, in part because they will + * never be evicted (and therefore there's no opportunity for delayed + * coalescing), but also because operations on retained extents are not + * in the critical path. + */ + if (ecache_init(tsdn, &shard->ecache_retained, extent_state_retained, + ind, /* delay_coalesce */ false)) { + return true; + } + return false; +}