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.
This commit is contained in:
Willy Tarreau 2022-01-24 15:51:50 +01:00
parent 7fa092b727
commit 0e2a5b4b61
2 changed files with 10 additions and 7 deletions

View 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);
}

View 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);
}