]> git.ipfire.org Git - thirdparty/haproxy.git/commitdiff
DEBUG: pools: let's add reverse mapping from cache heads to thread and pool
authorWilly Tarreau <w@1wt.eu>
Wed, 9 Feb 2022 15:33:22 +0000 (16:33 +0100)
committerWilly Tarreau <w@1wt.eu>
Mon, 14 Feb 2022 19:10:43 +0000 (20:10 +0100)
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.

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

index 283cc9ffd263e20d6640d6a78a79d95ddeb3e4b0..a9234dd3c6a97e2621181ae24d0275c9b233d6be 100644 (file)
@@ -45,6 +45,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
index 554d1cbb8a2fd46fd3ac47087eb8a26723dbf912..8d9c17fd5b26e9b369a41e99028d70a651f5ebb5 100644 (file)
@@ -233,6 +233,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
        }
@@ -395,7 +397,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_evict_last_items(pool, ph, CONFIG_HAP_POOL_CLUSTER_SIZE);
        } while (pool_cache_bytes > CONFIG_HAP_POOL_CACHE_SIZE * 7 / 8);
 }