MINOR: pools: add macros to register aligned pools

This adds an alignment argument to create_pool_from_loc() and
completes the existing low-level macros with new ones that expose
the alignment and the new macros permit to specify it. For now
they're not used.
This commit is contained in:
Willy Tarreau 2025-08-05 18:26:37 +02:00
parent eb075d15f6
commit 6ea0e3e2f8
2 changed files with 33 additions and 11 deletions

View File

@ -33,36 +33,52 @@
/* This creates a pool_reg registers a call to create_pool_callback(ptr) with it. /* This creates a pool_reg registers a call to create_pool_callback(ptr) with it.
* Do not use this one, use REGISTER_POOL() instead. * Do not use this one, use REGISTER_POOL() instead.
*/ */
#define __REGISTER_POOL(_line, _ptr, _name, _size) \ #define __REGISTER_POOL(_line, _ptr, _name, _size, _align) \
static struct pool_registration __pool_reg_##_line = { \ static struct pool_registration __pool_reg_##_line = { \
.name = _name, \ .name = _name, \
.file = __FILE__, \ .file = __FILE__, \
.line = __LINE__, \ .line = __LINE__, \
.size = _size, \ .size = _size, \
.flags = MEM_F_STATREG, \ .flags = MEM_F_STATREG, \
.align = 0, \ .align = _align, \
}; \ }; \
INITCALL3(STG_POOL, create_pool_callback, (_ptr), (_name), &__pool_reg_##_line); INITCALL3(STG_POOL, create_pool_callback, (_ptr), (_name), &__pool_reg_##_line);
/* intermediary level for line number resolution, do not use this one, use /* intermediary level for line number resolution, do not use this one, use
* REGISTER_POOL() instead. * REGISTER_POOL() instead.
*/ */
#define _REGISTER_POOL(line, ptr, name, size) \ #define _REGISTER_POOL(line, ptr, name, size, align) \
__REGISTER_POOL(line, ptr, name, size) __REGISTER_POOL(line, ptr, name, size, align)
/* This registers a call to create_pool_callback(ptr) with these args */ /* This registers a call to create_pool_callback(ptr) with these args */
#define REGISTER_POOL(ptr, name, size) \ #define REGISTER_POOL(ptr, name, size) \
_REGISTER_POOL(__LINE__, ptr, name, size) _REGISTER_POOL(__LINE__, ptr, name, size, 0)
/* This macro declares a pool head <ptr> and registers its creation */ /* This macro declares a pool head <ptr> and registers its creation */
#define DECLARE_POOL(ptr, name, size) \ #define DECLARE_POOL(ptr, name, size) \
struct pool_head *(ptr) __read_mostly = NULL; \ struct pool_head *(ptr) __read_mostly = NULL; \
_REGISTER_POOL(__LINE__, &ptr, name, size) _REGISTER_POOL(__LINE__, &ptr, name, size, 0)
/* This macro declares a static pool head <ptr> and registers its creation */ /* This macro declares a static pool head <ptr> and registers its creation */
#define DECLARE_STATIC_POOL(ptr, name, size) \ #define DECLARE_STATIC_POOL(ptr, name, size) \
static struct pool_head *(ptr) __read_mostly; \ static struct pool_head *(ptr) __read_mostly; \
_REGISTER_POOL(__LINE__, &ptr, name, size) _REGISTER_POOL(__LINE__, &ptr, name, size, 0)
/*** below are the aligned pool macros, taking one extra arg for alignment ***/
/* This registers a call to create_pool_callback(ptr) with these args */
#define REGISTER_ALIGNED_POOL(ptr, name, size, align) \
_REGISTER_POOL(__LINE__, ptr, name, size, align)
/* This macro declares an aligned pool head <ptr> and registers its creation */
#define DECLARE_ALIGNED_POOL(ptr, name, size, align) \
struct pool_head *(ptr) __read_mostly = NULL; \
_REGISTER_POOL(__LINE__, &ptr, name, size, align)
/* This macro declares a static aligned pool head <ptr> and registers its creation */
#define DECLARE_STATIC_ALIGNED_POOL(ptr, name, size, align) \
static struct pool_head *(ptr) __read_mostly; \
_REGISTER_POOL(__LINE__, &ptr, name, size, align)
/* By default, free objects are linked by a pointer stored at the beginning of /* 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 * the memory area. When DEBUG_MEMORY_POOLS is set, the allocated area is
@ -143,7 +159,8 @@ unsigned long long pool_total_allocated(void);
unsigned long long pool_total_used(void); unsigned long long pool_total_used(void);
void pool_flush(struct pool_head *pool); void pool_flush(struct pool_head *pool);
void pool_gc(struct pool_head *pool_ctx); void pool_gc(struct pool_head *pool_ctx);
struct pool_head *create_pool_with_loc(const char *name, unsigned int size, unsigned int flags, const char *file, unsigned int line); struct pool_head *create_pool_with_loc(const char *name, unsigned int size, unsigned int align,
unsigned int flags, const char *file, unsigned int line);
struct pool_head *create_pool_from_reg(const char *name, struct pool_registration *reg); struct pool_head *create_pool_from_reg(const char *name, struct pool_registration *reg);
void create_pool_callback(struct pool_head **ptr, char *name, struct pool_registration *reg); void create_pool_callback(struct pool_head **ptr, char *name, struct pool_registration *reg);
void *pool_destroy(struct pool_head *pool); void *pool_destroy(struct pool_head *pool);
@ -153,7 +170,10 @@ void __pool_free(struct pool_head *pool, void *ptr);
void pool_inspect_item(const char *msg, struct pool_head *pool, const void *item, const void *caller, ssize_t ofs); void pool_inspect_item(const char *msg, struct pool_head *pool, const void *item, const void *caller, ssize_t ofs);
#define create_pool(name, size, flags) \ #define create_pool(name, size, flags) \
create_pool_with_loc(name, size, flags, __FILE__, __LINE__) create_pool_with_loc(name, size, 0, flags, __FILE__, __LINE__)
#define create_aligned_pool(name, size, align, flags) \
create_pool_with_loc(name, size, align, flags, __FILE__, __LINE__)
/****************** Thread-local cache management ******************/ /****************** Thread-local cache management ******************/

View File

@ -293,8 +293,10 @@ static int mem_should_fail(const struct pool_head *pool)
* The name must be a stable pointer during all the program's life time. * The name must be a stable pointer during all the program's life time.
* The file and line are passed to store the registration location in the * The file and line are passed to store the registration location in the
* registration struct. Use create_pool() instead which does it for free. * registration struct. Use create_pool() instead which does it for free.
* The alignment will be stored as-is in the registration.
*/ */
struct pool_head *create_pool_with_loc(const char *name, unsigned int size, unsigned int flags, struct pool_head *create_pool_with_loc(const char *name, unsigned int size,
unsigned int align, unsigned int flags,
const char *file, unsigned int line) const char *file, unsigned int line)
{ {
struct pool_registration *reg; struct pool_registration *reg;
@ -309,7 +311,7 @@ struct pool_head *create_pool_with_loc(const char *name, unsigned int size, unsi
reg->line = line; reg->line = line;
reg->size = size; reg->size = size;
reg->flags = flags; reg->flags = flags;
reg->align = 0; reg->align = align;
pool = create_pool_from_reg(name, reg); pool = create_pool_from_reg(name, reg);
if (!pool) if (!pool)