]> git.ipfire.org Git - thirdparty/haproxy.git/commitdiff
MINOR: pools: make the basic pool_refill_alloc()/pool_free() update needed_avg
authorWilly Tarreau <w@1wt.eu>
Thu, 15 Apr 2021 15:23:15 +0000 (17:23 +0200)
committerWilly Tarreau <w@1wt.eu>
Mon, 19 Apr 2021 13:24:33 +0000 (15:24 +0200)
This is a first step towards unifying all the fallback code. Right now
these two functions are the only ones which do not update the needed_avg
rate counter since there's currently no shared pool kept when using them.
But their code is similar to what could be used everywhere except for
this one, so let's make them capable of maintaining usage statistics.

As a side effect the needed field in "show pools" will now be populated.

include/haproxy/pool.h
src/pool.c

index 92fb6dfbfb55ff6a52ea7f66f1ff2cd006ab0a5b..d01c6d7c801b7d5fca31de26d9842d2fea4b8baf 100644 (file)
@@ -141,6 +141,7 @@ static inline void __pool_free(struct pool_head *pool, void *ptr)
 {
        _HA_ATOMIC_DEC(&pool->used);
        _HA_ATOMIC_DEC(&pool->allocated);
+       swrate_add(&pool->needed_avg, POOL_AVG_SAMPLES, pool->used);
        pool_free_area(ptr, pool->size + POOL_EXTRA);
 }
 
index 59cc5083e960b0a571e356e5262e140be4e0844a..685d6b3002b9f50731e9c335f2394f38bdf0173b 100644 (file)
@@ -165,6 +165,8 @@ void *__pool_refill_alloc(struct pool_head *pool, unsigned int avail)
                return NULL;
        }
 
+       swrate_add_scaled(&pool->needed_avg, POOL_AVG_SAMPLES, pool->allocated, POOL_AVG_SAMPLES/4);
+
        ptr = pool_alloc_area(pool->size + POOL_EXTRA);
        if (!ptr) {
                _HA_ATOMIC_INC(&pool->failed);