From 889da687a09579bc78d9978928ebb96cc02cff01 Mon Sep 17 00:00:00 2001 From: Willy Tarreau Date: Wed, 9 Feb 2022 16:33:22 +0100 Subject: [PATCH] DEBUG: pools: let's add reverse mapping from cache heads to thread and pool During global eviction we're visiting nodes from the LRU tail and we determine their pool cache head and their pool. In order to make sure we never mess up, let's add some backwards pointer to the thread number and pool from the pool_cache_head. It's 64-byte aligned anyway so we're not wasting space and it helps for debugging and will prevent memory corruption the earliest possible. (cherry picked from commit 49bb5d4268adaea64490ee20f4d73d94afe6a903) [wt: context adjustment] Signed-off-by: Willy Tarreau --- include/haproxy/pool-t.h | 2 ++ src/pool.c | 6 ++++++ 2 files changed, 8 insertions(+) diff --git a/include/haproxy/pool-t.h b/include/haproxy/pool-t.h index 2ddf800..33e6c82 100644 --- a/include/haproxy/pool-t.h +++ b/include/haproxy/pool-t.h @@ -59,6 +59,8 @@ struct pool_cache_head { struct list list; /* head of objects in this pool */ unsigned int count; /* number of objects in this pool */ + unsigned int tid; /* thread id, for debugging only */ + struct pool_head *pool; /* assigned pool, for debugging only */ #if defined(DEBUG_POOL_INTEGRITY) ulong fill_pattern; /* pattern used to fill the area on free */ #endif diff --git a/src/pool.c b/src/pool.c index 605508d..68dd8ea 100644 --- a/src/pool.c +++ b/src/pool.c @@ -190,6 +190,8 @@ struct pool_head *create_pool(char *name, unsigned int size, unsigned int flags) /* update per-thread pool cache if necessary */ for (thr = 0; thr < MAX_THREADS; thr++) { LIST_INIT(&pool->cache[thr].list); + pool->cache[thr].tid = thr; + pool->cache[thr].pool = pool; } #endif } @@ -311,7 +313,11 @@ void pool_evict_from_local_caches() * oldest in their own pools, thus their next is the pool's head. */ ph = LIST_NEXT(&item->by_pool, struct pool_cache_head *, list); + BUG_ON(ph->tid != tid); + pool = container_of(ph - tid, struct pool_head, cache); + BUG_ON(pool != ph->pool); + pool_check_pattern(ph, item, pool->size); LIST_DELETE(&item->by_pool); LIST_DELETE(&item->by_lru); -- 1.7.10.4