]> git.ipfire.org Git - thirdparty/haproxy.git/commitdiff
MINOR: applet: make appctx use their own pool
authorWilly Tarreau <w@1wt.eu>
Thu, 18 Jul 2019 08:41:36 +0000 (10:41 +0200)
committerWilly Tarreau <w@1wt.eu>
Thu, 18 Jul 2019 08:45:08 +0000 (10:45 +0200)
A long time ago, applets were seen as an alternative to connections,
and since their respective sizes were roughly equal it appeared wise
to share the same pool. Nowadays, connections got significantly larger
but applets are not that often used, except for the cache. However
applets are mostly complementary and not alternatives anymore, as
it's very possible not to have a back connection or to share one with
other streams.

The connections will soon lose their addresses and their size will
shrink so much that appctx won't fit anymore. Given that the old
benefits of sharing these pools have long disappeared, let's stop
doing this and have a dedicated pool for appctx.

include/proto/applet.h
include/proto/stream_interface.h
src/applet.c

index 62612b5546f3201397cb7c72ce9ba3bb2ffe84ee..b4e9396e0d3469bdf76482ba7db3050362ceec93 100644 (file)
 #include <stdlib.h>
 
 #include <common/config.h>
+#include <common/memory.h>
 #include <common/mini-clist.h>
 #include <types/applet.h>
-#include <proto/connection.h>
 #include <proto/task.h>
 
 extern unsigned int nb_applets;
+extern struct pool_head *pool_head_appctx;
 
 struct task *task_run_applet(struct task *t, void *context, unsigned short state);
 
@@ -56,21 +57,20 @@ static inline void appctx_init(struct appctx *appctx, unsigned long thread_mask)
 
 /* Tries to allocate a new appctx and initialize its main fields. The appctx
  * is returned on success, NULL on failure. The appctx must be released using
- * pool_free(connection) or appctx_free(), since it's allocated from the
- * connection pool. <applet> is assigned as the applet, but it can be NULL.
+ * appctx_free(). <applet> is assigned as the applet, but it can be NULL.
  */
 static inline struct appctx *appctx_new(struct applet *applet, unsigned long thread_mask)
 {
        struct appctx *appctx;
 
-       appctx = pool_alloc(pool_head_connection);
+       appctx = pool_alloc(pool_head_appctx);
        if (likely(appctx != NULL)) {
                appctx->obj_type = OBJ_TYPE_APPCTX;
                appctx->applet = applet;
                appctx_init(appctx, thread_mask);
                appctx->t = task_new(thread_mask);
                if (unlikely(appctx->t == NULL)) {
-                       pool_free(pool_head_connection, appctx);
+                       pool_free(pool_head_appctx, appctx);
                        return NULL;
                }
                appctx->t->process = task_run_applet;
@@ -83,9 +83,7 @@ static inline struct appctx *appctx_new(struct applet *applet, unsigned long thr
        return appctx;
 }
 
-/* Releases an appctx previously allocated by appctx_new(). Note that
- * we share the connection pool.
- */
+/* Releases an appctx previously allocated by appctx_new(). */
 static inline void __appctx_free(struct appctx *appctx)
 {
        task_destroy(appctx->t);
@@ -96,7 +94,7 @@ static inline void __appctx_free(struct appctx *appctx)
                HA_SPIN_UNLOCK(BUF_WQ_LOCK, &buffer_wq_lock);
        }
 
-       pool_free(pool_head_connection, appctx);
+       pool_free(pool_head_appctx, appctx);
        _HA_ATOMIC_SUB(&nb_applets, 1);
 }
 
index 63f1738bcc9d75887ba7d23082d60f9ccdcf901d..6727921ebce0c2585bda03ea7384096181ae66b5 100644 (file)
@@ -188,7 +188,7 @@ static inline void si_release_endpoint(struct stream_interface *si)
        else if ((appctx = objt_appctx(si->end))) {
                if (appctx->applet->release && !si_state_in(si->state, SI_SB_DIS|SI_SB_CLO))
                        appctx->applet->release(appctx);
-               appctx_free(appctx); /* we share the connection pool */
+               appctx_free(appctx);
        } else if ((conn = objt_conn(si->end))) {
                conn_stop_tracking(conn);
                conn_full_close(conn);
index 4832a748f455020132709d728fc7c74d47e9ff10..f6cc08809b9d1bbdd152c98ec623d2f1ee7def45 100644 (file)
@@ -23,6 +23,8 @@
 
 unsigned int nb_applets = 0;
 
+DECLARE_POOL(pool_head_appctx,  "appctx",  sizeof(struct appctx));
+
 /* Callback used to wake up an applet when a buffer is available. The applet
  * <appctx> is woken up if an input buffer was requested for the associated
  * stream interface. In this case the buffer is immediately allocated and the