]> git.ipfire.org Git - thirdparty/haproxy.git/commitdiff
MINOR: pools: replace DEBUG_MEMORY_POOLS with runtime POOL_DBG_TAG
authorWilly Tarreau <w@1wt.eu>
Wed, 23 Feb 2022 09:20:37 +0000 (10:20 +0100)
committerWilly Tarreau <w@1wt.eu>
Wed, 23 Feb 2022 16:11:33 +0000 (17:11 +0100)
This option used to allow to store a marker at the end of the area, which
was used as a canary and detection against wrong freeing while the object
is used, and as a pointer to the last pool_free() caller when back in cache.
Now that we can compute the offsets at runtime, let's check it at run time
and continue the code simplification.

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

index b68a4ab4d34c48ddc5b6997ac236265d7bde8276..6f77bd985781af2b3803f4aa4487fbab5831b6dd 100644 (file)
@@ -48,6 +48,7 @@
 #define POOL_DBG_NO_GLOBAL  0x00000010  // disable global pools
 #define POOL_DBG_NO_CACHE   0x00000020  // disable thread-local pool caches
 #define POOL_DBG_CALLER     0x00000040  // trace last caller's location
+#define POOL_DBG_TAG        0x00000080  // place a tag at the end of the area
 
 
 /* This is the head of a thread-local cache */
index b1a0c60dd0b2146429f8c378fe54e219565c5315..2f5d7b1d3d6e0772436174284ad0249b7c72e5c8 100644 (file)
  * this location is used to keep a pointer to the pool the object was
  * allocated from, and verify it's freed into the appropriate one.
  */
-#ifdef DEBUG_MEMORY_POOLS
-
 # define POOL_EXTRA_MARK (sizeof(void *))
 # define POOL_DEBUG_SET_MARK(pool, item)                               \
        do {                                                            \
                typeof(pool) __p = (pool);                              \
                typeof(item) __i = (item);                              \
+               if (likely(!(pool_debugging & POOL_DBG_TAG)))           \
+                       break;                                          \
                *(typeof(pool)*)(((char *)__i) + __p->size) = __p;      \
        } while (0)
 
@@ -66,6 +66,8 @@
        do {                                                            \
                typeof(pool) __p = (pool);                              \
                typeof(item) __i = (item);                              \
+               if (likely(!(pool_debugging & POOL_DBG_TAG)))           \
+                       break;                                          \
                *(typeof(pool)*)(((char *)__i) + __p->size) = __builtin_return_address(0); \
        } while (0)
 
        do {                                                            \
                typeof(pool) __p = (pool);                              \
                typeof(item) __i = (item);                              \
+               if (likely(!(pool_debugging & POOL_DBG_TAG)))           \
+                       break;                                          \
                if (*(typeof(pool)*)(((char *)__i) + __p->size) != __p) \
                        ABORT_NOW();                                    \
        } while (0)
 
-#else // DEBUG_MEMORY_POOLS
-
-# define POOL_EXTRA_MARK (0)
-# define POOL_DEBUG_SET_MARK(pool, item)   do { } while (0)
-# define POOL_DEBUG_RESET_MARK(pool, item) do { } while (0)
-# define POOL_DEBUG_CHECK_MARK(pool, item) do { } while (0)
-
-#endif // DEBUG_MEMORY_POOLS
-
 /* It's possible to trace callers of pool_free() by placing their pointer
  * after the end of the area and the optional mark above, which means the
  * end of the allocated array.
index afe3d512043cb30ba98d943e74ddf906d739beca..b85a797a08fea937924f06b1944f372b9795542c 100644 (file)
@@ -56,6 +56,9 @@ uint pool_debugging __read_mostly =               /* set of POOL_DBG_* flags */
 #endif
 #if defined(DEBUG_POOL_TRACING)
        POOL_DBG_CALLER     |
+#endif
+#if defined(DEBUG_MEMORY_POOLS)
+       POOL_DBG_TAG        |
 #endif
        0;
 
@@ -206,7 +209,7 @@ 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_mark = (pool_debugging & POOL_DBG_TAG) ? POOL_EXTRA_MARK : 0;
        extra_caller = (pool_debugging & POOL_DBG_CALLER) ? POOL_EXTRA_CALLER : 0;
        extra = extra_mark + extra_caller;