]> git.ipfire.org Git - thirdparty/haproxy.git/commitdiff
[MAJOR] call garbage collector when doing soft stop
authorWilly Tarreau <w@1wt.eu>
Sun, 13 May 2007 22:39:29 +0000 (00:39 +0200)
committerWilly Tarreau <w@1wt.eu>
Sun, 13 May 2007 22:39:29 +0000 (00:39 +0200)
When we're interrupted by another instance, it is very likely
that the other one will need some memory. Now we know how to
free what is not used, so let's do it.

Also only free non-null pointers. Previously, pool_destroy()
did implicitly check for this case which was incidentely
needed.

include/common/memory.h
src/haproxy.c
src/memory.c
src/proxy.c

index 66f789e25a1dda1bfd09656d77f85f721ee4a431..835d79df08efbe5ee765d7a3a2816db70bb5f790 100644 (file)
@@ -160,7 +160,7 @@ void pool_gc2();
  * This function destroys a pull by freeing it completely.
  * This should be called only under extreme circumstances.
  */
-void pool_destroy2(struct pool_head *pool);
+void *pool_destroy2(struct pool_head *pool);
 
 /*
  * Returns a pointer to type <type> taken from the
index 4e22e1920dc527d430839a5d01ef8918f7418f75..a86abeb3196d3a47f416d05e4d69d030c4ab1470 100644 (file)
@@ -203,6 +203,7 @@ void usage(char *name)
 void sig_soft_stop(int sig)
 {
        soft_stop();
+       pool_gc2();
        signal(sig, SIG_IGN);
 }
 
@@ -212,6 +213,7 @@ void sig_soft_stop(int sig)
 void sig_pause(int sig)
 {
        pause_proxies();
+       pool_gc2();
        signal(sig, sig_pause);
 }
 
@@ -318,6 +320,7 @@ void sig_int(int sig)
           0 GRACE time
        */
        fast_stop();
+       pool_gc2();
        /* If we are killed twice, we decide to die*/
        signal(sig, SIG_DFL);
 }
@@ -330,6 +333,7 @@ void sig_term(int sig)
           0 GRACE time
        */
        fast_stop();
+       pool_gc2();
        /* If we are killed twice, we decide to die*/
        signal(sig, SIG_DFL);
 }
@@ -580,7 +584,7 @@ void init(int argc, char **argv)
 
 void deinit(void)
 {
-       struct proxy *p = proxy;
+       struct proxy *p = proxy, *p0;
        struct cap_hdr *h,*h_next;
        struct server *s,*s_next;
        struct listener *l,*l_next;
@@ -654,7 +658,9 @@ void deinit(void)
        
                pool_destroy2(p->req_cap_pool);
                pool_destroy2(p->rsp_cap_pool);
+               p0 = p;
                p = p->next;
+               free(p0);
        }/* end while(p) */
     
        if (global.chroot)    free(global.chroot);
index 589d1d2706471068bab7f85a486fca9baef7bd3f..8009227143e737a8963670afe2a0214870a4a6e8 100644 (file)
@@ -103,6 +103,9 @@ void *pool_refill_alloc(struct pool_head *pool)
 void pool_flush2(struct pool_head *pool)
 {
        void *temp, *next;
+       if (!pool)
+               return;
+
        next = pool->free_list;
        while (next) {
                temp = next;
@@ -141,11 +144,15 @@ void pool_gc2()
 /*
  * This function destroys a pull by freeing it completely.
  * This should be called only under extreme circumstances.
+ * It always returns NULL, easing the clearing of the old pointer.
  */
-void pool_destroy2(struct pool_head *pool)
+void *pool_destroy2(struct pool_head *pool)
 {
-       pool_flush2(pool);
-       FREE(pool);
+       if (pool) {
+               pool_flush2(pool);
+               FREE(pool);
+       }
+       return NULL;
 }
 
 /* Dump statistics on pools usage.
index dd7f993e34e8828c633ceff9aeb9cf0435ecba7c..7d4b2ec08bde3c43eb50fd9c86b4e94cced85c2c 100644 (file)
@@ -19,6 +19,7 @@
 #include <common/defaults.h>
 #include <common/compat.h>
 #include <common/config.h>
+#include <common/memory.h>
 #include <common/time.h>
 
 #include <types/global.h>
@@ -230,6 +231,8 @@ void maintain_proxies(struct timeval *next)
                                                listeners--;
                                        }
                                        p->state = PR_STSTOPPED;
+                                       /* try to free more memory */
+                                       pool_gc2();
                                }
                                else {
                                        tv_bound(next, &p->stop_time);