]> git.ipfire.org Git - thirdparty/haproxy.git/commitdiff
[MAJOR] migrated task, tree64 and session to pool2
authorWilly Tarreau <w@1wt.eu>
Sun, 13 May 2007 17:43:47 +0000 (19:43 +0200)
committerWilly Tarreau <w@1wt.eu>
Sun, 13 May 2007 17:43:47 +0000 (19:43 +0200)
task and tree64 are already very close in size and are merged together.
Overall performance gained slightly by this simple change.

include/import/tree.h
include/proto/session.h
include/proto/task.h
include/types/session.h
include/types/task.h
src/appsession.c
src/cfgparse.c
src/client.c
src/haproxy.c
src/session.c
src/task.c

index 7c375e7ab3e38ea925dab1156a7b6bb6f63c7959..11ca6e00f2f71358d44ea832d4adf38637c1cdbb 100644 (file)
@@ -2,6 +2,8 @@
  * tree.h : tree manipulation macros and structures.
  * (C) 2002 - Willy Tarreau - willy@ant-computing.com
  *
+ * 2007/05/13: adapted to mempools v2.
+ *
  */
 
 #ifndef __TREE_H__
@@ -51,8 +53,7 @@ struct tree64 {
     struct tree64 *up;                 /* parent node. NULL = root */
 };
 
-#define sizeof_tree64 (sizeof (struct tree64))
-extern void **pool_tree64;
+extern struct pool_head *pool2_tree64;
 
 #define ULTREE_HEAD(l)         struct ultree (l) = { .left=NULL, .right=NULL, .up=NULL, .low=0, .level=LONGBITS, .data=NULL }
 #define ULTREE_INIT(l)         { (l)->data = (l)->left = (l)->right = NULL; }
