From 7133cce19621746cba36e142060816fd6de7b64a Mon Sep 17 00:00:00 2001 From: Donatas Abraitis Date: Mon, 29 Jan 2024 15:29:25 +0200 Subject: [PATCH 1/6] bgpd: Optimize memory usage for bgp_notify struct ``` struct bgp_notify { uint8_t code; /* 0 1 */ uint8_t subcode; /* 1 1 */ bgp_size_t length; /* 2 2 */ _Bool hard_reset; /* 4 1 */ /* XXX 3 bytes hole, try to pack */ char * data; /* 8 8 */ uint8_t * raw_data; /* 16 8 */ /* size: 24, cachelines: 1, members: 6 */ /* sum members: 21, holes: 1, sum holes: 3 */ /* last cacheline: 24 bytes */ }; /* saved 16 bytes! */ ``` Signed-off-by: Donatas Abraitis --- bgpd/bgpd.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/bgpd/bgpd.h b/bgpd/bgpd.h index a1593421beb6..8bde9999f9bf 100644 --- a/bgpd/bgpd.h +++ b/bgpd/bgpd.h @@ -888,10 +888,10 @@ struct peer_group { struct bgp_notify { uint8_t code; uint8_t subcode; - char *data; bgp_size_t length; - uint8_t *raw_data; bool hard_reset; + char *data; + uint8_t *raw_data; }; /* Next hop self address. */ From 89e124f042f514b5ce0e3dc39796613152e225b8 Mon Sep 17 00:00:00 2001 From: Donatas Abraitis Date: Mon, 29 Jan 2024 15:37:23 +0200 Subject: [PATCH 2/6] bgpd: Optimize memory usage for bgp_nlri struct ``` struct bgp_nlri { uint16_t afi; /* 0 2 */ uint8_t safi; /* 2 1 */ /* XXX 1 byte hole, try to pack */ bgp_size_t length; /* 4 2 */ /* XXX 2 bytes hole, try to pack */ uint8_t * nlri; /* 8 8 */ /* size: 16, cachelines: 1, members: 4 */ /* sum members: 13, holes: 2, sum holes: 3 */ /* last cacheline: 16 bytes */ }; /* saved 8 bytes! */ ``` Signed-off-by: Donatas Abraitis --- bgpd/bgpd.h | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/bgpd/bgpd.h b/bgpd/bgpd.h index 8bde9999f9bf..385a2f01e889 100644 --- a/bgpd/bgpd.h +++ b/bgpd/bgpd.h @@ -1890,11 +1890,11 @@ struct bgp_nlri { /* SAFI. */ uint8_t safi; /* iana_safi_t */ - /* Pointer to NLRI byte stream. */ - uint8_t *nlri; - /* Length of whole NLRI. */ bgp_size_t length; + + /* Pointer to NLRI byte stream. */ + uint8_t *nlri; }; /* BGP versions. */ From 4821e7a0d88ce1a70c1a27398b040817e5941238 Mon Sep 17 00:00:00 2001 From: Donatas Abraitis Date: Mon, 29 Jan 2024 15:56:07 +0200 Subject: [PATCH 3/6] bgpd: Optimize memory usage for attr struct ``` struct attr { struct aspath * aspath; /* 0 8 */ struct community * community; /* 8 8 */ long unsigned int refcnt; /* 16 8 */ _uint64_t flag; /* 24 8 */ struct in_addr nexthop; /* 32 4 */ uint32_t med; /* 36 4 */ uint32_t local_pref; /* 40 4 */ ifindex_t nh_ifindex; /* 44 4 */ uint8_t origin; /* 48 1 */ uint8_t es_flags; /* 49 1 */ uint8_t router_flag; /* 50 1 */ uint8_t default_gw; /* 51 1 */ enum pta_type pmsi_tnl_type; /* 52 4 */ uint32_t rmap_change_flags; /* 56 4 */ struct in6_addr mp_nexthop_global; /* 60 16 */ /* --- cacheline 1 boundary (64 bytes) was 12 bytes ago --- */ struct in6_addr mp_nexthop_local; /* 76 16 */ ifindex_t nh_lla_ifindex; /* 92 4 */ struct ecommunity * ecommunity; /* 96 8 */ struct ecommunity * ipv6_ecommunity; /* 104 8 */ struct lcommunity * lcommunity; /* 112 8 */ struct cluster_list * cluster1; /* 120 8 */ /* --- cacheline 2 boundary (128 bytes) --- */ struct transit * transit; /* 128 8 */ struct in_addr mp_nexthop_global_in; /* 136 4 */ struct in_addr aggregator_addr; /* 140 4 */ struct in_addr originator_id; /* 144 4 */ uint32_t weight; /* 148 4 */ as_t aggregator_as; /* 152 4 */ uint8_t mp_nexthop_len; /* 156 1 */ uint8_t mp_nexthop_prefer_global; /* 157 1 */ uint8_t sticky; /* 158 1 */ uint8_t distance; /* 159 1 */ uint16_t encap_tunneltype; /* 160 2 */ uint8_t df_alg; /* 162 1 */ /* XXX 1 byte hole, try to pack */ route_tag_t tag; /* 164 4 */ uint32_t label_index; /* 168 4 */ mpls_label_t label; /* 172 4 */ struct bgp_attr_srv6_vpn * srv6_vpn; /* 176 8 */ struct bgp_attr_srv6_l3vpn * srv6_l3vpn; /* 184 8 */ /* --- cacheline 3 boundary (192 bytes) --- */ struct bgp_attr_encap_subtlv * encap_subtlvs; /* 192 8 */ struct bgp_attr_encap_subtlv * vnc_subtlvs; /* 200 8 */ struct bgp_route_evpn evpn_overlay; /* 208 36 */ uint32_t mm_seqnum; /* 244 4 */ uint32_t mm_sync_seqnum; /* 248 4 */ struct ethaddr rmac; /* 252 6 */ /* --- cacheline 4 boundary (256 bytes) was 2 bytes ago --- */ uint16_t df_pref; /* 258 2 */ uint32_t rmap_table_id; /* 260 4 */ uint32_t link_bw; /* 264 4 */ esi_t esi; /* 268 10 */ /* XXX 2 bytes hole, try to pack */ uint32_t srte_color; /* 280 4 */ uint32_t otc; /* 284 4 */ enum nexthop_types_t nh_type; /* 288 4 */ enum blackhole_type bh_type; /* 292 4 */ _uint64_t aigp_metric; /* 296 8 */ /* size: 304, cachelines: 5, members: 53 */ /* sum members: 301, holes: 2, sum holes: 3 */ /* last cacheline: 48 bytes */ }; /* saved 16 bytes! */ ``` Signed-off-by: Donatas Abraitis --- bgpd/bgp_attr.h | 87 +++++++++++++++++++++++++------------------------ 1 file changed, 44 insertions(+), 43 deletions(-) diff --git a/bgpd/bgp_attr.h b/bgpd/bgp_attr.h index d30155e6dba0..9ac0c9854d44 100644 --- a/bgpd/bgp_attr.h +++ b/bgpd/bgp_attr.h @@ -159,6 +159,45 @@ struct attr { /* Path origin attribute */ uint8_t origin; + /* ES info */ + uint8_t es_flags; + /* Path is not "locally-active" on the advertising VTEP. This is + * translated into an ARP-ND ECOM. + */ +#define ATTR_ES_PROXY_ADVERT (1 << 0) + /* Destination ES is present locally. This flag is set on local + * paths and sync paths + */ +#define ATTR_ES_IS_LOCAL (1 << 1) + /* There are one or more non-best paths from ES peers. Note that + * this flag is only set on the local MAC-IP paths in the VNI + * route table (not set in the global routing table). And only + * non-proxy advertisements from an ES peer can result in this + * flag being set. + */ +#define ATTR_ES_PEER_ACTIVE (1 << 2) + /* There are one or more non-best proxy paths from ES peers */ +#define ATTR_ES_PEER_PROXY (1 << 3) + /* An ES peer has router bit set - only applicable if + * ATTR_ES_PEER_ACTIVE is set + */ +#define ATTR_ES_PEER_ROUTER (1 << 4) + + /* These two flags are only set on L3 routes installed in a + * VRF as a result of EVPN MAC-IP route + * XXX - while splitting up per-family attrs these need to be + * classified as non-EVPN + */ +#define ATTR_ES_L3_NHG_USE (1 << 5) +#define ATTR_ES_L3_NHG_ACTIVE (1 << 6) +#define ATTR_ES_L3_NHG (ATTR_ES_L3_NHG_USE | ATTR_ES_L3_NHG_ACTIVE) + + /* NA router flag (R-bit) support in EVPN */ + uint8_t router_flag; + + /* Distance as applied by Route map */ + uint8_t distance; + /* PMSI tunnel type (RFC 6514). */ enum pta_type pmsi_tnl_type; @@ -214,42 +253,6 @@ struct attr { /* Flag for default gateway extended community in EVPN */ uint8_t default_gw; - /* NA router flag (R-bit) support in EVPN */ - uint8_t router_flag; - - /* ES info */ - uint8_t es_flags; - /* Path is not "locally-active" on the advertising VTEP. This is - * translated into an ARP-ND ECOM. - */ -#define ATTR_ES_PROXY_ADVERT (1 << 0) - /* Destination ES is present locally. This flag is set on local - * paths and sync paths - */ -#define ATTR_ES_IS_LOCAL (1 << 1) - /* There are one or more non-best paths from ES peers. Note that - * this flag is only set on the local MAC-IP paths in the VNI - * route table (not set in the global routing table). And only - * non-proxy advertisements from an ES peer can result in this - * flag being set. - */ -#define ATTR_ES_PEER_ACTIVE (1 << 2) - /* There are one or more non-best proxy paths from ES peers */ -#define ATTR_ES_PEER_PROXY (1 << 3) - /* An ES peer has router bit set - only applicable if - * ATTR_ES_PEER_ACTIVE is set - */ -#define ATTR_ES_PEER_ROUTER (1 << 4) - - /* These two flags are only set on L3 routes installed in a - * VRF as a result of EVPN MAC-IP route - * XXX - while splitting up per-family attrs these need to be - * classified as non-EVPN - */ -#define ATTR_ES_L3_NHG_USE (1 << 5) -#define ATTR_ES_L3_NHG_ACTIVE (1 << 6) -#define ATTR_ES_L3_NHG (ATTR_ES_L3_NHG_USE | ATTR_ES_L3_NHG_ACTIVE) - /* route tag */ route_tag_t tag; @@ -259,13 +262,16 @@ struct attr { /* MPLS label */ mpls_label_t label; + /* EVPN DF preference for DF election on local ESs */ + uint16_t df_pref; + uint8_t df_alg; + /* SRv6 VPN SID */ struct bgp_attr_srv6_vpn *srv6_vpn; /* SRv6 L3VPN SID */ struct bgp_attr_srv6_l3vpn *srv6_l3vpn; - uint16_t encap_tunneltype; /* grr */ struct bgp_attr_encap_subtlv *encap_subtlvs; /* rfc5512 */ #ifdef ENABLE_BGP_VNC @@ -287,8 +293,7 @@ struct attr { /* EVPN local router-mac */ struct ethaddr rmac; - /* Distance as applied by Route map */ - uint8_t distance; + uint16_t encap_tunneltype; /* rmap set table */ uint32_t rmap_table_id; @@ -302,10 +307,6 @@ struct attr { /* SR-TE Color */ uint32_t srte_color; - /* EVPN DF preference and algorithm for DF election on local ESs */ - uint16_t df_pref; - uint8_t df_alg; - /* Nexthop type */ enum nexthop_types_t nh_type; From 0804038916212cf8902595aeab016877e3b08bb2 Mon Sep 17 00:00:00 2001 From: Donatas Abraitis Date: Mon, 29 Jan 2024 16:00:07 +0200 Subject: [PATCH 4/6] bgpd: Optimize memory usage for bgp_static struct ``` struct bgp_static { int backdoor; /* 0 4 */ uint32_t label_index; /* 4 4 */ uint8_t valid; /* 8 1 */ /* XXX 1 byte hole, try to pack */ uint16_t encap_tunneltype; /* 10 2 */ uint32_t igpmetric; /* 12 4 */ struct in_addr igpnexthop; /* 16 4 */ uint32_t atomic; /* 20 4 */ struct { char * name; /* 24 8 */ struct route_map * map; /* 32 8 */ } rmap; /* 24 16 */ struct prefix_rd prd __attribute__((__aligned__(8))); /* 40 16 */ char * prd_pretty; /* 56 8 */ /* --- cacheline 1 boundary (64 bytes) --- */ mpls_label_t label; /* 64 4 */ /* XXX 4 bytes hole, try to pack */ esi_t * eth_s_id; /* 72 8 */ struct ethaddr * router_mac; /* 80 8 */ struct prefix gatewayIp __attribute__((__aligned__(8))); /* 88 56 */ /* size: 144, cachelines: 3, members: 14 */ /* sum members: 139, holes: 2, sum holes: 5 */ /* forced alignments: 2 */ /* last cacheline: 16 bytes */ } __attribute__((__aligned__(8))); /* saved 8 bytes! */ ``` Signed-off-by: Donatas Abraitis --- bgpd/bgp_route.h | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/bgpd/bgp_route.h b/bgpd/bgp_route.h index 0599e8dce1f0..a3f7ba2d76e8 100644 --- a/bgpd/bgp_route.h +++ b/bgpd/bgp_route.h @@ -369,6 +369,8 @@ struct bgp_static { /* Import check status. */ uint8_t valid; + uint16_t encap_tunneltype; + /* IGP metric. */ uint32_t igpmetric; @@ -394,7 +396,6 @@ struct bgp_static { /* EVPN */ esi_t *eth_s_id; struct ethaddr *router_mac; - uint16_t encap_tunneltype; struct prefix gatewayIp; }; From a699cc1796db61601b9246a7439126ced5fe2e9f Mon Sep 17 00:00:00 2001 From: Donatas Abraitis Date: Mon, 29 Jan 2024 16:18:54 +0200 Subject: [PATCH 5/6] bgpd: Optimize memory usage for bgp_aggregate struct ``` struct bgp_aggregate { uint8_t summary_only; /* 0 1 */ uint8_t as_set; /* 1 1 */ uint8_t origin; /* 2 1 */ _Bool med_mismatched; /* 3 1 */ _Bool med_initialized; /* 4 1 */ _Bool match_med; /* 5 1 */ /* XXX 2 bytes hole, try to pack */ struct { char * name; /* 8 8 */ struct route_map * map; /* 16 8 */ } rmap; /* 8 16 */ long unsigned int count; /* 24 8 */ long unsigned int incomplete_origin_count; /* 32 8 */ long unsigned int egp_origin_count; /* 40 8 */ struct hash * community_hash; /* 48 8 */ struct hash * ecommunity_hash; /* 56 8 */ /* --- cacheline 1 boundary (64 bytes) --- */ struct hash * lcommunity_hash; /* 64 8 */ struct hash * aspath_hash; /* 72 8 */ struct community * community; /* 80 8 */ struct ecommunity * ecommunity; /* 88 8 */ struct lcommunity * lcommunity; /* 96 8 */ struct aspath * aspath; /* 104 8 */ safi_t safi; /* 112 4 */ uint32_t med_matched_value; /* 116 4 */ char * suppress_map_name; /* 120 8 */ /* --- cacheline 2 boundary (128 bytes) --- */ struct route_map * suppress_map; /* 128 8 */ /* size: 136, cachelines: 3, members: 22 */ /* sum members: 134, holes: 1, sum holes: 2 */ /* last cacheline: 8 bytes */ }; ``` Signed-off-by: Donatas Abraitis --- bgpd/bgp_route.h | 21 +++++++++++---------- 1 file changed, 11 insertions(+), 10 deletions(-) diff --git a/bgpd/bgp_route.h b/bgpd/bgp_route.h index a3f7ba2d76e8..fde3e861c43a 100644 --- a/bgpd/bgp_route.h +++ b/bgpd/bgp_route.h @@ -416,6 +416,17 @@ struct bgp_aggregate { /* AS set generation. */ uint8_t as_set; + /* Optional modify flag to override ORIGIN */ + uint8_t origin; + + /** Are there MED mismatches? */ + bool med_mismatched; + /* MED matching state. */ + /** Did we get the first MED value? */ + bool med_initialized; + /** Match only equal MED. */ + bool match_med; + /* Route-map for aggregated route. */ struct { char *name; @@ -431,9 +442,6 @@ struct bgp_aggregate { /* Count of routes of origin type egp under this aggregate. */ unsigned long egp_origin_count; - /* Optional modify flag to override ORIGIN */ - uint8_t origin; - /* Hash containing the communities of all the * routes under this aggregate. */ @@ -469,13 +477,6 @@ struct bgp_aggregate { /* SAFI configuration. */ safi_t safi; - /** Match only equal MED. */ - bool match_med; - /* MED matching state. */ - /** Did we get the first MED value? */ - bool med_initialized; - /** Are there MED mismatches? */ - bool med_mismatched; /** MED value found in current group. */ uint32_t med_matched_value; From 48856741bd7583af2a37740e197e8a198df20b91 Mon Sep 17 00:00:00 2001 From: Donatas Abraitis Date: Mon, 29 Jan 2024 16:21:21 +0200 Subject: [PATCH 6/6] bgpd: Optimize memory usage for bgp_damp_config struct ``` struct bgp_damp_config { unsigned int suppress_value; /* 0 4 */ unsigned int reuse_limit; /* 4 4 */ time_t max_suppress_time; /* 8 8 */ time_t half_life; /* 16 8 */ unsigned int reuse_list_size; /* 24 4 */ unsigned int reuse_index_size; /* 28 4 */ unsigned int ceiling; /* 32 4 */ unsigned int decay_rate_per_tick; /* 36 4 */ unsigned int decay_array_size; /* 40 4 */ unsigned int reuse_scale_factor; /* 44 4 */ double scale_factor; /* 48 8 */ double * decay_array; /* 56 8 */ /* --- cacheline 1 boundary (64 bytes) --- */ int * reuse_index; /* 64 8 */ struct bgp_damp_info * * reuse_list; /* 72 8 */ int reuse_offset; /* 80 4 */ safi_t safi; /* 84 4 */ struct bgp_damp_info * no_reuse_list; /* 88 8 */ struct event * t_reuse; /* 96 8 */ afi_t afi; /* 104 4 */ /* size: 112, cachelines: 2, members: 19 */ /* padding: 4 */ /* last cacheline: 48 bytes */ }; /* saved 8 bytes! */ ``` Signed-off-by: Donatas Abraitis --- bgpd/bgp_damp.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/bgpd/bgp_damp.h b/bgpd/bgp_damp.h index 4aff52c09c98..6033c34bfdc8 100644 --- a/bgpd/bgp_damp.h +++ b/bgpd/bgp_damp.h @@ -74,8 +74,8 @@ struct bgp_damp_config { unsigned int ceiling; /* Max value a penalty can attain */ unsigned int decay_rate_per_tick; /* Calculated from half-life */ unsigned int decay_array_size; /* Calculated using config parameters */ - double scale_factor; unsigned int reuse_scale_factor; + double scale_factor; /* Decay array per-set based. */ double *decay_array; @@ -86,6 +86,7 @@ struct bgp_damp_config { /* Reuse list array per-set based. */ struct bgp_damp_info **reuse_list; int reuse_offset; + safi_t safi; /* All dampening information which is not on reuse list. */ struct bgp_damp_info *no_reuse_list; @@ -94,7 +95,6 @@ struct bgp_damp_config { struct event *t_reuse; afi_t afi; - safi_t safi; }; #define BGP_DAMP_NONE 0