From e2ab215324d7d19e37f4be87beb7a179528a300f Mon Sep 17 00:00:00 2001 From: Dave Watson Date: Thu, 18 Oct 2018 13:13:57 -0700 Subject: [PATCH] refactor tcache_dalloc_small Add a cache_bin_dalloc_easy (to match the alloc_easy function), and use it in tcache_dalloc_small. It will also be used in the new free fastpath. --- include/jemalloc/internal/cache_bin.h | 16 ++++++++++++++-- include/jemalloc/internal/tcache_inlines.h | 7 +++---- 2 files changed, 17 insertions(+), 6 deletions(-) diff --git a/include/jemalloc/internal/cache_bin.h b/include/jemalloc/internal/cache_bin.h index 40d942e5..d14556a3 100644 --- a/include/jemalloc/internal/cache_bin.h +++ b/include/jemalloc/internal/cache_bin.h @@ -90,7 +90,7 @@ cache_bin_alloc_easy(cache_bin_t *bin, bool *success) { bin->ncached--; - /* + /* * Check for both bin->ncached == 0 and ncached < low_water * in a single branch. */ @@ -102,7 +102,7 @@ cache_bin_alloc_easy(cache_bin_t *bin, bool *success) { return NULL; } } - + /* * success (instead of ret) should be checked upon the return of this * function. We avoid checking (ret == NULL) because there is never a @@ -116,4 +116,16 @@ cache_bin_alloc_easy(cache_bin_t *bin, bool *success) { return ret; } +JEMALLOC_ALWAYS_INLINE bool +cache_bin_dalloc_easy(cache_bin_t *bin, cache_bin_info_t *bin_info, void *ptr) { + if (unlikely(bin->ncached == bin_info->ncached_max)) { + return false; + } + assert(bin->ncached < bin_info->ncached_max); + bin->ncached++; + *(bin->avail - bin->ncached) = ptr; + + return true; +} + #endif /* JEMALLOC_INTERNAL_CACHE_BIN_H */ diff --git a/include/jemalloc/internal/tcache_inlines.h b/include/jemalloc/internal/tcache_inlines.h index 7c956468..c2c3ac37 100644 --- a/include/jemalloc/internal/tcache_inlines.h +++ b/include/jemalloc/internal/tcache_inlines.h @@ -175,13 +175,12 @@ tcache_dalloc_small(tsd_t *tsd, tcache_t *tcache, void *ptr, szind_t binind, bin = tcache_small_bin_get(tcache, binind); bin_info = &tcache_bin_info[binind]; - if (unlikely(bin->ncached == bin_info->ncached_max)) { + if (unlikely(!cache_bin_dalloc_easy(bin, bin_info, ptr))) { tcache_bin_flush_small(tsd, tcache, bin, binind, (bin_info->ncached_max >> 1)); + bool ret = cache_bin_dalloc_easy(bin, bin_info, ptr); + assert(ret); } - assert(bin->ncached < bin_info->ncached_max); - bin->ncached++; - *(bin->avail - bin->ncached) = ptr; tcache_event(tsd, tcache); }