From patchwork Fri Oct 8 16:03:39 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Anton Ivanov X-Patchwork-Id: 1538437 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=140.211.166.138; helo=smtp1.osuosl.org; envelope-from=ovs-dev-bounces@openvswitch.org; receiver=) Received: from smtp1.osuosl.org (smtp1.osuosl.org [140.211.166.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 bilbo.ozlabs.org (Postfix) with ESMTPS id 4HQtKY68Vyz9s0r for ; Sat, 9 Oct 2021 03:04:01 +1100 (AEDT) Received: from localhost (localhost [127.0.0.1]) by smtp1.osuosl.org (Postfix) with ESMTP id 107F384204; Fri, 8 Oct 2021 16:03:59 +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 HukXLB08my1V; Fri, 8 Oct 2021 16:03:58 +0000 (UTC) Received: from lists.linuxfoundation.org (lf-lists.osuosl.org [140.211.9.56]) by smtp1.osuosl.org (Postfix) with ESMTPS id 3CF9F83B19; Fri, 8 Oct 2021 16:03:57 +0000 (UTC) Received: from lf-lists.osuosl.org (localhost [127.0.0.1]) by lists.linuxfoundation.org (Postfix) with ESMTP id 0E942C0011; Fri, 8 Oct 2021 16:03:57 +0000 (UTC) X-Original-To: ovs-dev@openvswitch.org Delivered-To: ovs-dev@lists.linuxfoundation.org Received: from smtp1.osuosl.org (smtp1.osuosl.org [IPv6:2605:bc80:3010::138]) by lists.linuxfoundation.org (Postfix) with ESMTP id A08A5C000D for ; Fri, 8 Oct 2021 16:03:55 +0000 (UTC) Received: from localhost (localhost [127.0.0.1]) by smtp1.osuosl.org (Postfix) with ESMTP id 8007D8417B for ; Fri, 8 Oct 2021 16:03:55 +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 2-78ySBWmODp for ; Fri, 8 Oct 2021 16:03:54 +0000 (UTC) X-Greylist: from auto-whitelisted by SQLgrey-1.8.0 Received: from www.kot-begemot.co.uk (ivanoab7.miniserver.com [37.128.132.42]) by smtp1.osuosl.org (Postfix) with ESMTPS id 8172483B19 for ; Fri, 8 Oct 2021 16:03:54 +0000 (UTC) Received: from tun252.jain.kot-begemot.co.uk ([192.168.18.6] helo=jain.kot-begemot.co.uk) by www.kot-begemot.co.uk with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1mYsLf-0007dD-FL; Fri, 08 Oct 2021 16:03:51 +0000 Received: from jain.kot-begemot.co.uk ([192.168.3.3]) by jain.kot-begemot.co.uk with esmtp (Exim 4.92) (envelope-from ) id 1mYsLb-0004ba-LE; Fri, 08 Oct 2021 17:03:49 +0100 From: anton.ivanov@cambridgegreys.com To: ovs-dev@openvswitch.org Date: Fri, 8 Oct 2021 17:03:39 +0100 Message-Id: <20211008160339.17628-1-anton.ivanov@cambridgegreys.com> X-Mailer: git-send-email 2.20.1 MIME-Version: 1.0 X-Clacks-Overhead: GNU Terry Pratchett Cc: Anton Ivanov Subject: [ovs-dev] [OVN Patch v2] northd: Optimize dp/lflow postprocessing 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" From: Anton Ivanov 1. Compute dp group hash only if there will be dp group processing. 2. Remove hmapx interim storage and related hmapx computation for single dp flows and replace it with a pre-sized hmap. Signed-off-by: Anton Ivanov Acked-by: Mark D. Gray --- northd/northd.c | 48 ++++++++++++++++++++++++++++-------------------- ovs | 2 +- 2 files changed, 29 insertions(+), 21 deletions(-) diff --git a/northd/northd.c b/northd/northd.c index e42795ca0..a3c3dbcf9 100644 --- a/northd/northd.c +++ b/northd/northd.c @@ -13331,10 +13331,20 @@ build_lflows(struct northd_context *ctx, struct hmap *datapaths, stopwatch_start(LFLOWS_DP_GROUPS_STOPWATCH_NAME, time_msec()); /* Collecting all unique datapath groups. */ struct hmap dp_groups = HMAP_INITIALIZER(&dp_groups); - struct hmapx single_dp_lflows = HMAPX_INITIALIZER(&single_dp_lflows); - struct ovn_lflow *lflow; - HMAP_FOR_EACH (lflow, hmap_node, &lflows) { - uint32_t hash = hash_int(hmapx_count(&lflow->od_group), 0); + struct hmap single_dp_lflows; + + /* Single dp_flows will never grow bigger than lflows, + * thus the two hmaps will remain the same size regardless + * of how many elements we remove from lflows and add to + * single_dp_lflows. + * Note - lflows is always sized for at least 128 flows. + */ + fast_hmap_size_for(&single_dp_lflows, max_seen_lflow_size); + + struct ovn_lflow *lflow, *next_lflow; + struct hmapx_node *node; + HMAP_FOR_EACH_SAFE (lflow, next_lflow, hmap_node, &lflows) { + uint32_t hash; struct ovn_dp_group *dpg; ovs_assert(hmapx_count(&lflow->od_group)); @@ -13342,17 +13352,24 @@ build_lflows(struct northd_context *ctx, struct hmap *datapaths, if (hmapx_count(&lflow->od_group) == 1) { /* There is only one datapath, so it should be moved out of the * group to a single 'od'. */ - const struct hmapx_node *node; HMAPX_FOR_EACH (node, &lflow->od_group) { lflow->od = node->data; break; } hmapx_clear(&lflow->od_group); + /* Logical flow should be re-hashed later to allow lookups. */ - hmapx_add(&single_dp_lflows, lflow); + hash = hmap_node_hash(&lflow->hmap_node); + /* Remove from lflows. */ + hmap_remove(&lflows, &lflow->hmap_node); + hash = ovn_logical_flow_hash_datapath(&lflow->od->sb->header_.uuid, + hash); + /* Add to single_dp_lflows. */ + hmap_insert_fast(&single_dp_lflows, &lflow->hmap_node, hash); continue; } + hash = hash_int(hmapx_count(&lflow->od_group), 0); dpg = ovn_dp_group_find(&dp_groups, &lflow->od_group, hash); if (!dpg) { dpg = xzalloc(sizeof *dpg); @@ -13362,19 +13379,11 @@ build_lflows(struct northd_context *ctx, struct hmap *datapaths, lflow->dpg = dpg; } - /* Adding datapath to the flow hash for logical flows that have only one, - * so they could be found by the southbound db record. */ - const struct hmapx_node *node; - uint32_t hash; - HMAPX_FOR_EACH (node, &single_dp_lflows) { - lflow = node->data; - hash = hmap_node_hash(&lflow->hmap_node); - hmap_remove(&lflows, &lflow->hmap_node); - hash = ovn_logical_flow_hash_datapath(&lflow->od->sb->header_.uuid, - hash); - hmap_insert(&lflows, &lflow->hmap_node, hash); - } - hmapx_destroy(&single_dp_lflows); + /* Merge multiple and single dp hashes. */ + + fast_hmap_merge(&lflows, &single_dp_lflows); + + hmap_destroy(&single_dp_lflows); /* Push changes to the Logical_Flow table to database. */ const struct sbrec_logical_flow *sbflow, *next_sbflow; @@ -13507,7 +13516,6 @@ build_lflows(struct northd_context *ctx, struct hmap *datapaths, } stopwatch_stop(LFLOWS_DP_GROUPS_STOPWATCH_NAME, time_msec()); - struct ovn_lflow *next_lflow; HMAP_FOR_EACH_SAFE (lflow, next_lflow, hmap_node, &lflows) { const char *pipeline = ovn_stage_get_pipeline_name(lflow->stage); uint8_t table = ovn_stage_get_table(lflow->stage);