Skip to content

Commit

Permalink
Merge pull request #15266 from donaldsharp/packable
Browse files Browse the repository at this point in the history
2 memory optimizations
  • Loading branch information
riw777 authored Feb 1, 2024
2 parents a2caf2b + bb1e126 commit 398c700
Show file tree
Hide file tree
Showing 11 changed files with 246 additions and 231 deletions.
1 change: 1 addition & 0 deletions bgpd/bgp_memory.c
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ DEFINE_MTYPE(BGPD, BGP_ROUTE_EXTRA, "BGP ancillary route info");
DEFINE_MTYPE(BGPD, BGP_ROUTE_EXTRA_EVPN, "BGP extra info for EVPN");
DEFINE_MTYPE(BGPD, BGP_ROUTE_EXTRA_FS, "BGP extra info for flowspec");
DEFINE_MTYPE(BGPD, BGP_ROUTE_EXTRA_VRFLEAK, "BGP extra info for vrf leaking");
DEFINE_MTYPE(BGPD, BGP_ROUTE_EXTRA_VNC, "BGP extra info for vnc");
DEFINE_MTYPE(BGPD, BGP_CONN, "BGP connected");
DEFINE_MTYPE(BGPD, BGP_STATIC, "BGP static");
DEFINE_MTYPE(BGPD, BGP_ADVERTISE_ATTR, "BGP adv attr");
Expand Down
1 change: 1 addition & 0 deletions bgpd/bgp_memory.h
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ DECLARE_MTYPE(BGP_ROUTE_EXTRA);
DECLARE_MTYPE(BGP_ROUTE_EXTRA_EVPN);
DECLARE_MTYPE(BGP_ROUTE_EXTRA_FS);
DECLARE_MTYPE(BGP_ROUTE_EXTRA_VRFLEAK);
DECLARE_MTYPE(BGP_ROUTE_EXTRA_VNC);
DECLARE_MTYPE(BGP_CONN);
DECLARE_MTYPE(BGP_STATIC);
DECLARE_MTYPE(BGP_ADVERTISE_ATTR);
Expand Down
4 changes: 4 additions & 0 deletions bgpd/bgp_route.c
Original file line number Diff line number Diff line change
Expand Up @@ -263,6 +263,10 @@ void bgp_path_info_extra_free(struct bgp_path_info_extra **extra)
XFREE(MTYPE_BGP_ROUTE_EXTRA_FS, e->flowspec);
if (e->vrfleak)
XFREE(MTYPE_BGP_ROUTE_EXTRA_VRFLEAK, e->vrfleak);
#ifdef ENABLE_BGP_VNC
if (e->vnc)
XFREE(MTYPE_BGP_ROUTE_EXTRA_VNC, e->vnc);
#endif

XFREE(MTYPE_BGP_ROUTE_EXTRA, *extra);
}
Expand Down
56 changes: 30 additions & 26 deletions bgpd/bgp_route.h
Original file line number Diff line number Diff line change
Expand Up @@ -193,33 +193,9 @@ struct bgp_path_info_extra_vrfleak {
struct prefix nexthop_orig;
};

