[ovs-dev] [PATCH ovn] northd: Avoid memory reallocation while building lb rules.

Ilya Maximets i.maximets at ovn.org
Thu May 20 19:02:19 UTC 2021


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 at ovn.org>
---
 northd/ovn-northd.c | 14 ++++++++------
 1 file changed, 8 insertions(+), 6 deletions(-)

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
-- 
2.26.3



More information about the dev mailing list