]> git.ipfire.org Git - thirdparty/haproxy.git/commitdiff
MINOR: pools: extend pool_cache API to pass a pointer to a caller
authorWilly Tarreau <w@1wt.eu>
Mon, 24 Jan 2022 14:51:50 +0000 (15:51 +0100)
committerWilly Tarreau <w@1wt.eu>
Mon, 24 Jan 2022 15:40:48 +0000 (16:40 +0100)
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
src/pool.c

index e7b077a9964e7c752b2a9909ad7ff69506808781..a79eb284bff420e4fb72eba3eca392736e644ee0 100644 (file)
@@ -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
  * <pool>. 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);
 }
index f569897c9c9450eb024d66e32167cbb468a98a4d..4b12d7c91f7ba75be0cd651523ce8c980c4a820a 100644 (file)
@@ -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);
 }