]> git.ipfire.org Git - thirdparty/haproxy.git/commitdiff
MEDIUM: pools: make pool_put_to_cache() always call pool_put_to_local_cache()
authorWilly Tarreau <w@1wt.eu>
Mon, 19 Apr 2021 06:50:45 +0000 (08:50 +0200)
committerWilly Tarreau <w@1wt.eu>
Mon, 19 Apr 2021 13:24:33 +0000 (15:24 +0200)
Till now it used to call it only if there were not too many objects into
the local cache otherwise would send the latest one directly into the
shared cache. Now it always sends to the local cache and it's up to the
local cache to free its oldest objects. From a cache freshness perspective
it's better this way since we always evict cold objects instead of hot
ones. From an API perspective it's better because it will help make the
shared cache invisible to the public API.

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

index dc01e1a8051e7e799b2f080e5f95779e6d0a5da7..d7ae5f06877137e3088aec3e69cc6cd91e839a16 100644 (file)
@@ -72,6 +72,7 @@ void pool_destroy_all();
 extern THREAD_LOCAL size_t pool_cache_bytes;   /* total cache size */
 extern THREAD_LOCAL size_t pool_cache_count;   /* #cache objects   */
 
+void pool_evict_from_local_cache(struct pool_head *pool);
 void pool_evict_from_local_caches();
 
 /* returns true if the pool is considered to have too many free objects */
@@ -120,6 +121,10 @@ static inline void pool_put_to_local_cache(struct pool_head *pool, void *ptr)
        pool_cache_count++;
        pool_cache_bytes += pool->size;
 
+       if (unlikely(pool_cache_bytes > CONFIG_HAP_POOL_CACHE_SIZE * 3 / 4 &&
+                    ph->count >= 16 + pool_cache_count / 8))
+               pool_evict_from_local_cache(pool);
+
        if (unlikely(pool_cache_bytes > CONFIG_HAP_POOL_CACHE_SIZE))
                pool_evict_from_local_caches();
 }
@@ -286,16 +291,7 @@ static inline void *pool_get_from_cache(struct pool_head *pool)
  */
 static inline void pool_put_to_cache(struct pool_head *pool, void *ptr)
 {
-       /* put the object back into the cache only if there are not too
-        * many objects yet in this pool (no more than half of the cached
-        * is used or this pool uses no more than 1/8 of the cache size).
-        */
-       if ((pool_cache_bytes <= CONFIG_HAP_POOL_CACHE_SIZE * 3 / 4 ||
-            pool->cache[tid].count < 16 + pool_cache_count / 8)) {
-               pool_put_to_local_cache(pool, ptr);
-               return;
-       }
-       pool_put_to_shared_cache(pool, ptr);
+       pool_put_to_local_cache(pool, ptr);
 }
 
 
index 8ccb0c0b85eae5ea01cd78a4217efa73be6e2906..bc568d22567e08c26be970bf33bfdad201c21e58 100644 (file)
@@ -196,7 +196,6 @@ void pool_evict_from_local_cache(struct pool_head *pool)
 {
        struct pool_cache_head *ph = &pool->cache[tid];
        struct pool_cache_item *item;
-       struct pool_head *pool;
 
        while (ph->count >= 16 + pool_cache_count / 8 &&
               pool_cache_bytes > CONFIG_HAP_POOL_CACHE_SIZE * 3 / 4) {