From 42705d06b71afdd9418675ab895ec1f109d530af Mon Sep 17 00:00:00 2001 From: Willy Tarreau Date: Wed, 23 Feb 2022 10:03:11 +0100 Subject: [PATCH] MINOR: pools: get rid of POOL_EXTRA This macro is build-time dependent and is almost unused, yet where it cannot easily be avoided. Now that we store the distinction between pool->size and pool->alloc_sz, we don't need to maintain it and we can instead compute it on the fly when creating a pool. This is what this patch does. The variables are for now pretty static, but this is sufficient to kill the macro and will allow to set them more dynamically. --- include/haproxy/pool.h | 2 -- src/pool.c | 13 +++++++++---- 2 files changed, 9 insertions(+), 6 deletions(-) diff --git a/include/haproxy/pool.h b/include/haproxy/pool.h index 90d928ade..05511a1a2 100644 --- a/include/haproxy/pool.h +++ b/include/haproxy/pool.h @@ -107,8 +107,6 @@ #endif -# define POOL_EXTRA (POOL_EXTRA_MARK + POOL_EXTRA_CALLER) - /* poison each newly allocated area with this byte if >= 0 */ extern int mem_poison_byte; diff --git a/src/pool.c b/src/pool.c index f203397b0..0fb3f08b4 100644 --- a/src/pool.c +++ b/src/pool.c @@ -186,6 +186,7 @@ static int mem_should_fail(const struct pool_head *pool) */ struct pool_head *create_pool(char *name, unsigned int size, unsigned int flags) { + unsigned int extra_mark, extra_caller, extra; struct pool_head *pool; struct pool_head *entry; struct list *start; @@ -202,9 +203,13 @@ struct pool_head *create_pool(char *name, unsigned int size, unsigned int flags) * Note: for the LRU cache, we need to store 2 doubly-linked lists. */ + extra_mark = POOL_EXTRA_MARK; + extra_caller = POOL_EXTRA_CALLER; + extra = extra_mark + extra_caller; + if (!(flags & MEM_F_EXACT)) { align = 4 * sizeof(void *); // 2 lists = 4 pointers min - size = ((size + POOL_EXTRA + align - 1) & -align) - POOL_EXTRA; + size = ((size + extra + align - 1) & -align) - extra; } if (!(pool_debugging & POOL_DBG_NO_CACHE)) { @@ -213,8 +218,8 @@ struct pool_head *create_pool(char *name, unsigned int size, unsigned int flags) * the only EXTRA part is in fact the one that's stored in the cache * in addition to the pci struct. */ - if (size + POOL_EXTRA - POOL_EXTRA_CALLER < sizeof(struct pool_cache_item)) - size = sizeof(struct pool_cache_item) + POOL_EXTRA_CALLER - POOL_EXTRA; + if (size + extra - extra_caller < sizeof(struct pool_cache_item)) + size = sizeof(struct pool_cache_item) + extra_caller - extra; } /* TODO: thread: we do not lock pool list for now because all pools are @@ -252,7 +257,7 @@ struct pool_head *create_pool(char *name, unsigned int size, unsigned int flags) return NULL; if (name) strlcpy2(pool->name, name, sizeof(pool->name)); - pool->alloc_sz = size + POOL_EXTRA; + pool->alloc_sz = size + extra; pool->size = size; pool->flags = flags; LIST_APPEND(start, &pool->list);