@@ -96,7 +97,7 @@ inline static struct ulltree *__ulltree_insert(struct ulltree *root, unsigned lo
 
        if (next == NULL) {
            /* we'll have to insert our node here */
-           *branch = new = (struct ulltree *)pool_alloc(tree64);
+           *branch = new = (struct ulltree *)pool_alloc2(pool2_tree64);
            ULLTREE_INIT(new);
            new->up = root;
            new->value = x;
@@ -111,7 +112,7 @@ inline static struct ulltree *__ulltree_insert(struct ulltree *root, unsigned lo
     /* ok, now we know that we must insert between both. */
 
     /* the new interconnect node */
-    *branch = node = (struct ulltree *)pool_alloc(tree64); /* was <next> */
+    *branch = node = (struct ulltree *)pool_alloc2(pool2_tree64); /* was <next> */
     ULLTREE_INIT(node);
     node->up = root;
     next->up = node;
@@ -139,7 +140,7 @@ inline static struct ulltree *__ulltree_insert(struct ulltree *root, unsigned lo
 
     /* the new leaf now */
     node->level = m; /* set the level to the lowest common bit */
-    new = (struct ulltree *)pool_alloc(tree64);
+    new = (struct ulltree *)pool_alloc2(pool2_tree64);
     ULLTREE_INIT(new);
     new->value = x;
     new->level = ffs;
@@ -186,7 +187,7 @@ inline static struct ultree *__ultree_insert(struct ultree *root, unsigned long
 
        if (next == NULL) {
            /* we'll have to insert our node here */
-           *branch = new = (struct ultree *)pool_alloc(tree64);
+           *branch = new = (struct ultree *)pool_alloc2(pool2_tree64);
            ULTREE_INIT(new);
            new->up = root;
            new->low = x;
@@ -200,7 +201,7 @@ inline static struct ultree *__ultree_insert(struct ultree *root, unsigned long
     /* ok, now we know that we must insert between both. */
 
     /* the new interconnect node */
-    *branch = node = (struct ultree *)pool_alloc(tree64); /* was <next> */
+    *branch = node = (struct ultree *)pool_alloc2(pool2_tree64); /* was <next> */
     ULTREE_INIT(node);
     node->up = root;
     next->up = node;
@@ -228,7 +229,7 @@ inline static struct ultree *__ultree_insert(struct ultree *root, unsigned long
 
     /* the new leaf now */
     node->level = m; /* set the level to the lowest common bit */
-    new = (struct ultree *)pool_alloc(tree64);
+    new = (struct ultree *)pool_alloc2(pool2_tree64);
     ULTREE_INIT(new);
     new->low = x;
     new->level = ffs;
@@ -279,7 +280,7 @@ inline static struct ultree *__ul2tree_insert(struct ultree *root, unsigned long
 
        if (next == NULL) {
            /* we'll have to insert our node here */
-           *branch = new =(struct ultree *)pool_alloc(tree64);
+           *branch = new =(struct ultree *)pool_alloc2(pool2_tree64);
            UL2TREE_INIT(new);
            new->up = root;
            new->high = h;
@@ -308,7 +309,7 @@ inline static struct ultree *__ul2tree_insert(struct ultree *root, unsigned long
     /* ok, now we know that we must insert between both. */
 
     /* the new interconnect node */
-    *branch = node = (struct ultree *)pool_alloc(tree64); /* was <next> */
+    *branch = node = (struct ultree *)pool_alloc2(pool2_tree64); /* was <next> */
     UL2TREE_INIT(node);
     node->up = root;
     next->up = node;
@@ -352,7 +353,7 @@ inline static struct ultree *__ul2tree_insert(struct ultree *root, unsigned long
 
     /* the new leaf now */
     node->level = m; /* set the level to the lowest common bit */
-    new = (struct ultree *)pool_alloc(tree64);
+    new = (struct ultree *)pool_alloc2(pool2_tree64);
     UL2TREE_INIT(new);
     new->high = h;
     new->low = l;
@@ -456,7 +457,7 @@ __right:                                                            \
            goto __end; /* nothing left, don't delete the root node */  \
        else {                                                          \
            typeof (__root) __old;                                      \
-           pool_free(tree64, __ptr);                                   \
+           pool_free2(pool2_tree64, __ptr);                            \
            __old = __ptr;                                              \
            __ptr = __stack[__slen];                                    \
            if (__ptr->left == __old) {                                 \
@@ -506,7 +507,7 @@ __right:                                                            \
            goto __end; /* nothing left, don't delete the root node */  \
        else {                                                          \
            typeof (__root) __old;                                      \
-           pool_free(__type, __ptr);                                   \
+           pool_free2(pool##__type, __ptr);                            \
            __old = __ptr;                                              \
            __ptr = __stack[__slen];                                    \
            if (__ptr->left == __old) {                                 \
@@ -561,7 +562,7 @@ __right:                                                            \
            goto __end; /* nothing left, don't delete the root node */  \
        else {                                                          \
            typeof (__root) __old;                                      \
-           pool_free(tree64, __ptr);                                   \
+           pool_free2(pool2_tree64, __ptr);                            \
            __old = __ptr;                                              \
            __ptr = __stack[__slen];                                    \
            if (__ptr->left == __old) {                                 \
@@ -617,7 +618,7 @@ __right:                                                            \
            goto __end; /* nothing left, don't delete the root node */  \
        else {                                                          \
            typeof (__root) __old;                                      \
-           pool_free(tree64, __ptr);                                   \
+           pool_free2(pool2_tree64, __ptr);                            \
            __old = __ptr;                                              \
            __ptr = __stack[__slen];                                    \
            if (__ptr->left == __old) {                                 \
@@ -671,7 +672,7 @@ inline static void *__tree_delete_only_one(void *firstnode) {
         */
        down = node;
        node = node->up;
-       pool_free(tree64, down);
+       pool_free2(pool2_tree64, down);
        if (node->data || node->up == NULL)
            return node;
        /* now we're sure we were sharing this empty node with another branch, let's find it */
@@ -684,7 +685,7 @@ inline static void *__tree_delete_only_one(void *firstnode) {
        down->up = node->up;
     }
     /* free the last node */
-    pool_free(tree64, node);
+    pool_free2(pool2_tree64, node);
     return down->up;
 }
 
@@ -716,7 +717,7 @@ inline static void *__tree_delete(void *firstnode) {
            uplink = &up->right;
 
        *uplink = down; /* we relink the lower branch above us or simply cut it */
-       pool_free(tree64, node);
+       pool_free2(pool2_tree64, node);
        node = up;
        if (down)
            down->up = node;
index e3e523409728f5b7be6be5ff704f8766dc2fe34e..a18669e1d533ea5ea0fd84f74d81618e80699c50 100644 (file)
@@ -2,7 +2,7 @@
   include/proto/session.h
   This file defines everything related to sessions.
 
-  Copyright (C) 2000-2006 Willy Tarreau - w@1wt.eu
+  Copyright (C) 2000-2007 Willy Tarreau - w@1wt.eu
   
   This library is free software; you can redistribute it and/or
   modify it under the terms of the GNU Lesser General Public
 #define _PROTO_SESSION_H
 
 #include <common/config.h>
+#include <common/memory.h>
 #include <types/session.h>
 
+extern struct pool_head *pool2_session;
+
 void session_free(struct session *s);
 
+/* perform minimal intializations, report 0 in case of error, 1 if OK. */
+int init_session();
 
 #endif /* _PROTO_SESSION_H */
 
index c594d525ed5fc485b1e32381a3da985a1258bd29..6bee1b2f19cb37a7cb45a9e5629ae82206f7a5fc 100644 (file)
 #include <types/task.h>
 
 extern void *run_queue;
+extern struct pool_head *pool2_task;
+
+/* perform minimal intializations, report 0 in case of error, 1 if OK. */
+int init_task();
 
 /* needed later */
 void *tree_delete(void *node);
@@ -97,7 +101,7 @@ static inline struct task *task_delete(struct task *t)
  */
 static inline void task_free(struct task *t)
 {
-       pool_free(task, t);
+       pool_free2(pool2_task, t);
 }
 
 /* inserts <task> into its assigned wait queue, where it may already be. In this case, it
index 7ef138f105cc5920526b2549b7b766510b83b567..819acfd74aa5ed039e63b9f5f5459ea397b543ec 100644 (file)
@@ -2,7 +2,7 @@
   include/types/session.h
   This file defines everything related to sessions.
 
-  Copyright (C) 2000-2006 Willy Tarreau - w@1wt.eu
+  Copyright (C) 2000-2007 Willy Tarreau - w@1wt.eu
   
   This library is free software; you can redistribute it and/or
   modify it under the terms of the GNU Lesser General Public
@@ -123,10 +123,6 @@ struct session {
 };
 
 
-#define sizeof_session  sizeof(struct session)
-extern void **pool_session;
-
-
 #endif /* _TYPES_SESSION_H */
 
 /*
index 42699dbfff886f305421f336dd3b22a21dbc78ad..e0bbd6dac80e99e3f0860a4d1ccd0958a2c0e493 100644 (file)
@@ -42,9 +42,6 @@ struct task {
        void *context;                  /* the task's context */
 };
 
-#define sizeof_task     sizeof(struct task)
-extern void **pool_task;
-
 #endif /* _TYPES_TASK_H */
 
 /*
index 72b7e403fa9661fa19c121f5de38a627fd5f6dc4..bf26510e40a8e28cd5c9926e9b78f95defff7e9d 100644 (file)
@@ -111,7 +111,7 @@ int appsession_task_init(void)
        static int initialized = 0;
        struct task *t;
        if (!initialized) {
-               if ((t = pool_alloc(task)) == NULL)
+               if ((t = pool_alloc2(pool2_task)) == NULL)
                        return -1;
                t->wq = NULL;
                t->qlist.p = NULL;
index 1edaa8fc0b52068df8eb67e8c39bb7c185c47151..6dd7ab6173afcf2dabb91a5df20ce01f7b9d3b6d 100644 (file)
@@ -2488,7 +2488,7 @@ int readcfgfile(const char *file)
                        if (newsrv->maxconn > 0) {
                                struct task *t;
 
-                               if ((t = pool_alloc(task)) == NULL) {
+                               if ((t = pool_alloc2(pool2_task)) == NULL) {
                                        Alert("parsing [%s:%d] : out of memory.\n", file, linenum);
                                        return -1;
                                }
@@ -2535,7 +2535,7 @@ int readcfgfile(const char *file)
                        while (newsrv != NULL) {
                                /* should this server be checked ? */
                                if (newsrv->state & SRV_CHECKED) {
-                                       if ((t = pool_alloc(task)) == NULL) {
+                                       if ((t = pool_alloc2(pool2_task)) == NULL) {
                                                Alert("parsing [%s:%d] : out of memory.\n", file, linenum);
                                                return -1;
                                        }
index 52b281bded81100cf177ad0523957b6cfc6d956a..6afb20636590c6079f683d84d35c37469ced33b4 100644 (file)
@@ -41,6 +41,7 @@
 #include <proto/log.h>
 #include <proto/hdr_idx.h>
 #include <proto/proto_http.h>
+#include <proto/session.h>
 #include <proto/stream_sock.h>
 #include <proto/task.h>
 
@@ -110,7 +111,7 @@ int event_accept(int fd) {
                        }
                }
 
-               if ((s = pool_alloc(session)) == NULL) { /* disable this proxy for a while */
+               if ((s = pool_alloc2(pool2_session)) == NULL) { /* disable this proxy for a while */
                        Alert("out of memory in event_accept().\n");
                        EV_FD_CLR(fd, DIR_RD);
                        p->state = PR_STIDLE;
@@ -127,18 +128,18 @@ int event_accept(int fd) {
                    (((struct sockaddr_in *)&addr)->sin_addr.s_addr & p->mon_mask.s_addr) == p->mon_net.s_addr) {
                        if (p->mode == PR_MODE_TCP) {
                                close(cfd);
-                               pool_free(session, s);
+                               pool_free2(pool2_session, s);
                                continue;
                        }
                        s->flags |= SN_MONITOR;
                }
 
-               if ((t = pool_alloc(task)) == NULL) { /* disable this proxy for a while */
+               if ((t = pool_alloc2(pool2_task)) == NULL) { /* disable this proxy for a while */
                        Alert("out of memory in event_accept().\n");
                        EV_FD_CLR(fd, DIR_RD);
                        p->state = PR_STIDLE;
                        close(cfd);
-                       pool_free(session, s);
+                       pool_free2(pool2_session, s);
                        return 0;
                }
 
@@ -146,8 +147,8 @@ int event_accept(int fd) {
                if (cfd >= global.maxsock) {
                        Alert("accept(): not enough free sockets. Raise -n argument. Giving up.\n");
                        close(cfd);
-                       pool_free(task, t);
-                       pool_free(session, s);
+                       pool_free2(pool2_task, t);
+                       pool_free2(pool2_session, s);
                        return 0;
                }
 
@@ -156,8 +157,8 @@ int event_accept(int fd) {
                                (char *) &one, sizeof(one)) == -1)) {
                        Alert("accept(): cannot set the socket in non blocking mode. Giving up\n");
                        close(cfd);
-                       pool_free(task, t);
-                       pool_free(session, s);
+                       pool_free2(pool2_task, t);
+                       pool_free2(pool2_session, s);
                        return 0;
                }
 
@@ -236,8 +237,8 @@ int event_accept(int fd) {
                                     pool_alloc_from(p->req_cap_pool, p->nb_req_cap*sizeof(char *)))
                                    == NULL) { /* no memory */
                                        close(cfd); /* nothing can be done for this fd without memory */
-                                       pool_free(task, t);
-                                       pool_free(session, s);
+                                       pool_free2(pool2_task, t);
+                                       pool_free2(pool2_session, s);
                                        return 0;
                                }
                                memset(txn->req.cap, 0, p->nb_req_cap*sizeof(char *));
@@ -251,8 +252,8 @@ int event_accept(int fd) {
                                        if (txn->req.cap != NULL)
                                                pool_free_to(p->req_cap_pool, txn->req.cap);
                                        close(cfd); /* nothing can be done for this fd without memory */
-                                       pool_free(task, t);
-                                       pool_free(session, s);
+                                       pool_free2(pool2_task, t);
+                                       pool_free2(pool2_session, s);
                                        return 0;
                                }
                                memset(txn->rsp.cap, 0, p->nb_rsp_cap*sizeof(char *));
@@ -267,8 +268,8 @@ int event_accept(int fd) {
                                if (txn->req.cap != NULL)
                                        pool_free_to(p->req_cap_pool, txn->req.cap);
                                close(cfd); /* nothing can be done for this fd without memory */
-                               pool_free(task, t);
-                               pool_free(session, s);
+                               pool_free2(pool2_task, t);
+                               pool_free2(pool2_session, s);
                                return 0;
                        }
                        hdr_idx_init(&txn->hdr_idx);
@@ -354,8 +355,8 @@ int event_accept(int fd) {
                        if (txn->req.cap != NULL)
                                pool_free_to(p->req_cap_pool, txn->req.cap);
                        close(cfd); /* nothing can be done for this fd without memory */
-                       pool_free(task, t);
-                       pool_free(session, s);
+                       pool_free2(pool2_task, t);
+                       pool_free2(pool2_session, s);
                        return 0;
                }
 
@@ -377,8 +378,8 @@ int event_accept(int fd) {
                        if (txn->req.cap != NULL)
                                pool_free_to(p->req_cap_pool, txn->req.cap);
                        close(cfd); /* nothing can be done for this fd without memory */
-                       pool_free(task, t);
-                       pool_free(session, s);
+                       pool_free2(pool2_task, t);
+                       pool_free2(pool2_session, s);
                        return 0;
                }
 
index 0acf75fb5d7e7b8dc394bf687568bde6bc294031..18bef851473c9a4eb2715f0a37dc0622454a5729 100644 (file)
@@ -87,6 +87,7 @@
 #include <proto/proxy.h>
 #include <proto/queue.h>
 #include <proto/server.h>
+#include <proto/session.h>
 #include <proto/stream_sock.h>
 #include <proto/task.h>
 
@@ -292,6 +293,9 @@ void dump(int sig)
                         );
        }
 #endif
+       /* dump memory usage then free everything possible */
+       dump_pools();
+       pool_gc2();
 }
 
 #ifdef DEBUG_MEMORY
@@ -370,6 +374,8 @@ void init(int argc, char **argv)
        localtime((time_t *)&now.tv_sec);
        start_date = now;
 
+       init_task();
+       init_session();
        init_proto_http();
 
        cfg_polling_mechanism = POLL_USE_SELECT;  /* select() is always available */
@@ -654,10 +660,10 @@ void deinit(void)
     
        if (fdtab)            free(fdtab);
     
-       pool_destroy(pool_session);
+       pool_destroy2(pool2_session);
        pool_destroy(pool_buffer);
        pool_destroy(pool_requri);
-       pool_destroy(pool_task);
+       pool_destroy2(pool2_task);
        pool_destroy(pool_capture);
        pool_destroy(pool_appsess);
     
index 21d34801cc4e55609fb781a1aa6419c395f0e2a7..63bede3ee5079b3861ac5448bf3ea26c88995027 100644 (file)
@@ -1,7 +1,7 @@
 /*
  * Server management functions.
  *
- * Copyright 2000-2006 Willy Tarreau <w@1wt.eu>
+ * Copyright 2000-2007 Willy Tarreau <w@1wt.eu>
  *
  * This program is free software; you can redistribute it and/or
  * modify it under the terms of the GNU General Public License
@@ -26,7 +26,7 @@
 #include <proto/queue.h>
 
 
-void **pool_session = NULL;
+struct pool_head *pool2_session;
 
 /*
  * frees  the context associated to a session. It must have been removed first.
@@ -69,7 +69,15 @@ void session_free(struct session *s)
        if (txn->srv_cookie)
                pool_free(capture, txn->srv_cookie);
 
-       pool_free(session, s);
+       pool_free2(pool2_session, s);
+}
+
+
+/* perform minimal intializations, report 0 in case of error, 1 if OK. */
+int init_session()
+{
+       pool2_session = create_pool("session", sizeof(struct session), MEM_F_SHARED);
+       return pool2_session != NULL;
 }
 
 
index 41c0b2a2b3a5f2dd2d89b42cb306b1d16055fe85..182de2508c5cef43d4551415cbf57b8d13d1c9df 100644 (file)
@@ -11,6 +11,7 @@
  */
 
 #include <common/config.h>
+#include <common/memory.h>
 #include <common/mini-clist.h>
 #include <common/standard.h>
 #include <common/time.h>
 #include <import/bitops.h>
 #include <import/tree.h>
 
-
-void **pool_task= NULL;
-void **pool_tree64 = NULL;
 static struct ultree *stack[LLONGBITS];
 
+struct pool_head *pool2_task, *pool2_tree64;
+
 UL2TREE_HEAD(timer_wq);
 void *eternity_queue = NULL;
 void *run_queue = NULL;
 
+/* perform minimal intializations, report 0 in case of error, 1 if OK. */
+int init_task()
+{
+       pool2_task = create_pool("task", sizeof(struct task), MEM_F_SHARED);
+       pool2_tree64 = create_pool("tree64", sizeof(struct tree64), MEM_F_SHARED);
+       return pool2_task && pool2_tree64;
+}
+
 struct ultree *ul2tree_insert(struct ultree *root, unsigned long h, unsigned long l)
 {
        return __ul2tree_insert(root, h, l);