/* Ancillary information to struct bgp_path_info,
* used for uncommonly used data (aggregation, MPLS, etc.)
* and lazily allocated to save memory.
*/
struct bgp_path_info_extra {
/* Pointer to dampening structure. */
struct bgp_damp_info *damp_info;

/** List of aggregations that suppress this path. */
struct list *aggr_suppressors;

/* Nexthop reachability check. */
uint32_t igpmetric;

/* MPLS label(s) - VNI(s) for EVPN-VxLAN */
mpls_label_t label[BGP_MAX_LABELS];
uint32_t num_labels;

/* timestamp of the rib installation */
time_t bgp_rib_uptime;

/*For EVPN*/
struct bgp_path_info_extra_evpn *evpn;

#ifdef ENABLE_BGP_VNC
struct bgp_path_info_extra_vnc {
union {

struct {
void *rfapi_handle; /* export: NVE advertising this
route */
Expand All @@ -242,8 +218,36 @@ struct bgp_path_info_extra {
struct prefix aux_prefix; /* AFI_L2VPN: the IP addr,
if family set */
} import;

} vnc;
};
#endif

/* Ancillary information to struct bgp_path_info,
* used for uncommonly used data (aggregation, MPLS, etc.)
* and lazily allocated to save memory.
*/
struct bgp_path_info_extra {
/* Pointer to dampening structure. */
struct bgp_damp_info *damp_info;

/** List of aggregations that suppress this path. */
struct list *aggr_suppressors;

/* Nexthop reachability check. */
uint32_t igpmetric;

/* MPLS label(s) - VNI(s) for EVPN-VxLAN */
mpls_label_t label[BGP_MAX_LABELS];
uint32_t num_labels;

/* timestamp of the rib installation */
time_t bgp_rib_uptime;

/*For EVPN*/
struct bgp_path_info_extra_evpn *evpn;

#ifdef ENABLE_BGP_VNC
struct bgp_path_info_extra_vnc *vnc;
#endif

/* For flowspec*/
Expand Down
59 changes: 29 additions & 30 deletions bgpd/rfapi/rfapi.c
Original file line number Diff line number Diff line change
Expand Up @@ -366,20 +366,19 @@ void del_vnc_route(struct rfapi_descriptor *rfd,

for (bpi = (bn ? bgp_dest_get_bgp_path_info(bn) : NULL); bpi;
bpi = bpi->next) {

vnc_zlog_debug_verbose(
"%s: trying bpi=%p, bpi->peer=%p, bpi->type=%d, bpi->sub_type=%d, bpi->extra->vnc.export.rfapi_handle=%p, local_pref=%" PRIu64,
__func__, bpi, bpi->peer, bpi->type, bpi->sub_type,
(bpi->extra ? bpi->extra->vnc.export.rfapi_handle
(bpi->extra ? bpi->extra->vnc->vnc.export.rfapi_handle
: NULL),
CHECK_FLAG(bpi->attr->flag,
ATTR_FLAG_BIT(BGP_ATTR_LOCAL_PREF)
? bpi->attr->local_pref : 0));

if (bpi->peer == peer && bpi->type == type
&& bpi->sub_type == sub_type && bpi->extra
&& bpi->extra->vnc.export.rfapi_handle == (void *)rfd) {
? bpi->attr->local_pref
: 0));

if (bpi->peer == peer && bpi->type == type &&
bpi->sub_type == sub_type && bpi->extra &&
bpi->extra->vnc->vnc.export.rfapi_handle == (void *)rfd) {
vnc_zlog_debug_verbose("%s: matched it", __func__);

break;
Expand All @@ -392,8 +391,8 @@ void del_vnc_route(struct rfapi_descriptor *rfd,
* route. Leave the route itself in place.
* TBD add return code reporting of success/failure
*/
if (!bpi || !bpi->extra
|| !bpi->extra->vnc.export.local_nexthops) {
if (!bpi || !bpi->extra ||
!bpi->extra->vnc->vnc.export.local_nexthops) {
/*
* no local nexthops
*/
Expand All @@ -409,16 +408,16 @@ void del_vnc_route(struct rfapi_descriptor *rfd,
struct listnode *node;
struct rfapi_nexthop *pLnh = NULL;

for (ALL_LIST_ELEMENTS_RO(bpi->extra->vnc.export.local_nexthops,
for (ALL_LIST_ELEMENTS_RO(bpi->extra->vnc->vnc.export
.local_nexthops,
node, pLnh)) {

if (prefix_same(&pLnh->addr, &lnh->addr)) {
break;
}
}

if (pLnh) {
listnode_delete(bpi->extra->vnc.export.local_nexthops,
listnode_delete(bpi->extra->vnc->vnc.export.local_nexthops,
pLnh);

/* silly rabbit, listnode_delete doesn't invoke
Expand Down Expand Up @@ -459,8 +458,8 @@ void del_vnc_route(struct rfapi_descriptor *rfd,
/*
* Delete local_nexthops list
*/
if (bpi->extra && bpi->extra->vnc.export.local_nexthops)
list_delete(&bpi->extra->vnc.export.local_nexthops);
if (bpi->extra && bpi->extra->vnc->vnc.export.local_nexthops)
list_delete(&bpi->extra->vnc->vnc.export.local_nexthops);

bgp_aggregate_decrement(bgp, p, bpi, afi, safi);
bgp_path_info_delete(bn, bpi);
Expand Down Expand Up @@ -902,11 +901,10 @@ void add_vnc_route(struct rfapi_descriptor *rfd, /* cookie, VPN UN addr, peer */
*/
for (bpi = bgp_dest_get_bgp_path_info(bn); bpi; bpi = bpi->next) {
/* probably only need to check
* bpi->extra->vnc.export.rfapi_handle */
if (bpi->peer == rfd->peer && bpi->type == type
&& bpi->sub_type == sub_type && bpi->extra
&& bpi->extra->vnc.export.rfapi_handle == (void *)rfd) {

* bpi->extra->vnc->vnc.export.rfapi_handle */
if (bpi->peer == rfd->peer && bpi->type == type &&
bpi->sub_type == sub_type && bpi->extra &&
bpi->extra->vnc->vnc.export.rfapi_handle == (void *)rfd) {
break;
}
}
Expand All @@ -918,11 +916,11 @@ void add_vnc_route(struct rfapi_descriptor *rfd, /* cookie, VPN UN addr, peer */
* what is advertised via BGP
*/
if (lnh) {
if (!bpi->extra->vnc.export.local_nexthops) {
if (!bpi->extra->vnc->vnc.export.local_nexthops) {
/* TBD make arrangements to free when needed */
bpi->extra->vnc.export.local_nexthops =
bpi->extra->vnc->vnc.export.local_nexthops =
list_new();
bpi->extra->vnc.export.local_nexthops->del =
bpi->extra->vnc->vnc.export.local_nexthops->del =
rfapi_nexthop_free;
}

Expand All @@ -932,10 +930,9 @@ void add_vnc_route(struct rfapi_descriptor *rfd, /* cookie, VPN UN addr, peer */
struct listnode *node;
struct rfapi_nexthop *pLnh = NULL;

for (ALL_LIST_ELEMENTS_RO(
bpi->extra->vnc.export.local_nexthops,
node, pLnh)) {

for (ALL_LIST_ELEMENTS_RO(bpi->extra->vnc->vnc.export
.local_nexthops,
node, pLnh)) {
if (prefix_same(&pLnh->addr, &lnh->addr)) {
break;
}
Expand All @@ -946,9 +943,9 @@ void add_vnc_route(struct rfapi_descriptor *rfd, /* cookie, VPN UN addr, peer */
*/
if (!pLnh) {
pLnh = rfapi_nexthop_new(lnh);
listnode_add(
bpi->extra->vnc.export.local_nexthops,
pLnh);
listnode_add(bpi->extra->vnc->vnc.export
.local_nexthops,
pLnh);
}
}

Expand Down Expand Up @@ -1020,7 +1017,9 @@ void add_vnc_route(struct rfapi_descriptor *rfd, /* cookie, VPN UN addr, peer */

/* save backref to rfapi handle */
bgp_path_info_extra_get(new);
new->extra->vnc.export.rfapi_handle = (void *)rfd;
new->extra->vnc = XCALLOC(MTYPE_BGP_ROUTE_EXTRA_VNC,
sizeof(struct bgp_path_info_extra_vnc));
new->extra->vnc->vnc.export.rfapi_handle = (void *)rfd;
encode_label(label_val, &new->extra->label[0]);

/* debug */
Expand Down
Loading

0 comments on commit 398c700

Please sign in to comment.