]> git.ipfire.org Git - thirdparty/haproxy.git/commitdiff
MINOR: pools: get rid of POOL_EXTRA
authorWilly Tarreau <w@1wt.eu>
Wed, 23 Feb 2022 09:03:11 +0000 (10:03 +0100)
committerWilly Tarreau <w@1wt.eu>
Wed, 23 Feb 2022 16:11:33 +0000 (17:11 +0100)
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
src/pool.c

index 90d928aded527214b6937e342e68d14eb4573679..05511a1a25828c5ad4c130557782113969ee7f0d 100644 (file)
 
 #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;
 
index f203397b06dbb313d076450fd1d86eb46d425499..0fb3f08b49780c1c23908bd293359d8ef6868247 100644 (file)
@@ -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);