From: Willy Tarreau Date: Thu, 15 Apr 2021 17:38:42 +0000 (+0200) Subject: MINOR: pools: call pool_alloc_nocache() out of the pool's lock X-Git-Tag: v2.4-dev17~73 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=8ee9df57db622d518713c68cf7345794ed744330;p=thirdparty%2Fhaproxy.git MINOR: pools: call pool_alloc_nocache() out of the pool's lock In __pool_alloc(), historically we used to use factor out the pool's lock between __pool_get_first() and __pool_refill_alloc(), resulting in real malloc() or mmap() calls being performed under the pool lock (for platforms using the locked shared pools). As this is not needed anymore, let's move the call out of the lock, it may improve allocation patterns on some platforms. This also makes __pool_alloc() cleaner as we see a first attempt to allocate from the local cache, then a second from the shared cache then a reall allocation. --- diff --git a/include/haproxy/pool.h b/include/haproxy/pool.h index a62a93b39e..876668763f 100644 --- a/include/haproxy/pool.h +++ b/include/haproxy/pool.h @@ -277,11 +277,12 @@ static inline void *__pool_alloc(struct pool_head *pool, unsigned int flags) #if !defined(CONFIG_HAP_LOCKLESS_POOLS) && !defined(CONFIG_HAP_NO_GLOBAL_POOLS) HA_SPIN_LOCK(POOL_LOCK, &pool->lock); #endif - if ((p = __pool_get_first(pool)) == NULL) - p = pool_alloc_nocache(pool); + p = __pool_get_first(pool); #if !defined(CONFIG_HAP_LOCKLESS_POOLS) && !defined(CONFIG_HAP_NO_GLOBAL_POOLS) HA_SPIN_UNLOCK(POOL_LOCK, &pool->lock); #endif + if (!p) + p = pool_alloc_nocache(pool); ret: if (p) { if (flags & POOL_F_MUST_ZERO)