MINOR: pools: do not maintain the lock during pool_flush()

The locked version of pool_flush() is absurd, it locks the pool for each
and every element to be released till the end. Not only this is extremely
inefficient, but it may even never finish if other threads spend their
time refilling the pool. The only case where this can happen is during
soft-stop so the risk remains limited, but it should be addressed.
This commit is contained in:
Willy Tarreau 2021-06-10 07:13:04 +02:00
parent 9a7aa3b4a1
commit c88914379d

View File

@ -360,20 +360,19 @@ void pool_gc(struct pool_head *pool_ctx)
*/ */
void pool_flush(struct pool_head *pool) void pool_flush(struct pool_head *pool)
{ {
void *temp; void *temp, **next;
if (!pool) if (!pool)
return; return;
while (1) { HA_SPIN_LOCK(POOL_LOCK, &pool->lock);
HA_SPIN_LOCK(POOL_LOCK, &pool->lock); next = pool->free_list;
temp = pool->free_list; pool->free_list = NULL;
if (!temp) { HA_SPIN_UNLOCK(POOL_LOCK, &pool->lock);
HA_SPIN_UNLOCK(POOL_LOCK, &pool->lock);
break; while (next) {
} temp = next;
pool->free_list = *POOL_LINK(pool, temp); next = *POOL_LINK(pool, temp);
HA_SPIN_UNLOCK(POOL_LOCK, &pool->lock);
pool_put_to_os(pool, temp); pool_put_to_os(pool, temp);
} }
/* here, we should have pool->allocated == pool->used */ /* here, we should have pool->allocated == pool->used */