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).
This commit is contained in:
Willy Tarreau 2021-03-22 20:54:15 +01:00
parent a213b683f7
commit de749a9333
3 changed files with 18 additions and 15 deletions

View File

@ -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;

View File

@ -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 */

View File

@ -286,16 +286,16 @@ static inline void __pool_free(struct pool_head *pool, void *ptr)
/*
* Returns a pointer to type <type> taken from the pool <pool_type> or
* dynamically allocated. In the first case, <pool_type> 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. <flags> 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 <type> taken from the pool <pool_type> or
* dynamically allocated. In the first case, <pool_type> 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);
}
/*