Message ID | 20210520190219.758420-1-i.maximets@ovn.org |
---|---|
State | Accepted |
Headers | show |
Series | [ovs-dev] northd: Avoid memory reallocation while building lb rules. | expand |
On 5/20/21 9:02 PM, Ilya Maximets wrote: > This is one of the hottest points in the northd in case of big number > of load balancers and we're reallocating matches and actions several > times for each vIP for each load balancer. > > Fix that by re-using the allocated memory and just clearing dynamic > strings for all subsequnet IPs. > > Signed-off-by: Ilya Maximets <i.maximets@ovn.org> > --- Looks good to me, thanks! Acked-by: Dumitru Ceara <dceara@redhat.com>
On Tue, May 25, 2021 at 4:46 AM Dumitru Ceara <dceara@redhat.com> wrote: > > On 5/20/21 9:02 PM, Ilya Maximets wrote: > > This is one of the hottest points in the northd in case of big number > > of load balancers and we're reallocating matches and actions several > > times for each vIP for each load balancer. > > > > Fix that by re-using the allocated memory and just clearing dynamic > > strings for all subsequnet IPs. > > > > Signed-off-by: Ilya Maximets <i.maximets@ovn.org> > > --- > > Looks good to me, thanks! > > Acked-by: Dumitru Ceara <dceara@redhat.com> Thanks. I applied this patch to the main branch. Numan > > > _______________________________________________ > dev mailing list > dev@openvswitch.org > https://mail.openvswitch.org/mailman/listinfo/ovs-dev >
diff --git a/northd/ovn-northd.c b/northd/ovn-northd.c index 0e5092a87..9fc4deb76 100644 --- a/northd/ovn-northd.c +++ b/northd/ovn-northd.c @@ -6013,13 +6013,17 @@ static void build_lb_rules(struct ovn_datapath *od, struct hmap *lflows, struct ovn_northd_lb *lb) { + struct ds action = DS_EMPTY_INITIALIZER; + struct ds match = DS_EMPTY_INITIALIZER; + for (size_t i = 0; i < lb->n_vips; i++) { struct ovn_lb_vip *lb_vip = &lb->vips[i]; struct ovn_northd_lb_vip *lb_vip_nb = &lb->vips_nb[i]; - - struct ds action = DS_EMPTY_INITIALIZER; const char *ip_match = NULL; + ds_clear(&action); + ds_clear(&match); + /* Store the original destination IP to be used when generating * hairpin flows. */ @@ -6055,7 +6059,6 @@ build_lb_rules(struct ovn_datapath *od, struct hmap *lflows, build_lb_vip_actions(lb_vip, lb_vip_nb, &action, lb->selection_fields, true); - struct ds match = DS_EMPTY_INITIALIZER; ds_put_format(&match, "ct.new && %s.dst == %s", ip_match, lb_vip->vip_str); if (lb_vip->vip_port) { @@ -6068,10 +6071,9 @@ build_lb_rules(struct ovn_datapath *od, struct hmap *lflows, ds_cstr(&match), ds_cstr(&action), &lb->nlb->header_); } - - ds_destroy(&match); - ds_destroy(&action); } + ds_destroy(&action); + ds_destroy(&match); } static void
This is one of the hottest points in the northd in case of big number of load balancers and we're reallocating matches and actions several times for each vIP for each load balancer. Fix that by re-using the allocated memory and just clearing dynamic strings for all subsequnet IPs. Signed-off-by: Ilya Maximets <i.maximets@ovn.org> --- northd/ovn-northd.c | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-)