From 0e2a5b4b61fa91b67e67631b8ae75295f22d0bee Mon Sep 17 00:00:00 2001 From: Willy Tarreau Date: Mon, 24 Jan 2022 15:51:50 +0100 Subject: [PATCH] MINOR: pools: extend pool_cache API to pass a pointer to a caller This adds a caller to pool_put_to_cache() and pool_get_from_cache() which will optionally be used to pass a pointer to their callers. For now it's not used, only the API is extended to support this pointer. --- include/haproxy/pool.h | 8 ++++---- src/pool.c | 9 ++++++--- 2 files changed, 10 insertions(+), 7 deletions(-) diff --git a/include/haproxy/pool.h b/include/haproxy/pool.h index e7b077a99..a79eb284b 100644 --- a/include/haproxy/pool.h +++ b/include/haproxy/pool.h @@ -112,7 +112,7 @@ extern THREAD_LOCAL size_t pool_cache_count; /* #cache objects */ void pool_evict_from_local_cache(struct pool_head *pool); void pool_evict_from_local_caches(void); -void pool_put_to_cache(struct pool_head *pool, void *ptr); +void pool_put_to_cache(struct pool_head *pool, void *ptr, const void *caller); #if defined(CONFIG_HAP_NO_GLOBAL_POOLS) @@ -246,7 +246,7 @@ static inline void pool_check_pattern(struct pool_cache_head *pch, struct pool_c * . If none is available, tries to allocate from the shared cache, and * returns NULL if nothing is available. */ -static inline void *pool_get_from_cache(struct pool_head *pool) +static inline void *pool_get_from_cache(struct pool_head *pool, const void *caller) { struct pool_cache_item *item; struct pool_cache_head *ph; @@ -286,12 +286,12 @@ static inline void *pool_get_from_cache(struct pool_head *pool) /* no cache pools implementation */ -static inline void *pool_get_from_cache(struct pool_head *pool) +static inline void *pool_get_from_cache(struct pool_head *pool, const void *caller) { return NULL; } -static inline void pool_put_to_cache(struct pool_head *pool, void *ptr) +static inline void pool_put_to_cache(struct pool_head *pool, void *ptr, const void *caller) { pool_free_nocache(pool, ptr); } diff --git a/src/pool.c b/src/pool.c index f569897c9..4b12d7c91 100644 --- a/src/pool.c +++ b/src/pool.c @@ -392,7 +392,7 @@ void pool_evict_from_local_caches() * While it is unspecified what the object becomes past this point, it is * guaranteed to be released from the users' perpective. */ -void pool_put_to_cache(struct pool_head *pool, void *ptr) +void pool_put_to_cache(struct pool_head *pool, void *ptr, const void *caller) { struct pool_cache_item *item = (struct pool_cache_item *)ptr; struct pool_cache_head *ph = &pool->cache[tid]; @@ -597,6 +597,7 @@ void pool_gc(struct pool_head *pool_ctx) void *__pool_alloc(struct pool_head *pool, unsigned int flags) { void *p = NULL; + void *caller = NULL; #ifdef DEBUG_FAIL_ALLOC if (unlikely(!(flags & POOL_F_NO_FAIL) && mem_should_fail(pool))) @@ -604,7 +605,7 @@ void *__pool_alloc(struct pool_head *pool, unsigned int flags) #endif if (!p) - p = pool_get_from_cache(pool); + p = pool_get_from_cache(pool, caller); if (unlikely(!p)) p = pool_alloc_nocache(pool); @@ -623,13 +624,15 @@ void *__pool_alloc(struct pool_head *pool, unsigned int flags) */ void __pool_free(struct pool_head *pool, void *ptr) { + const void *caller = NULL; + /* we'll get late corruption if we refill to the wrong pool or double-free */ POOL_DEBUG_CHECK_MARK(pool, ptr); if (unlikely(mem_poison_byte >= 0)) memset(ptr, mem_poison_byte, pool->size); - pool_put_to_cache(pool, ptr); + pool_put_to_cache(pool, ptr, caller); }