]> git.ipfire.org Git - thirdparty/haproxy.git/commitdiff
MEDIUM: backend: move all LB algo parameters into an union
authorWilly Tarreau <w@1wt.eu>
Mon, 14 Jan 2019 15:55:42 +0000 (16:55 +0100)
committerWilly Tarreau <w@1wt.eu>
Mon, 14 Jan 2019 18:33:17 +0000 (19:33 +0100)
Since all of them are exclusive, let's move them to an union instead
of eating memory with the sum of all of them. We're using a transparent
union to limit the code changes.

Doing so reduces the struct lbprm from 392 bytes to 372, and thanks
to these changes, the struct proxy is now down to 6480 bytes vs 6624
before the changes (144 bytes saved per proxy).

include/types/backend.h
src/haproxy.c

index ea38ed2c2a4c89cb8276f9cd8ffd70b9c5871446..22e5f21e68de42cd90973638140e8bebcbef3914 100644 (file)
 
 /* LB parameters for all algorithms */
 struct lbprm {
+       union { /* LB parameters depending on the algo type */
+               struct lb_map map;
+               struct lb_fwrr fwrr;
+               struct lb_fwlc fwlc;
+               struct lb_chash chash;
+               struct lb_fas fas;
+       };
        int algo;                       /* load balancing algorithm and variants: BE_LB_* */
        int tot_wact, tot_wbck;         /* total effective weights of active and backup servers */
        int tot_weight;                 /* total effective weight of servers participating to LB */
@@ -151,11 +158,6 @@ struct lbprm {
        int   arg_opt2;                 /* extra option 2 for the LB algo (algo-specific) */
        int   arg_opt3;                 /* extra option 3 for the LB algo (algo-specific) */
        struct server *fbck;            /* first backup server when !PR_O_USE_ALL_BK, or NULL */
-       struct lb_map map;              /* LB parameters for map-based algorithms */
-       struct lb_fwrr fwrr;
-       struct lb_fwlc fwlc;
-       struct lb_chash chash;
-       struct lb_fas fas;
        __decl_hathreads(HA_SPINLOCK_T lock);
 
        /* Call backs for some actions. Any of them may be NULL (thus should be ignored). */
index dbc2adabc88336355e47127c70e79260fc44d398..8ae5f33198121584e84ddc208786fbdec5a76c55 100644 (file)
@@ -2258,7 +2258,8 @@ void deinit(void)
                free(p->conf.lfs_file);
                free(p->conf.uniqueid_format_string);
                free(p->conf.uif_file);
-               free(p->lbprm.map.srv);
+               if ((p->lbprm.algo & BE_LB_LKUP) == BE_LB_LKUP_MAP)
+                       free(p->lbprm.map.srv);
 
                if (p->conf.logformat_sd_string != default_rfc5424_sd_log_format)
                        free(p->conf.logformat_sd_string);