From: Willy Tarreau Date: Wed, 23 Feb 2022 09:20:37 +0000 (+0100) Subject: MINOR: pools: replace DEBUG_MEMORY_POOLS with runtime POOL_DBG_TAG X-Git-Tag: v2.6-dev2~74 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=13d7775b068241d4d2aa79ac8c987894fada05e9;p=thirdparty%2Fhaproxy.git 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 b68a4ab4d3..6f77bd9857 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 b1a0c60dd0..2f5d7b1d3d 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 afe3d51204..b85a797a08 100644 --- a/src/pool.c +++ b/src/pool.c @@ -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;