mirror of
http://git.haproxy.org/git/haproxy.git/
synced 2025-04-19 21:45:33 +00:00
MINOR: pool: add a function to estimate how many may be released at once
At the moment we count the number of releasable objects to a shared pool one by one. The way the formula is made allows to pre-compute the number of available slots, so let's add a function for that so that callers can do it once before iterating. This takes into account the average number of entries needed and the minimum availability per pool. The function is not used yet.
This commit is contained in:
parent
c16ed3b090
commit
91a8e28f90
@ -118,6 +118,12 @@ static inline int pool_is_crowded(const struct pool_head *pool)
|
||||
return 1;
|
||||
}
|
||||
|
||||
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 */
|
||||
@ -140,6 +146,33 @@ static inline int pool_is_crowded(const struct pool_head *pool)
|
||||
(int)(pool->allocated - pool->used) >= pool->minavail;
|
||||
}
|
||||
|
||||
/* Returns the max number of entries that may be brought back to the pool
|
||||
* before it's considered as full. Note that it is only usable for releasing
|
||||
* objects, hence the function assumes that no more than ->used entries will
|
||||
* 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.
|
||||
*/
|
||||
static inline uint pool_releasable(const struct pool_head *pool)
|
||||
{
|
||||
uint alloc, used;
|
||||
|
||||
alloc = HA_ATOMIC_LOAD(&pool->allocated);
|
||||
used = HA_ATOMIC_LOAD(&pool->used);
|
||||
if (used < alloc)
|
||||
used = alloc;
|
||||
|
||||
if (alloc < swrate_avg(pool->needed_avg + pool->needed_avg / 4, POOL_AVG_SAMPLES))
|
||||
return used; // less than needed is allocated, can release everything
|
||||
|
||||
if ((uint)(alloc - used) < pool->minavail)
|
||||
return pool->minavail - (alloc - used); // less than minimum available
|
||||
|
||||
/* there are enough objects in this pool */
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
#endif /* CONFIG_HAP_NO_GLOBAL_POOLS */
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user