CLEANUP: pools: factor all malloc_trim() calls into trim_all_pools()
authorWilly Tarreau <w@1wt.eu>
Wed, 15 Sep 2021 08:38:21 +0000 (10:38 +0200)
committerChristopher Faulet <cfaulet@haproxy.com>
Mon, 20 Sep 2021 14:54:46 +0000 (16:54 +0200)
The code was slightly cleaned up by removing repeated occurrences of ifdefs
and moving that into a single trim_all_pools() function.

(cherry picked from commit ea3323f62c093f2ee5e09b131ab6e3e23d113838)
Signed-off-by: Christopher Faulet <cfaulet@haproxy.com>
(cherry picked from commit 33298de642027a51451e40eae7a122f29c18dc09)
Signed-off-by: Christopher Faulet <cfaulet@haproxy.com>

src/pool.c

index 1a4d1f8..709f67b 100644 (file)
@@ -48,6 +48,21 @@ static int mem_fail_rate = 0;
 static int mem_should_fail(const struct pool_head *);
 #endif
 
+#if defined(HA_HAVE_MALLOC_TRIM)
+/* ask the allocator to trim memory pools */
+static void trim_all_pools(void)
+{
+       if (using_libc_allocator)
+               malloc_trim(0);
+}
+
+#else
+
+static void trim_all_pools(void)
+{
+}
+#endif
+
 /* Try to find an existing shared pool with the same characteristics and
  * returns it, otherwise creates this one. NULL is returned if no memory
  * is available for a new creation. Two flags are supported :
@@ -224,9 +239,7 @@ void pool_flush(struct pool_head *pool)
 /* This function might ask the malloc library to trim its buffers. */
 void pool_gc(struct pool_head *pool_ctx)
 {
-#if defined(HA_HAVE_MALLOC_TRIM)
-       malloc_trim(0);
-#endif
+       trim_all_pools();
 }
 
 #elif defined(CONFIG_HAP_LOCKLESS_POOLS)
@@ -363,9 +376,8 @@ void pool_gc(struct pool_head *pool_ctx)
                }
        }
 
-#if defined(HA_HAVE_MALLOC_TRIM)
-       malloc_trim(0);
-#endif
+       trim_all_pools();
+
        if (!isolated)
                thread_release();
 }
@@ -493,9 +505,7 @@ void pool_gc(struct pool_head *pool_ctx)
                }
        }
 
-#if defined(HA_HAVE_MALLOC_TRIM)
-       malloc_trim(0);
-#endif
+       trim_all_pools();
 
        if (!isolated)
                thread_release();