From 7b81563443963571f909503863866ea5b76a3912 Mon Sep 17 00:00:00 2001 From: Willy Tarreau Date: Fri, 21 Oct 2011 18:51:57 +0200 Subject: OPTIM/MINOR: move struct sockaddr_storage to the tail of structs Struct sockaddr_storage is huge (128 bytes) and severely impacts the cache. It also displaces other struct members, causing them to have larger relative offsets. By moving these few occurrences to the end of the structs which host them, we can reduce the code size by no less than 2 kB ! --- include/types/protocols.h | 3 ++- include/types/proxy.h | 18 ++++++++++-------- include/types/server.h | 19 ++++++++++--------- 3 files changed, 22 insertions(+), 18 deletions(-) diff --git a/include/types/protocols.h b/include/types/protocols.h index 212ecef..eba4874 100644 --- a/include/types/protocols.h +++ b/include/types/protocols.h @@ -101,7 +101,6 @@ struct listener { int state; /* state: NEW, INIT, ASSIGNED, LISTEN, READY, FULL */ int options; /* socket options : LI_O_* */ struct licounters *counters; /* statistics counters */ - struct sockaddr_storage addr; /* the address we listen to */ struct protocol *proto; /* protocol this listener belongs to */ int nbconn; /* current number of connections on this listener */ int maxconn; /* maximum connections allowed on this listener */ @@ -126,6 +125,8 @@ struct listener { char *interface; /* interface name or NULL */ int maxseg; /* for TCP, advertised MSS */ + /* warning: this struct is huge, keep it at the bottom */ + struct sockaddr_storage addr; /* the address we listen to */ struct { const char *file; /* file where the section appears */ int line; /* line where the section appears */ diff --git a/include/types/proxy.h b/include/types/proxy.h index d51eed1..46e03a1 100644 --- a/include/types/proxy.h +++ b/include/types/proxy.h @@ -191,7 +191,6 @@ struct proxy { unsigned int fe_req_ana, be_req_ana; /* bitmap of common request protocol analysers for the frontend and backend */ unsigned int fe_rsp_ana, be_rsp_ana; /* bitmap of common response protocol analysers for the frontend and backend */ int mode; /* mode = PR_MODE_TCP, PR_MODE_HTTP or PR_MODE_HEALTH */ - struct sockaddr_storage dispatch_addr; /* the default address to connect to */ union { struct proxy *be; /* default backend, or NULL if none set */ char *name; /* default backend name during config parse */ @@ -280,13 +279,6 @@ struct proxy { int conn_retries; /* maximum number of connect retries */ int cap; /* supported capabilities (PR_CAP_*) */ - struct sockaddr_storage source_addr; /* the address to which we want to bind for connect() */ -#if defined(CONFIG_HAP_CTTPROXY) || defined(CONFIG_HAP_LINUX_TPROXY) - struct sockaddr_storage tproxy_addr; /* non-local address we want to bind to for connect() */ - char *bind_hdr_name; /* bind to this header name if defined */ - int bind_hdr_len; /* length of the name of the header above */ - int bind_hdr_occ; /* occurrence number of header above: >0 = from first, <0 = from end, 0=disabled */ -#endif int iface_len; /* bind interface name length */ char *iface_name; /* bind interface name or NULL */ int (*accept)(struct session *s); /* application layer's accept() */ @@ -322,6 +314,16 @@ struct proxy { int uuid; /* universally unique proxy ID, used for SNMP */ unsigned int backlog; /* force the frontend's listen backlog */ unsigned int bind_proc; /* bitmask of processes using this proxy. 0 = all. */ + + /* warning: these structs are huge, keep them at the bottom */ + struct sockaddr_storage dispatch_addr; /* the default address to connect to */ + struct sockaddr_storage source_addr; /* the address to which we want to bind for connect() */ +#if defined(CONFIG_HAP_CTTPROXY) || defined(CONFIG_HAP_LINUX_TPROXY) + struct sockaddr_storage tproxy_addr; /* non-local address we want to bind to for connect() */ + char *bind_hdr_name; /* bind to this header name if defined */ + int bind_hdr_len; /* length of the name of the header above */ + int bind_hdr_occ; /* occurrence number of header above: >0 = from first, <0 = from end, 0=disabled */ +#endif struct error_snapshot invalid_req, invalid_rep; /* captures of last errors */ /* used only during configuration parsing */ diff --git a/include/types/server.h b/include/types/server.h index f829399..6b35c32 100644 --- a/include/types/server.h +++ b/include/types/server.h @@ -99,20 +99,13 @@ struct server { unsigned maxconn, minconn; /* max # of active sessions (0 = unlimited), min# for dynamic limit. */ int nbpend; /* number of pending connections */ int maxqueue; /* maximum number of pending connections allowed */ + struct freq_ctr sess_per_sec; /* sessions per second on this server */ struct srvcounters counters; /* statistics counters */ struct list pendconns; /* pending connections */ struct list actconns; /* active connections */ struct task *check; /* the task associated to the health check processing */ - struct sockaddr_storage addr; /* the address to connect to */ - struct sockaddr_storage source_addr; /* the address to which we want to bind for connect() */ -#if defined(CONFIG_HAP_CTTPROXY) || defined(CONFIG_HAP_LINUX_TPROXY) - struct sockaddr_storage tproxy_addr; /* non-local address we want to bind to for connect() */ - char *bind_hdr_name; /* bind to this header name if defined */ - int bind_hdr_len; /* length of the name of the header above */ - int bind_hdr_occ; /* occurrence number of header above: >0 = from first, <0 = from end, 0=disabled */ -#endif int iface_len; /* bind interface name length */ char *iface_name; /* bind interface name or NULL */ struct port_range *sport_range; /* optional per-server TCP source ports */ @@ -145,6 +138,15 @@ struct server { unsigned lb_nodes_now; /* number of lb_nodes placed in the tree (C-HASH) */ struct tree_occ *lb_nodes; /* lb_nodes_tot * struct tree_occ */ + /* warning, these structs are huge, keep them at the bottom */ + struct sockaddr_storage addr; /* the address to connect to */ + struct sockaddr_storage source_addr; /* the address to which we want to bind for connect() */ +#if defined(CONFIG_HAP_CTTPROXY) || defined(CONFIG_HAP_LINUX_TPROXY) + struct sockaddr_storage tproxy_addr; /* non-local address we want to bind to for connect() */ + char *bind_hdr_name; /* bind to this header name if defined */ + int bind_hdr_len; /* length of the name of the header above */ + int bind_hdr_occ; /* occurrence number of header above: >0 = from first, <0 = from end, 0=disabled */ +#endif unsigned down_time; /* total time the server was down */ time_t last_change; /* last time, when the state was changed */ struct timeval check_start; /* last health check start time */ @@ -152,7 +154,6 @@ struct server { short check_status, check_code; /* check result, check code */ char check_desc[HCHK_DESC_LEN]; /* health check descritpion */ - struct freq_ctr sess_per_sec; /* sessions per second on this server */ int puid; /* proxy-unique server ID, used for SNMP */ char *check_data; /* storage of partial check results */ -- 1.7.2.3