]> git.ipfire.org Git - thirdparty/haproxy.git/commitdiff
MINOR: pools: call malloc_trim() under thread isolation
authorWilly Tarreau <w@1wt.eu>
Thu, 10 Jun 2021 06:40:16 +0000 (08:40 +0200)
committerWilly Tarreau <w@1wt.eu>
Thu, 10 Jun 2021 15:46:50 +0000 (17:46 +0200)
pool_gc() was adjusted to run under thread isolation by commit c0e2ff202
("MEDIUM: memory: make pool_gc() run under thread isolation") so that the
underlying malloc() and free() don't compete between threads during these
potentially aggressive moments (especially when mmap/munmap are involved).

Commit 88366c292 ("MEDIUM: pools: call malloc_trim() from pool_gc()")
later added a call to malloc_trim() but made it outside of the thread
isolation, which is contrary to the principle explained above. Also it
missed it in the locked version, meaning that those without a lockless
implementation cannot benefit from trimming.

This patch fixes that by calling it before thread_release() in both
places.

src/pool.c

index c69143a089499df5c7ba9d239e2e8cf7e9a45133..dc849636599dc67044bc649108455248f3a269e7 100644 (file)
@@ -345,12 +345,11 @@ void pool_gc(struct pool_head *pool_ctx)
                }
        }
 
-       if (!isolated)
-               thread_release();
-
 #if defined(HA_HAVE_MALLOC_TRIM)
        malloc_trim(0);
 #endif
+       if (!isolated)
+               thread_release();
 }
 
 #else /* CONFIG_HAP_LOCKLESS_POOLS */
@@ -402,6 +401,10 @@ void pool_gc(struct pool_head *pool_ctx)
                }
        }
 
+#if defined(HA_HAVE_MALLOC_TRIM)
+       malloc_trim(0);
+#endif
+
        if (!isolated)
                thread_release();
 }