]> git.ipfire.org Git - thirdparty/haproxy.git/commitdiff
CLEANUP: pools: uninline pool_put_to_cache()
authorWilly Tarreau <w@1wt.eu>
Mon, 19 Apr 2021 09:49:26 +0000 (11:49 +0200)
committerWilly Tarreau <w@1wt.eu>
Mon, 19 Apr 2021 13:24:33 +0000 (15:24 +0200)
This function has become too big (251 bytes) and is now hurting
performance a lot, with up to 4% request rate being lost over the last
pool changes. Let's move it to pool.c as a regular function. Other
attempts were made to cut it in half but it's still inefficient. Doing
this results in saving ~90kB of object code, and even 112kB since the
pool changes, with code that is even slightly faster!

Conversely, pool_get_from_cache(), which remains half of this size, is
still faster inlined, likely in part due to the immediate use of the
returned pointer afterwards.

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

index 6e67b00d32fe80a65fab9047cc1f31e827751718..d9dc527c911c5f120e7715757dd2fc64a1accc08 100644 (file)
@@ -74,6 +74,7 @@ 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();
+void pool_put_to_cache(struct pool_head *pool, void *ptr);
 
 /* returns true if the pool is considered to have too many free objects */
 static inline int pool_is_crowded(const struct pool_head *pool)
@@ -248,30 +249,6 @@ static inline void *pool_get_from_cache(struct pool_head *pool)
        return item;
 }
 
-/* Frees an object to the local cache, possibly pushing oldest objects to the
- * shared cache, which itself may decide to release some of them to the OS.
- * While it is unspecified what the object becomes past this point, it is
- * guaranteed to be released from the users' perpective.
- */
-static inline void pool_put_to_cache(struct pool_head *pool, void *ptr)
-{
-       struct pool_cache_item *item = (struct pool_cache_item *)ptr;
-       struct pool_cache_head *ph = &pool->cache[tid];
-
-       LIST_ADD(&ph->list, &item->by_pool);
-       LIST_ADD(&ti->pool_lru_head, &item->by_lru);
-       ph->count++;
-       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();
-}
-
 
 #endif /* CONFIG_HAP_POOLS */
 
index bc568d22567e08c26be970bf33bfdad201c21e58..88c579b6d5cc7fcf822ddf4aa027386bfc9736d3 100644 (file)
@@ -234,6 +234,30 @@ void pool_evict_from_local_caches()
        } while (pool_cache_bytes > CONFIG_HAP_POOL_CACHE_SIZE * 7 / 8);
 }
 
+/* Frees an object to the local cache, possibly pushing oldest objects to the
+ * shared cache, which itself may decide to release some of them to the OS.
+ * While it is unspecified what the object becomes past this point, it is
+ * guaranteed to be released from the users' perpective.
+ */
+void pool_put_to_cache(struct pool_head *pool, void *ptr)
+{
+       struct pool_cache_item *item = (struct pool_cache_item *)ptr;
+       struct pool_cache_head *ph = &pool->cache[tid];
+
+       LIST_ADD(&ph->list, &item->by_pool);
+       LIST_ADD(&ti->pool_lru_head, &item->by_lru);
+       ph->count++;
+       pool_cache_count++;
+       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)
+                       pool_evict_from_local_cache(pool);
+               if (pool_cache_bytes > CONFIG_HAP_POOL_CACHE_SIZE)
+                       pool_evict_from_local_caches();
+       }
+}
+
 #if defined(CONFIG_HAP_NO_GLOBAL_POOLS)
 
 /* legacy stuff */