[MAJOR] migrated task, tree64 and session to pool2
task and tree64 are already very close in size and are merged together.
Overall performance gained slightly by this simple change.
diff --git a/src/appsession.c b/src/appsession.c
index 72b7e40..bf26510 100644
--- a/src/appsession.c
+++ b/src/appsession.c
@@ -111,7 +111,7 @@
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;
diff --git a/src/cfgparse.c b/src/cfgparse.c
index 1edaa8f..6dd7ab6 100644
--- a/src/cfgparse.c
+++ b/src/cfgparse.c
@@ -2488,7 +2488,7 @@
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 @@
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;
}
diff --git a/src/client.c b/src/client.c
index 52b281b..6afb206 100644
--- a/src/client.c
+++ b/src/client.c
@@ -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 @@
}
}
- 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 @@
(((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 @@
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 @@
(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 @@
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 @@
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 @@
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 @@
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 @@
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;
}
diff --git a/src/haproxy.c b/src/haproxy.c
index 0acf75f..18bef85 100644
--- a/src/haproxy.c
+++ b/src/haproxy.c
@@ -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 @@
);
}
#endif
+ /* dump memory usage then free everything possible */
+ dump_pools();
+ pool_gc2();
}
#ifdef DEBUG_MEMORY
@@ -370,6 +374,8 @@
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 @@
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);
diff --git a/src/session.c b/src/session.c
index 21d3480..63bede3 100644
--- a/src/session.c
+++ b/src/session.c
@@ -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 @@
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;
}
diff --git a/src/task.c b/src/task.c
index 41c0b2a..182de25 100644
--- a/src/task.c
+++ b/src/task.c
@@ -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>
@@ -23,15 +24,22 @@
#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);