From patchwork Fri Aug 27 19:17:41 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ilya Maximets X-Patchwork-Id: 1521779 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::138; helo=smtp1.osuosl.org; envelope-from=ovs-dev-bounces@openvswitch.org; receiver=) Received: from smtp1.osuosl.org (smtp1.osuosl.org [IPv6:2605:bc80:3010::138]) (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 4Gx8cs3BK8z9sRN for ; Sat, 28 Aug 2021 05:18:05 +1000 (AEST) Received: from localhost (localhost [127.0.0.1]) by smtp1.osuosl.org (Postfix) with ESMTP id C55FF83E8F; Fri, 27 Aug 2021 19:18:01 +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 F8kHv-tMLyoZ; Fri, 27 Aug 2021 19:17:57 +0000 (UTC) Received: from lists.linuxfoundation.org (lf-lists.osuosl.org [140.211.9.56]) by smtp1.osuosl.org (Postfix) with ESMTPS id 61E2783E59; Fri, 27 Aug 2021 19:17:55 +0000 (UTC) Received: from lf-lists.osuosl.org (localhost [127.0.0.1]) by lists.linuxfoundation.org (Postfix) with ESMTP id 4E5E6C0024; Fri, 27 Aug 2021 19:17:53 +0000 (UTC) X-Original-To: ovs-dev@openvswitch.org Delivered-To: ovs-dev@lists.linuxfoundation.org Received: from smtp4.osuosl.org (smtp4.osuosl.org [IPv6:2605:bc80:3010::137]) by lists.linuxfoundation.org (Postfix) with ESMTP id 15F05C000E for ; Fri, 27 Aug 2021 19:17:52 +0000 (UTC) Received: from localhost (localhost [127.0.0.1]) by smtp4.osuosl.org (Postfix) with ESMTP id EDD6A42753 for ; Fri, 27 Aug 2021 19:17:51 +0000 (UTC) X-Virus-Scanned: amavisd-new at osuosl.org Received: from smtp4.osuosl.org ([127.0.0.1]) by localhost (smtp4.osuosl.org [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id g6iMiZ41ZPup for ; Fri, 27 Aug 2021 19:17:51 +0000 (UTC) X-Greylist: domain auto-whitelisted by SQLgrey-1.8.0 Received: from relay4-d.mail.gandi.net (relay4-d.mail.gandi.net [217.70.183.196]) by smtp4.osuosl.org (Postfix) with ESMTPS id E43F84273A for ; Fri, 27 Aug 2021 19:17:50 +0000 (UTC) Received: (Authenticated sender: i.maximets@ovn.org) by relay4-d.mail.gandi.net (Postfix) with ESMTPSA id 42D71E0005; Fri, 27 Aug 2021 19:17:48 +0000 (UTC) From: Ilya Maximets To: ovs-dev@openvswitch.org Date: Fri, 27 Aug 2021 21:17:41 +0200 Message-Id: <20210827191742.2307529-2-i.maximets@ovn.org> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20210827191742.2307529-1-i.maximets@ovn.org> References: <20210827191742.2307529-1-i.maximets@ovn.org> MIME-Version: 1.0 Cc: Ilya Maximets Subject: [ovs-dev] [PATCH ovn 1/2] ovn-northd: Avoid creation of identical datapath groups. 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" Currently, in a case where datapath groups doesn't need to be changed, but a new flow should be added, northd will create a new identical datapath group for a new flow. It happens because we're not looking for suitable group in Southbound database, but only tracking ones created on current iteration. With this change, northd will collect existing Sb DB datapath groups while checking logical flows by linking them to unique datapath groups generated on this run. This way we can reduce number of datapath groups. It wasn't really a problem, almost all the flows in typical use case are using the same datapath group with only a few of them using separate copies. More importantly, this change allows to avoid full comparison of datapath groups if we already checked this group from the database once and linked it to a new group generated on this run. Signed-off-by: Ilya Maximets Acked-by: Dumitru Ceara --- northd/ovn-northd.c | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) diff --git a/northd/ovn-northd.c b/northd/ovn-northd.c index cdc351c26..ae5874518 100644 --- a/northd/ovn-northd.c +++ b/northd/ovn-northd.c @@ -4308,6 +4308,7 @@ struct ovn_lflow { char *io_port; char *stage_hint; char *ctrl_meter; + struct ovn_dp_group *dpg; /* Link to unique Sb datapath group. */ const char *where; }; @@ -4356,6 +4357,7 @@ ovn_lflow_init(struct ovn_lflow *lflow, struct ovn_datapath *od, lflow->io_port = io_port; lflow->stage_hint = stage_hint; lflow->ctrl_meter = ctrl_meter; + lflow->dpg = NULL; lflow->where = where; } @@ -13208,6 +13210,7 @@ build_lflows(struct northd_context *ctx, struct hmap *datapaths, hmapx_clone(&dpg->map, &lflow->od_group); hmap_insert(&dp_groups, &dpg->node, hash); } + lflow->dpg = dpg; } /* Adding datapath to the flow hash for logical flows that have only one, @@ -13305,8 +13308,17 @@ build_lflows(struct northd_context *ctx, struct hmap *datapaths, bool update_dp_group = false; if (n_datapaths != hmapx_count(&lflow->od_group)) { + /* Groups are different. */ update_dp_group = true; - } else { + } else if (lflow->dpg && lflow->dpg->dp_group) { + /* We know the datapath group in Sb that should be used. */ + if (lflow->dpg->dp_group != dp_group) { + /* Flow has different datapath group in the database. */ + update_dp_group = true; + } + /* Datapath group is already up to date. */ + } else if (n_datapaths) { + /* Have to compare datapath groups in full. */ for (i = 0; i < n_datapaths; i++) { if (od[i] && !hmapx_contains(&lflow->od_group, od[i])) { update_dp_group = true; @@ -13318,7 +13330,12 @@ build_lflows(struct northd_context *ctx, struct hmap *datapaths, if (update_dp_group) { ovn_sb_set_lflow_logical_dp_group(ctx, &dp_groups, sbflow, &lflow->od_group); + } else if (lflow->dpg && !lflow->dpg->dp_group) { + /* Setting relation between unique datapath group and + * Sb DB datapath goup. */ + lflow->dpg->dp_group = dp_group; } + /* This lflow updated. Not needed anymore. */ ovn_lflow_destroy(&lflows, lflow); } else {