From patchwork Fri Aug 23 11:23:41 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dumitru Ceara X-Patchwork-Id: 1152128 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (mailfrom) smtp.mailfrom=openvswitch.org (client-ip=140.211.169.12; helo=mail.linuxfoundation.org; envelope-from=ovs-dev-bounces@openvswitch.org; receiver=) Authentication-Results: ozlabs.org; dmarc=fail (p=none dis=none) header.from=redhat.com Received: from mail.linuxfoundation.org (mail.linuxfoundation.org [140.211.169.12]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 46FJvW31lkz9s00 for ; Fri, 23 Aug 2019 21:24:23 +1000 (AEST) Received: from mail.linux-foundation.org (localhost [127.0.0.1]) by mail.linuxfoundation.org (Postfix) with ESMTP id 24BEEE2C; Fri, 23 Aug 2019 11:23:47 +0000 (UTC) X-Original-To: dev@openvswitch.org Delivered-To: ovs-dev@mail.linuxfoundation.org Received: from smtp1.linuxfoundation.org (smtp1.linux-foundation.org [172.17.192.35]) by mail.linuxfoundation.org (Postfix) with ESMTPS id 76E9FE17 for ; Fri, 23 Aug 2019 11:23:45 +0000 (UTC) X-Greylist: domain auto-whitelisted by SQLgrey-1.7.6 Received: from mx1.redhat.com (mx1.redhat.com [209.132.183.28]) by smtp1.linuxfoundation.org (Postfix) with ESMTPS id 101EA8A3 for ; Fri, 23 Aug 2019 11:23:45 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.13]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id A746B8AC6FD for ; Fri, 23 Aug 2019 11:23:44 +0000 (UTC) Received: from dceara.remote.csb (ovpn-117-75.ams2.redhat.com [10.36.117.75]) by smtp.corp.redhat.com (Postfix) with ESMTP id 0B4A760933 for ; Fri, 23 Aug 2019 11:23:43 +0000 (UTC) From: Dumitru Ceara To: dev@openvswitch.org Date: Fri, 23 Aug 2019 13:23:41 +0200 Message-Id: <20190823112332.30602.8218.stgit@dceara.remote.csb> In-Reply-To: <20190823112304.30602.63778.stgit@dceara.remote.csb> References: <20190823112304.30602.63778.stgit@dceara.remote.csb> User-Agent: StGit/0.17.1-dirty MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.13 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.6.2 (mx1.redhat.com [10.5.110.69]); Fri, 23 Aug 2019 11:23:44 +0000 (UTC) X-Spam-Status: No, score=-6.9 required=5.0 tests=BAYES_00,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on smtp1.linux-foundation.org Subject: [ovs-dev] [PATCH v2 ovn 2/3] ovn-controller: Optimize update of ct-zones external-ids. X-BeenThere: ovs-dev@openvswitch.org X-Mailman-Version: 2.1.12 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: ovs-dev-bounces@openvswitch.org Errors-To: ovs-dev-bounces@openvswitch.org commit_ct_zones() is called at every ovn-controller iteration but updates to ct-zones don't happen at every iteration. Avoid cloning the br-int->external_ids map unless an update is needed. Signed-off-by: Dumitru Ceara --- controller/ovn-controller.c | 53 +++++++++++++++++++++++++++++++++++++------ 1 file changed, 45 insertions(+), 8 deletions(-) diff --git a/controller/ovn-controller.c b/controller/ovn-controller.c index 86f29ac..1825c1f 100644 --- a/controller/ovn-controller.c +++ b/controller/ovn-controller.c @@ -531,10 +531,9 @@ static void commit_ct_zones(const struct ovsrec_bridge *br_int, struct shash *pending_ct_zones) { - struct smap new_ids; - smap_clone(&new_ids, &br_int->external_ids); + struct smap ct_add_ids = SMAP_INITIALIZER(&ct_add_ids); + struct sset ct_del_ids = SSET_INITIALIZER(&ct_del_ids); - bool updated = false; struct shash_node *iter; SHASH_FOR_EACH(iter, pending_ct_zones) { struct ct_zone_pending_entry *ctzpe = iter->data; @@ -550,22 +549,60 @@ commit_ct_zones(const struct ovsrec_bridge *br_int, char *user_str = xasprintf("ct-zone-%s", iter->name); if (ctzpe->add) { char *zone_str = xasprintf("%"PRId32, ctzpe->zone); - smap_replace(&new_ids, user_str, zone_str); + struct smap_node *node = + smap_get_node(&br_int->external_ids, user_str); + if (!node || strcmp(node->value, zone_str)) { + smap_add_nocopy(&ct_add_ids, user_str, zone_str); + user_str = NULL; + zone_str = NULL; + } free(zone_str); } else { - smap_remove(&new_ids, user_str); + if (smap_get(&br_int->external_ids, user_str)) { + sset_add(&ct_del_ids, user_str); + } } free(user_str); ctzpe->state = CT_ZONE_DB_SENT; - updated = true; } - if (updated) { + /* Update the bridge external IDs only if really needed (i.e., we must + * add a value or delete one). Rebuilding the external IDs map at + * every run is a costly operation when having lots of ct_zones. + */ + if (!smap_is_empty(&ct_add_ids) || !sset_is_empty(&ct_del_ids)) { + struct smap new_ids = SMAP_INITIALIZER(&new_ids); + + struct smap_node *id; + SMAP_FOR_EACH (id, &br_int->external_ids) { + if (sset_find_and_delete(&ct_del_ids, id->key)) { + continue; + } + + if (smap_get(&ct_add_ids, id->key)) { + continue; + } + + smap_add(&new_ids, id->key, id->value); + } + + struct smap_node *next_id; + SMAP_FOR_EACH_SAFE (id, next_id, &ct_add_ids) { + smap_replace(&new_ids, id->key, id->value); + smap_remove_node(&ct_add_ids, id); + } + ovsrec_bridge_verify_external_ids(br_int); ovsrec_bridge_set_external_ids(br_int, &new_ids); + smap_destroy(&new_ids); } - smap_destroy(&new_ids); + + ovs_assert(smap_is_empty(&ct_add_ids)); + ovs_assert(sset_is_empty(&ct_del_ids)); + + smap_destroy(&ct_add_ids); + sset_destroy(&ct_del_ids); } static void