]> git.ipfire.org Git - thirdparty/haproxy.git/commitdiff
MINOR: pool/debug: create a new pool_alloc_flag() macro
authorWilly Tarreau <w@1wt.eu>
Wed, 16 Nov 2022 10:30:04 +0000 (11:30 +0100)
committerWilly Tarreau <w@1wt.eu>
Wed, 16 Nov 2022 10:44:26 +0000 (11:44 +0100)
This macro just serves as an intermediary for __pool_alloc() and forwards
the flag. When DEBUG_MEM_STATS is set, it will be used to collect all
pool allocations including those which need to pass an explicit flag.

It's now used by b_alloc() which previously couldn't be tracked by
DEBUG_MEM_STATS, causing some free() calls to have no corresponding
allocations.

include/haproxy/dynbuf.h
include/haproxy/pool.h

index 5e8ece2f7697bc080dada3d1dac6d95ad71ee667..45bd4cf8c46fed955e8413856a07b4021f24b44b 100644 (file)
@@ -68,7 +68,7 @@ static inline struct buffer *b_alloc(struct buffer *buf)
                return buf;
 
        *buf = BUF_WANTED;
-       area = __pool_alloc(pool_head_buffer, POOL_F_NO_POISON);
+       area = pool_alloc_flag(pool_head_buffer, POOL_F_NO_POISON);
        if (unlikely(!area)) {
                activity[tid].buf_wait++;
                return NULL;
index 8fd14b9662cd0ef17b9d52a1ffc0af2325036906..b6aa372f4ce43393a417a82ec2466440c7cb2038 100644 (file)
@@ -226,6 +226,12 @@ static inline void *pool_get_from_cache(struct pool_head *pool, const void *call
 
 #if !defined(DEBUG_MEM_STATS)
 
+/*
+ * Returns a pointer to an object from pool <pool> allocated using
+ * flags <flag> from the POOL_F_* set.
+ */
+#define pool_alloc_flag(pool, flag)  __pool_alloc((pool), (flag))
+
 /*
  * Returns a pointer to type <type> taken from the pool <pool_type> or
  * dynamically allocated. Memory poisonning is performed if enabled.
@@ -272,8 +278,9 @@ static inline void *pool_get_from_cache(struct pool_head *pool, const void *call
        }                                                               \
 })
 
-#define pool_alloc(pool)  ({                                           \
+#define pool_alloc_flag(pool, flag)  ({                                        \
        struct pool_head *__pool = (pool);                              \
+       uint __flag = (flag);                                           \
        size_t __x = __pool->size;                                      \
        static struct mem_stats _ __attribute__((used,__section__("mem_stats"),__aligned__(sizeof(void*)))) = { \
                .caller = {                                             \
@@ -287,26 +294,12 @@ static inline void *pool_get_from_cache(struct pool_head *pool, const void *call
        HA_WEAK(__stop_mem_stats);                                      \
        _HA_ATOMIC_INC(&_.calls);                                       \
        _HA_ATOMIC_ADD(&_.size, __x);                                   \
-       __pool_alloc(__pool, 0);                                        \
+       __pool_alloc(__pool, __flag);                                   \
 })
 
-#define pool_zalloc(pool)  ({                                          \
-       struct pool_head *__pool = (pool);                              \
-       size_t __x = __pool->size;                                      \
-       static struct mem_stats _ __attribute__((used,__section__("mem_stats"),__aligned__(sizeof(void*)))) = { \
-               .caller = {                                             \
-                       .file = __FILE__, .line = __LINE__,             \
-                       .what = MEM_STATS_TYPE_P_ALLOC,                 \
-                       .func = __func__,                               \
-               },                                                      \
-       };                                                              \
-       _.extra = __pool;                                               \
-       HA_WEAK(__start_mem_stats);                                     \
-       HA_WEAK(__stop_mem_stats);                                      \
-       _HA_ATOMIC_INC(&_.calls);                                       \
-       _HA_ATOMIC_ADD(&_.size, __x);                                   \
-       __pool_alloc(__pool, POOL_F_MUST_ZERO);                         \
-})
+#define pool_alloc(pool) pool_alloc_flag(pool, 0)
+
+#define pool_zalloc(pool) pool_alloc_flag(pool, POOL_F_MUST_ZERO)
 
 #endif /* DEBUG_MEM_STATS */