From: Willy Tarreau Date: Mon, 22 Mar 2021 19:54:15 +0000 (+0100) Subject: MINOR: pools: make the pool allocator support a few flags X-Git-Tag: v2.4-dev14~59 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=de749a93337588b2211bf9465c948be95d0bda75;p=thirdparty%2Fhaproxy.git MINOR: pools: make the pool allocator support a few flags The pool_alloc_dirty() function was renamed to __pool_alloc() and now takes a set of flags indicating whether poisonning is permitted or not and whether zeroing the area is needed or not. The pool_alloc() function is now just a wrapper calling __pool_alloc(pool, 0). --- diff --git a/include/haproxy/dynbuf.h b/include/haproxy/dynbuf.h index 2a9051546d..d3377549e1 100644 --- a/include/haproxy/dynbuf.h +++ b/include/haproxy/dynbuf.h @@ -68,7 +68,7 @@ static inline struct buffer *b_alloc(struct buffer *buf) return buf; *buf = BUF_WANTED; - area = pool_alloc_dirty(pool_head_buffer); + area = __pool_alloc(pool_head_buffer, POOL_F_NO_POISON); if (unlikely(!area)) { activity[tid].buf_wait++; return NULL; diff --git a/include/haproxy/pool-t.h b/include/haproxy/pool-t.h index f1cba044eb..bc54c2d3e1 100644 --- a/include/haproxy/pool-t.h +++ b/include/haproxy/pool-t.h @@ -81,6 +81,10 @@ #define POOL_AVG_SAMPLES 1024 +/* possible flags for __pool_alloc() */ +#define POOL_F_NO_POISON 0x00000001 // do not poison the area +#define POOL_F_MUST_ZERO 0x00000002 // zero the returned area + struct pool_cache_head { struct list list; /* head of objects in this pool */ diff --git a/include/haproxy/pool.h b/include/haproxy/pool.h index abaa087e73..b37fb9d3e1 100644 --- a/include/haproxy/pool.h +++ b/include/haproxy/pool.h @@ -286,16 +286,16 @@ static inline void __pool_free(struct pool_head *pool, void *ptr) /* * Returns a pointer to type taken from the pool or * dynamically allocated. In the first case, is updated to point to - * the next element in the list. No memory poisonning is ever performed on the - * returned area. + * the next element in the list. is a binary-OR of POOL_F_* flags. + * Prefer using pool_alloc() which does the right thing without flags. */ -static inline void *pool_alloc_dirty(struct pool_head *pool) +static inline void *__pool_alloc(struct pool_head *pool, unsigned int flags) { void *p; #ifdef CONFIG_HAP_LOCAL_POOLS if (likely(p = __pool_get_from_cache(pool))) - return p; + goto ret; #endif #if !defined(CONFIG_HAP_LOCKLESS_POOLS) && !defined(CONFIG_HAP_NO_GLOBAL_POOLS) @@ -306,24 +306,23 @@ static inline void *pool_alloc_dirty(struct pool_head *pool) #if !defined(CONFIG_HAP_LOCKLESS_POOLS) && !defined(CONFIG_HAP_NO_GLOBAL_POOLS) HA_SPIN_UNLOCK(POOL_LOCK, &pool->lock); #endif + ret: + if (p) { + if (flags & POOL_F_MUST_ZERO) + memset(p, 0, pool->size); + else if (!(flags & POOL_F_NO_POISON) && mem_poison_byte >= 0) + memset(p, mem_poison_byte, pool->size); + } return p; } /* * Returns a pointer to type taken from the pool or - * dynamically allocated. In the first case, is updated to point to - * the next element in the list. Memory poisonning is performed if enabled. + * dynamically allocated. Memory poisonning is performed if enabled. */ static inline void *pool_alloc(struct pool_head *pool) { - void *p; - - p = pool_alloc_dirty(pool); - if (p && mem_poison_byte >= 0) { - memset(p, mem_poison_byte, pool->size); - } - - return p; + return __pool_alloc(pool, 0); } /*