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.
This commit is contained in:
Willy Tarreau 2022-02-23 10:20:37 +01:00
parent 0271822f17
commit 13d7775b06
3 changed files with 11 additions and 12 deletions

View 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 */

View File

@ -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.

View 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;