]> git.ipfire.org Git - thirdparty/haproxy.git/commitdiff
MEDIUM: pools: change the static pool creation to pass a registration
authorWilly Tarreau <w@1wt.eu>
Tue, 5 Aug 2025 16:59:15 +0000 (18:59 +0200)
committerWilly Tarreau <w@1wt.eu>
Wed, 6 Aug 2025 17:20:30 +0000 (19:20 +0200)
Now we're creating statically allocated registrations instead of
passing all the parameters and allocating them on the fly. Not only
this is simpler to extend (we're limited in number of INITCALL args),
but it also leaves all of these in the data segment where they are
easier to find when debugging.

include/haproxy/pool.h
src/pool.c

index 3c9651e402ca9b584667b8ef005216085df5a93e..2c9e2e75b4c0407efc50f25679a285a140cb2fa8 100644 (file)
 #include <haproxy/pool-t.h>
 #include <haproxy/thread.h>
 
-/* This registers a call to create_pool_callback(ptr, name, size) */
+/* This creates a pool_reg registers a call to create_pool_callback(ptr) with it.
+ * Do not use this one, use REGISTER_POOL() instead.
+ */
+#define __REGISTER_POOL(_line, _ptr, _name, _size)            \
+       static struct pool_registration __pool_reg_##_line = { \
+               .name = _name,                                 \
+               .size = _size,                                 \
+               .flags = MEM_F_STATREG,                        \
+               .align = 0,                                    \
+       };                                                     \
+       INITCALL3(STG_POOL, create_pool_callback, (_ptr), (_name), &__pool_reg_##_line);
+
+/* intermediary level for line number resolution, do not use this one, use
+ * REGISTER_POOL() instead.
+ */
+#define _REGISTER_POOL(line, ptr, name, size)          \
+       __REGISTER_POOL(line, ptr, name, size)
+
+/* This registers a call to create_pool_callback(ptr) with these args */
 #define REGISTER_POOL(ptr, name, size)  \
-       INITCALL3(STG_POOL, create_pool_callback, (ptr), (name), (size))
+       _REGISTER_POOL(__LINE__, ptr, name, size)
 
 /* This macro declares a pool head <ptr> and registers its creation */
 #define DECLARE_POOL(ptr, name, size)   \
        struct pool_head *(ptr) __read_mostly = NULL; \
-       REGISTER_POOL(&ptr, name, size)
+       _REGISTER_POOL(__LINE__, &ptr, name, size)
 
 /* This macro declares a static pool head <ptr> and registers its creation */
 #define DECLARE_STATIC_POOL(ptr, name, size) \
        static struct pool_head *(ptr) __read_mostly; \
-       REGISTER_POOL(&ptr, name, size)
+       _REGISTER_POOL(__LINE__, &ptr, name, size)
 
 /* By default, free objects are linked by a pointer stored at the beginning of
  * the memory area. When DEBUG_MEMORY_POOLS is set, the allocated area is
@@ -125,7 +143,7 @@ void pool_flush(struct pool_head *pool);
 void pool_gc(struct pool_head *pool_ctx);
 struct pool_head *create_pool(const char *name, unsigned int size, unsigned int flags);
 struct pool_head *create_pool_from_reg(const char *name, struct pool_registration *reg);
-void create_pool_callback(struct pool_head **ptr, char *name, unsigned int size);
+void create_pool_callback(struct pool_head **ptr, char *name, struct pool_registration *reg);
 void *pool_destroy(struct pool_head *pool);
 void pool_destroy_all(void);
 void *__pool_alloc(struct pool_head *pool, unsigned int flags);
index 507a52032aa48b280ca5de37372318100bdfed58..67ce7060f324d47597c5267f56b3b833e6a55f2b 100644 (file)
@@ -1536,12 +1536,12 @@ static int cli_io_handler_dump_pools(struct appctx *appctx)
  * resulting pointer into <ptr>. If the allocation fails, it quits with after
  * emitting an error message.
  */
-void create_pool_callback(struct pool_head **ptr, char *name, unsigned int size)
+void create_pool_callback(struct pool_head **ptr, char *name, struct pool_registration *reg)
 {
-       *ptr = create_pool(name, size, MEM_F_SHARED);
+       *ptr = create_pool_from_reg(name, reg);
        if (!*ptr) {
                ha_alert("Failed to allocate pool '%s' of size %u : %s. Aborting.\n",
-                        name, size, strerror(errno));
+                        name, reg->size, strerror(errno));
                exit(1);
        }
 }