diff --git a/include/haproxy/pool-t.h b/include/haproxy/pool-t.h index 217b7542b..c8f7d469b 100644 --- a/include/haproxy/pool-t.h +++ b/include/haproxy/pool-t.h @@ -45,6 +45,7 @@ #define POOL_DBG_DONT_MERGE 0x00000002 // do not merge same-size pools #define POOL_DBG_COLD_FIRST 0x00000004 // pick cold objects first #define POOL_DBG_INTEGRITY 0x00000008 // perform integrity checks on cache +#define POOL_DBG_NO_GLOBAL 0x00000010 // disable global pools /* This is the head of a thread-local cache */ diff --git a/include/haproxy/pool.h b/include/haproxy/pool.h index 296747ad1..8497cfafa 100644 --- a/include/haproxy/pool.h +++ b/include/haproxy/pool.h @@ -145,27 +145,6 @@ void pool_evict_from_local_caches(void); void pool_put_to_cache(struct pool_head *pool, void *ptr, const void *caller); void pool_fill_pattern(struct pool_cache_head *pch, struct pool_cache_item *item, uint size); void pool_check_pattern(struct pool_cache_head *pch, struct pool_cache_item *item, uint size); - -#if defined(CONFIG_HAP_NO_GLOBAL_POOLS) - -static inline uint pool_releasable(const struct pool_head *pool) -{ - /* no room left */ - return 0; -} - -static inline void pool_refill_local_from_shared(struct pool_head *pool, struct pool_cache_head *pch) -{ - /* ignored without shared pools */ -} - -static inline void pool_put_to_shared_cache(struct pool_head *pool, struct pool_item *item, uint count) -{ - /* ignored without shared pools */ -} - -#else /* CONFIG_HAP_NO_GLOBAL_POOLS */ - void pool_refill_local_from_shared(struct pool_head *pool, struct pool_cache_head *pch); void pool_put_to_shared_cache(struct pool_head *pool, struct pool_item *item, uint count); @@ -175,12 +154,17 @@ void pool_put_to_shared_cache(struct pool_head *pool, struct pool_item *item, ui * be released in the worst case, and that this value is always lower than or * equal to ->allocated. It's important to understand that under thread * contention these values may not always be accurate but the principle is that - * any deviation remains contained. + * any deviation remains contained. When global pools are disabled, this + * function always returns zero so that the caller knows it must free the + * object via other ways. */ static inline uint pool_releasable(const struct pool_head *pool) { uint alloc, used; + if (unlikely(pool_debugging & POOL_DBG_NO_GLOBAL)) + return 0; + alloc = HA_ATOMIC_LOAD(&pool->allocated); used = HA_ATOMIC_LOAD(&pool->used); if (used < alloc) @@ -196,16 +180,13 @@ static inline uint pool_releasable(const struct pool_head *pool) return 0; } - -#endif /* CONFIG_HAP_NO_GLOBAL_POOLS */ - /* These are generic cache-aware wrappers that allocate/free from/to the local * cache first, then from the second level if it exists. */ /* Tries to retrieve an object from the local pool cache corresponding to pool - * . If none is available, tries to allocate from the shared cache, and - * returns NULL if nothing is available. + * . If none is available, tries to allocate from the shared cache if any + * and returns NULL if nothing is available. */ static inline void *pool_get_from_cache(struct pool_head *pool, const void *caller) { @@ -214,7 +195,8 @@ static inline void *pool_get_from_cache(struct pool_head *pool, const void *call ph = &pool->cache[tid]; if (unlikely(LIST_ISEMPTY(&ph->list))) { - pool_refill_local_from_shared(pool, ph); + if (!(pool_debugging & POOL_DBG_NO_GLOBAL)) + pool_refill_local_from_shared(pool, ph); if (LIST_ISEMPTY(&ph->list)) return NULL; } diff --git a/src/pool.c b/src/pool.c index 4ba7ea799..82f51b541 100644 --- a/src/pool.c +++ b/src/pool.c @@ -49,6 +49,9 @@ uint pool_debugging __read_mostly = /* set of POOL_DBG_* flags */ #endif #ifdef DEBUG_POOL_INTEGRITY POOL_DBG_INTEGRITY | +#endif +#ifdef CONFIG_HAP_NO_GLOBAL_POOLS + POOL_DBG_NO_GLOBAL | #endif 0; @@ -393,6 +396,7 @@ static void pool_evict_last_items(struct pool_head *pool, struct pool_cache_head uint cluster = 0; uint to_free_max; + /* Note: this will be zero when global pools are disabled */ to_free_max = pool_releasable(pool); while (released < count && !LIST_ISEMPTY(&ph->list)) { @@ -404,6 +408,7 @@ static void pool_evict_last_items(struct pool_head *pool, struct pool_cache_head LIST_DELETE(&item->by_lru); if (to_free_max > released || cluster) { + /* will never match when global pools are disabled */ pi = (struct pool_item *)item; pi->next = NULL; pi->down = head; @@ -501,21 +506,6 @@ void pool_put_to_cache(struct pool_head *pool, void *ptr, const void *caller) } } -#if defined(CONFIG_HAP_NO_GLOBAL_POOLS) - -/* legacy stuff */ -void pool_flush(struct pool_head *pool) -{ -} - -/* This function might ask the malloc library to trim its buffers. */ -void pool_gc(struct pool_head *pool_ctx) -{ - trim_all_pools(); -} - -#else /* CONFIG_HAP_NO_GLOBAL_POOLS */ - /* Tries to refill the local cache from the shared one for pool . * This is only used when pools are in use and shared pools are enabled. No * malloc() is attempted, and poisonning is never performed. The purpose is to @@ -659,7 +649,6 @@ void pool_gc(struct pool_head *pool_ctx) if (!isolated) thread_release(); } -#endif /* CONFIG_HAP_NO_GLOBAL_POOLS */ #else /* CONFIG_HAP_POOLS */