]> git.ipfire.org Git - thirdparty/haproxy.git/commitdiff
MEDIUM: pools: start to batch eviction from local caches
authorWilly Tarreau <w@1wt.eu>
Sun, 2 Jan 2022 16:24:55 +0000 (17:24 +0100)
committerWilly Tarreau <w@1wt.eu>
Sun, 2 Jan 2022 18:35:26 +0000 (19:35 +0100)
Since previous patch we can forcefully evict multiple objects from the
local cache, even when evicting basd on the LRU entries. Let's define
a compile-time configurable setting to batch releasing of objects. For
now we set this value to 8 items per round.

This is marked medium because eviction from the LRU will slightly change
in order to group the last items that are freed within a single cache
instead of accurately scanning only the oldest ones exactly in their
order of appearance. But this is required in order to evolve towards
batched removals.

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

index 35ad50d04ab213be300cae15ab128636af2c9bac..baa9aff51a6429ab2d8e059d70db2043e9a56538 100644 (file)
 #define CONFIG_HAP_POOL_CACHE_SIZE 1048576
 #endif
 
+#ifndef CONFIG_HAP_POOL_CLUSTER_SIZE
+#define CONFIG_HAP_POOL_CLUSTER_SIZE 8
+#endif
+
 /* Number of samples used to compute the times reported in stats. A power of
  * two is highly recommended, and this value multiplied by the largest response
  * time must not overflow and unsigned int. See freq_ctr.h for more information.
index 2a56cd4dc50f547ae4028f2556d910002c261d6f..13ecc5fb0980ca147d948a4c0f17b60db1394036 100644 (file)
@@ -346,9 +346,10 @@ void pool_evict_from_local_cache(struct pool_head *pool)
 {
        struct pool_cache_head *ph = &pool->cache[tid];
 
-       while (ph->count >= 16 + pool_cache_count / 8 &&
+       while (ph->count >= CONFIG_HAP_POOL_CLUSTER_SIZE &&
+              ph->count >= 16 + pool_cache_count / 8 &&
               pool_cache_bytes > CONFIG_HAP_POOL_CACHE_SIZE * 3 / 4) {
-               pool_evict_last_items(pool, ph, 1);
+               pool_evict_last_items(pool, ph, CONFIG_HAP_POOL_CLUSTER_SIZE);
        }
 }
 
@@ -368,7 +369,7 @@ void pool_evict_from_local_caches()
                 */
                ph = LIST_NEXT(&item->by_pool, struct pool_cache_head *, list);
                pool = container_of(ph - tid, struct pool_head, cache);
-               pool_evict_last_items(pool, ph, 1);
+               pool_evict_last_items(pool, ph, CONFIG_HAP_POOL_CLUSTER_SIZE);
        } while (pool_cache_bytes > CONFIG_HAP_POOL_CACHE_SIZE * 7 / 8);
 }
 
@@ -389,7 +390,7 @@ void pool_put_to_cache(struct pool_head *pool, void *ptr)
        pool_cache_bytes += pool->size;
 
        if (unlikely(pool_cache_bytes > CONFIG_HAP_POOL_CACHE_SIZE * 3 / 4)) {
-               if (ph->count >= 16 + pool_cache_count / 8)
+               if (ph->count >= 16 + pool_cache_count / 8 + CONFIG_HAP_POOL_CLUSTER_SIZE)
                        pool_evict_from_local_cache(pool);
                if (pool_cache_bytes > CONFIG_HAP_POOL_CACHE_SIZE)
                        pool_evict_from_local_caches();