]> git.ipfire.org Git - thirdparty/haproxy.git/commitdiff
CLEANUP: pools: do not use the extra pointer to link shared elements
authorWilly Tarreau <w@1wt.eu>
Fri, 31 Dec 2021 15:00:19 +0000 (16:00 +0100)
committerWilly Tarreau <w@1wt.eu>
Sun, 2 Jan 2022 11:44:19 +0000 (12:44 +0100)
This practice relying on POOL_LINK() dates from the era where there were
no pool caches, but given that the structures are a bit more complex now
and that pool caches do not make use of this feature, it is totally
useless since released elements have already been overwritten, and yet
it complicates the architecture and prevents from making simplifications
and optimizations. Let's just get rid of this feature. The pointer to
the origin pool is preserved though, as it helps detect incorrect frees
and serves as a canary for overflows.

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

index 48d06be151cfb7d68307eea00d7f76de3b0c8ab1..d476f31d4ff8dca9568a6f80d9f5cead5d5541ed 100644 (file)
@@ -40,7 +40,6 @@
 #define POOL_LINK(pool, item) (void **)(((char *)(item)) + ((pool)->size))
 #else
 #define POOL_EXTRA (0)
-#define POOL_LINK(pool, item) ((void **)(item))
 #endif
 
 /* A special pointer for the pool's free_list that indicates someone is
index cb2c8b4de26e31a54d24aa62495b16f1908ccfdd..d8407b19eca2ca7903c1725d124c17d9a9b80cc5 100644 (file)
@@ -132,7 +132,7 @@ static inline void *pool_get_from_shared_cache(struct pool_head *pool)
        }
 
        /* this releases the lock */
-       _HA_ATOMIC_STORE(&pool->free_list, *POOL_LINK(pool, ret));
+       _HA_ATOMIC_STORE(&pool->free_list, *(void **)ret);
        _HA_ATOMIC_INC(&pool->used);
 
 #ifdef DEBUG_MEMORY_POOLS
@@ -164,7 +164,7 @@ static inline void pool_put_to_shared_cache(struct pool_head *pool, void *ptr)
                                __ha_cpu_relax();
                                free_list = _HA_ATOMIC_LOAD(&pool->free_list);
                        }
-                       _HA_ATOMIC_STORE(POOL_LINK(pool, ptr), (void *)free_list);
+                       _HA_ATOMIC_STORE((void **)ptr, (void *)free_list);
                        __ha_barrier_atomic_store();
                } while (!_HA_ATOMIC_CAS(&pool->free_list, &free_list, ptr));
                __ha_barrier_atomic_store();
index e64bfcacf0af0c9316392b9876c8589ccfc75599..7d83a953f9bbb7806f2aacba1da79119800db313 100644 (file)
@@ -417,7 +417,7 @@ void pool_flush(struct pool_head *pool)
 
        while (next) {
                temp = next;
-               next = *POOL_LINK(pool, temp);
+               next = *(void **)temp;
                pool_put_to_os(pool, temp);
        }
        /* here, we should have pool->allocated == pool->used */
@@ -442,7 +442,7 @@ void pool_gc(struct pool_head *pool_ctx)
                while (entry->free_list &&
                       (int)(entry->allocated - entry->used) > (int)entry->minavail) {
                        temp = entry->free_list;
-                       entry->free_list = *POOL_LINK(entry, temp);
+                       entry->free_list = *(void **)temp;
                        pool_put_to_os(entry, temp);
                }
        }