From patchwork Thu May 20 19:02:19 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ilya Maximets X-Patchwork-Id: 1481882 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=openvswitch.org (client-ip=2605:bc80:3010::136; helo=smtp3.osuosl.org; envelope-from=ovs-dev-bounces@openvswitch.org; receiver=) Received: from smtp3.osuosl.org (smtp3.osuosl.org [IPv6:2605:bc80:3010::136]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 4FmJyb1cGQz9sRK for ; Fri, 21 May 2021 05:02:30 +1000 (AEST) Received: from localhost (localhost [127.0.0.1]) by smtp3.osuosl.org (Postfix) with ESMTP id C5A2B60C18; Thu, 20 May 2021 19:02:28 +0000 (UTC) X-Virus-Scanned: amavisd-new at osuosl.org Received: from smtp3.osuosl.org ([127.0.0.1]) by localhost (smtp3.osuosl.org [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id 0GN8o5bGzkSC; Thu, 20 May 2021 19:02:27 +0000 (UTC) Received: from lists.linuxfoundation.org (lf-lists.osuosl.org [IPv6:2605:bc80:3010:104::8cd3:938]) by smtp3.osuosl.org (Postfix) with ESMTP id 0A4CA60C1F; Thu, 20 May 2021 19:02:27 +0000 (UTC) Received: from lf-lists.osuosl.org (localhost [127.0.0.1]) by lists.linuxfoundation.org (Postfix) with ESMTP id D5519C000E; Thu, 20 May 2021 19:02:26 +0000 (UTC) X-Original-To: ovs-dev@openvswitch.org Delivered-To: ovs-dev@lists.linuxfoundation.org Received: from smtp1.osuosl.org (smtp1.osuosl.org [140.211.166.138]) by lists.linuxfoundation.org (Postfix) with ESMTP id 3FC1EC0001 for ; Thu, 20 May 2021 19:02:25 +0000 (UTC) Received: from localhost (localhost [127.0.0.1]) by smtp1.osuosl.org (Postfix) with ESMTP id 19EC784425 for ; Thu, 20 May 2021 19:02:25 +0000 (UTC) X-Virus-Scanned: amavisd-new at osuosl.org Received: from smtp1.osuosl.org ([127.0.0.1]) by localhost (smtp1.osuosl.org [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id EuYad2BDOdOK for ; Thu, 20 May 2021 19:02:24 +0000 (UTC) X-Greylist: domain auto-whitelisted by SQLgrey-1.8.0 Received: from relay3-d.mail.gandi.net (relay3-d.mail.gandi.net [217.70.183.195]) by smtp1.osuosl.org (Postfix) with ESMTPS id 33BD384412 for ; Thu, 20 May 2021 19:02:23 +0000 (UTC) Received: (Authenticated sender: i.maximets@ovn.org) by relay3-d.mail.gandi.net (Postfix) with ESMTPSA id 6F5A960009; Thu, 20 May 2021 19:02:21 +0000 (UTC) From: Ilya Maximets To: ovs-dev@openvswitch.org Date: Thu, 20 May 2021 21:02:19 +0200 Message-Id: <20210520190219.758420-1-i.maximets@ovn.org> X-Mailer: git-send-email 2.26.3 MIME-Version: 1.0 Cc: Ilya Maximets , Dumitru Ceara Subject: [ovs-dev] [PATCH ovn] northd: Avoid memory reallocation while building lb rules. X-BeenThere: ovs-dev@openvswitch.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: ovs-dev-bounces@openvswitch.org Sender: "dev" 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 Acked-by: Dumitru Ceara --- 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