MINOR: pools: replace DEBUG_MEMORY_POOLS with runtime POOL_DBG_TAG
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.
diff --git a/include/haproxy/pool-t.h b/include/haproxy/pool-t.h
index b68a4ab..6f77bd9 100644
--- a/include/haproxy/pool-t.h
+++ b/include/haproxy/pool-t.h
@@ -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 */
diff --git a/include/haproxy/pool.h b/include/haproxy/pool.h
index b1a0c60..2f5d7b1 100644
--- a/include/haproxy/pool.h
+++ b/include/haproxy/pool.h
@@ -52,13 +52,13 @@
* 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)
@@ -73,19 +75,12 @@
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.
diff --git a/src/pool.c b/src/pool.c
index afe3d51..b85a797 100644
--- a/src/pool.c
+++ b/src/pool.c
@@ -57,6 +57,9 @@
#if defined(DEBUG_POOL_TRACING)
POOL_DBG_CALLER |
#endif
+#if defined(DEBUG_MEMORY_POOLS)
+ POOL_DBG_TAG |
+#endif
0;
static int mem_fail_rate __read_mostly = 0;
@@ -206,7 +209,7 @@
* 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;