]> git.ipfire.org Git - thirdparty/haproxy.git/commitdiff
MEDIUM: pools: use a single pool_gc() function for locked and lockless
authorWilly Tarreau <w@1wt.eu>
Thu, 10 Jun 2021 08:21:35 +0000 (10:21 +0200)
committerWilly Tarreau <w@1wt.eu>
Thu, 10 Jun 2021 15:46:50 +0000 (17:46 +0200)
Locked and lockless shared pools don't need to use a different pool_gc()
function because this function isolates itself during the operation, so
we do not need to rely on DWCAS nor any atomic operation in fact. Let's
just get rid of the lockless one in favor of the simple one. This should
even result in a faster execution.

The ifdefs were slightly moved so that we can have pool_gc() defined
as soon as there are global pools, this avoids duplicating the function.

src/pool.c

index dc849636599dc67044bc649108455248f3a269e7..1fc32941a45757fd3e31a860a3421728f2648447 100644 (file)
@@ -284,7 +284,9 @@ void pool_gc(struct pool_head *pool_ctx)
 #endif
 }
 
-#elif defined(CONFIG_HAP_LOCKLESS_POOLS)
+#else /* CONFIG_HAP_NO_GLOBAL_POOLS */
+
+#if defined(CONFIG_HAP_LOCKLESS_POOLS)
 
 /*
  * This function frees whatever can be freed in pool <pool>.
@@ -314,44 +316,6 @@ void pool_flush(struct pool_head *pool)
        /* here, we should have pool->allocated == pool->used */
 }
 
-/*
- * This function frees whatever can be freed in all pools, but respecting
- * the minimum thresholds imposed by owners. It makes sure to be alone to
- * run by using thread_isolate(). <pool_ctx> is unused.
- */
-void pool_gc(struct pool_head *pool_ctx)
-{
-       struct pool_head *entry;
-       int isolated = thread_isolated();
-
-       if (!isolated)
-               thread_isolate();
-
-       list_for_each_entry(entry, &pools, list) {
-               while ((int)((volatile int)entry->allocated - (volatile int)entry->used) > (int)entry->minavail) {
-                       struct pool_free_list cmp, new;
-
-                       cmp.seq = entry->seq;
-                       __ha_barrier_load();
-                       cmp.free_list = entry->free_list;
-                       __ha_barrier_load();
-                       if (cmp.free_list == NULL)
-                               break;
-                       new.free_list = *POOL_LINK(entry, cmp.free_list);
-                       new.seq = cmp.seq + 1;
-                       if (HA_ATOMIC_DWCAS(&entry->free_list, &cmp, &new) == 0)
-                               continue;
-                       pool_put_to_os(entry, cmp.free_list);
-               }
-       }
-
-#if defined(HA_HAVE_MALLOC_TRIM)
-       malloc_trim(0);
-#endif
-       if (!isolated)
-               thread_release();
-}
-
 #else /* CONFIG_HAP_LOCKLESS_POOLS */
 
 /*
@@ -377,6 +341,8 @@ void pool_flush(struct pool_head *pool)
        /* here, we should have pool->allocated == pool->used */
 }
 
+#endif /* CONFIG_HAP_LOCKLESS_POOLS */
+
 /*
  * This function frees whatever can be freed in all pools, but respecting
  * the minimum thresholds imposed by owners. It makes sure to be alone to
@@ -408,7 +374,7 @@ void pool_gc(struct pool_head *pool_ctx)
        if (!isolated)
                thread_release();
 }
-#endif /* CONFIG_HAP_LOCKLESS_POOLS */
+#endif /* CONFIG_HAP_NO_GLOBAL_POOLS */
 
 #else  /* CONFIG_HAP_POOLS */