]> git.ipfire.org Git - thirdparty/haproxy.git/commitdiff
MEDIUM: pool: compute the number of evictable entries once per pool
authorWilly Tarreau <w@1wt.eu>
Sat, 1 Jan 2022 23:27:06 +0000 (00:27 +0100)
committerWilly Tarreau <w@1wt.eu>
Sun, 2 Jan 2022 18:35:26 +0000 (19:35 +0100)
In pool_evict_from_local_cache() we used to check for room left in the
pool for each and every object. Now we compute the value before entering
the loop and keep into a local list what has to be released, and call
the OS-specific functions for the other ones.

It should already save some cycles since it's not needed anymore to
recheck for the pool's filling status. But the main expected benefit
comes from the ability to pre-construct a list of all releasable
objects, that will later help with grouping them.

src/pool.c

index 7b76802a587e11ee0334d351dbc5e6d90177413e..6ea081e876875ef3750470080190f2e2a6b3a4be 100644 (file)
@@ -310,7 +310,11 @@ void pool_free_nocache(struct pool_head *pool, void *ptr)
 void pool_evict_from_local_cache(struct pool_head *pool)
 {
        struct pool_cache_head *ph = &pool->cache[tid];
+       struct pool_item *pi, *to_free = NULL;
        struct pool_cache_item *item;
+       uint to_free_max;
+
+       to_free_max = pool_releasable(pool);
 
        while (ph->count >= 16 + pool_cache_count / 8 &&
               pool_cache_bytes > CONFIG_HAP_POOL_CACHE_SIZE * 3 / 4) {
@@ -321,10 +325,19 @@ void pool_evict_from_local_cache(struct pool_head *pool)
                LIST_DELETE(&item->by_pool);
                LIST_DELETE(&item->by_lru);
 
-               if (unlikely(pool_is_crowded(pool)))
+               if (to_free_max) {
+                       pi = (struct pool_item *)item;
+                       pi->next = to_free;
+                       to_free = pi;
+                       to_free_max--;
+               } else
                        pool_free_nocache(pool, item);
-               else
-                       pool_put_to_shared_cache(pool, (struct pool_item *)item);
+       }
+
+       while (to_free) {
+               pi = to_free;
+               to_free = pi->next;
+               pool_put_to_shared_cache(pool, pi);
        }
 }