From 44529da8525ef811ea8cc7704ffa9910459656ce Mon Sep 17 00:00:00 2001 From: David Goldblatt Date: Sat, 29 Feb 2020 10:48:59 -0800 Subject: [PATCH] Cache-bin: Make flush modifications internal I.e. the tcache code just calls a cache-bin function to finish flush (and move pointers around, etc.). It doesn't directly access the cache-bin's owned memory any more. --- include/jemalloc/internal/cache_bin.h | 18 +++++++++++++++++- src/tcache.c | 8 ++------ 2 files changed, 19 insertions(+), 7 deletions(-) diff --git a/include/jemalloc/internal/cache_bin.h b/include/jemalloc/internal/cache_bin.h index 6895dca2..382883cd 100644 --- a/include/jemalloc/internal/cache_bin.h +++ b/include/jemalloc/internal/cache_bin.h @@ -267,7 +267,7 @@ cache_bin_init_ptr_array_for_fill(cache_bin_t *bin, cache_bin_info_t *info, */ static inline void cache_bin_finish_fill(cache_bin_t *bin, cache_bin_info_t *info, - cache_bin_ptr_array_t *arr, szind_t nfilled) { + cache_bin_ptr_array_t *arr, cache_bin_sz_t nfilled) { assert(cache_bin_ncached_get(bin, info) == 0); if (nfilled < arr->n) { void **empty_position = cache_bin_empty_position_get(bin, info); @@ -285,6 +285,10 @@ cache_bin_init_ptr_array_for_flush(cache_bin_t *bin, cache_bin_info_t *info, || *arr->ptr != NULL); } +/* + * These accessors are used by the flush pathways -- they reverse ordinary flush + * ordering. + */ JEMALLOC_ALWAYS_INLINE void * cache_bin_ptr_array_get(cache_bin_ptr_array_t *arr, cache_bin_sz_t n) { return *(arr->ptr - n); @@ -295,4 +299,16 @@ cache_bin_ptr_array_set(cache_bin_ptr_array_t *arr, cache_bin_sz_t n, void *p) { *(arr->ptr - n) = p; } +static inline void +cache_bin_finish_flush(cache_bin_t *bin, cache_bin_info_t *info, + cache_bin_ptr_array_t *arr, cache_bin_sz_t nflushed) { + unsigned rem = cache_bin_ncached_get(bin, info) - nflushed; + memmove(bin->cur_ptr.ptr + nflushed, bin->cur_ptr.ptr, + rem * sizeof(void *)); + cache_bin_ncached_set(bin, info, rem); + if (bin->cur_ptr.lowbits > bin->low_water_position) { + bin->low_water_position = bin->cur_ptr.lowbits; + } +} + #endif /* JEMALLOC_INTERNAL_CACHE_BIN_H */ diff --git a/src/tcache.c b/src/tcache.c index 3c6d5d76..e7188585 100644 --- a/src/tcache.c +++ b/src/tcache.c @@ -346,12 +346,8 @@ tcache_bin_flush_impl(tsd_t *tsd, tcache_t *tcache, cache_bin_t *tbin, } } - memmove(tbin->cur_ptr.ptr + (ncached - rem), tbin->cur_ptr.ptr, rem * - sizeof(void *)); - cache_bin_ncached_set(tbin, &tcache_bin_info[binind], rem); - if (tbin->cur_ptr.lowbits > tbin->low_water_position) { - tbin->low_water_position = tbin->cur_ptr.lowbits; - } + cache_bin_finish_flush(tbin, &tcache_bin_info[binind], &ptrs, + ncached - rem); } void