From a6982e58687679753137498a6e8de2179a6f7993 Mon Sep 17 00:00:00 2001 From: Willy Tarreau Date: Mon, 1 Jun 2020 17:51:05 +0200 Subject: [PATCH] MINOR: memory: don't let __pool_get_first() pick from the cache When building with the local cache support, we have an asymmetry in the allocation path which is that __pool_get_first() picks from the cache while when no cache support is used, this one directly accesses the shared area. It looks like it was done this way only to centralize the call to __pool_get_from_cache() but this was not a good idea as it complicates the splitting the code. Let's move the cache access to the upper layer so thatt __pool_get_first() remains agnostic to the cache support. The call tree now looks like this with the cache enabled : pool_get_first() __pool_get_from_cache() // if cache enabled __pool_get_first() pool_alloc() pool_alloc_dirty() __pool_get_from_cache() // if cache enabled __pool_get_first() __pool_refill_alloc() __pool_free() pool_free_area() pool_put_to_cache() __pool_free() __pool_put_to_cache() pool_free() pool_put_to_cache() With cache disabled, the pool_free() path still differs: pool_free() __pool_free_area() __pool_put_to_cache() --- include/common/memory.h | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/include/common/memory.h b/include/common/memory.h index cf6df9a88..2eaa6234b 100644 --- a/include/common/memory.h +++ b/include/common/memory.h @@ -160,10 +160,6 @@ static inline void *__pool_get_from_cache(struct pool_head *pool) static inline void *__pool_get_first(struct pool_head *pool) { struct pool_free_list cmp, new; - void *ret = __pool_get_from_cache(pool); - - if (ret) - return ret; cmp.seq = pool->seq; __ha_barrier_load(); @@ -190,6 +186,9 @@ static inline void *pool_get_first(struct pool_head *pool) { void *ret; + if (likely(ret = __pool_get_from_cache(pool))) + return ret; + ret = __pool_get_first(pool); return ret; } @@ -203,6 +202,9 @@ static inline void *pool_alloc_dirty(struct pool_head *pool) { void *p; + if (likely(p = __pool_get_from_cache(pool))) + return p; + if ((p = __pool_get_first(pool)) == NULL) p = __pool_refill_alloc(pool, 0); return p;