]> git.ipfire.org Git - thirdparty/haproxy.git/commitdiff
MINOR: pools: add a new debugging flag POOL_DBG_COLD_FIRST
authorWilly Tarreau <w@1wt.eu>
Mon, 21 Feb 2022 17:30:25 +0000 (18:30 +0100)
committerWilly Tarreau <w@1wt.eu>
Wed, 23 Feb 2022 16:11:33 +0000 (17:11 +0100)
When enabling pools integrity checks, we usually prefer to allocate cold
objects first in order to maximize the time the objects spend in the
cache. In order to make this configurable at runtime, let's introduce
a new debugging flag to control this allocation order. It is currently
preset by the DEBUG_POOL_INTEGRITY build-time setting.

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

index 37980c6290b7cd95038db080598f676dd374c7f2..a1a9f653066bbbfbaba2b3679bc504bfd4a719ca 100644 (file)
@@ -43,6 +43,7 @@
 /* pool debugging flags */
 #define POOL_DBG_FAIL_ALLOC 0x00000001  // randomly fail memory allocations
 #define POOL_DBG_DONT_MERGE 0x00000002  // do not merge same-size pools
+#define POOL_DBG_COLD_FIRST 0x00000004  // pick cold objects first
 
 
 /* This is the head of a thread-local cache */
index 541e0d96bfe9c8e4b4278d07026f9be962f2cb66..1d224241b97d078e8ad43f7647955cff2b5c998a 100644 (file)
@@ -275,16 +275,18 @@ static inline void *pool_get_from_cache(struct pool_head *pool, const void *call
                        return NULL;
        }
 
+       if (unlikely(pool_debugging & POOL_DBG_COLD_FIRST)) {
+               /* allocate oldest objects first so as to keep them as long as possible
+                * in the cache before being reused and maximizing the chance to detect
+                * an overwrite.
+                */
+               item = LIST_PREV(&ph->list, typeof(item), by_pool);
+       } else {
+               /* allocate hottest objects first */
+               item = LIST_NEXT(&ph->list, typeof(item), by_pool);
+       }
 #if defined(DEBUG_POOL_INTEGRITY)
-       /* allocate oldest objects first so as to keep them as long as possible
-        * in the cache before being reused and maximizing the chance to detect
-        * an overwrite.
-        */
-       item = LIST_PREV(&ph->list, typeof(item), by_pool);
        pool_check_pattern(ph, item, pool->size);
-#else
-       /* allocate hottest objects first */
-       item = LIST_NEXT(&ph->list, typeof(item), by_pool);
 #endif
        BUG_ON(&item->by_pool == &ph->list);
        LIST_DELETE(&item->by_pool);
index 7f9c3df5a191a3c4c0a8be7e28c9f22b14cf69fc..87ab4b65de16919d4f4c11a4bd02ad9180fa2b39 100644 (file)
@@ -43,6 +43,9 @@ uint pool_debugging __read_mostly =               /* set of POOL_DBG_* flags */
 #endif
 #ifdef DEBUG_DONT_SHARE_POOLS
        POOL_DBG_DONT_MERGE |
+#endif
+#ifdef DEBUG_POOL_INTEGRITY
+       POOL_DBG_COLD_FIRST |
 #endif
        0;