MEDIUM: backend: move all LB algo parameters into an union

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).
This commit is contained in:
Willy Tarreau 2019-01-14 16:55:42 +01:00
parent 76e84f5091
commit 0cac26cd88
2 changed files with 9 additions and 6 deletions

View File

@ -138,6 +138,13 @@
/* 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). */

View 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);