From patchwork Tue Oct 30 22:03:16 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ben Pfaff X-Patchwork-Id: 991134 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=none (p=none dis=none) header.from=ovn.org 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 42l59l5t16z9sC2 for ; Wed, 31 Oct 2018 09:04:59 +1100 (AEDT) Received: from mail.linux-foundation.org (localhost [127.0.0.1]) by mail.linuxfoundation.org (Postfix) with ESMTP id 441E63DDC; Tue, 30 Oct 2018 22:03:55 +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 3B0CC3D84 for ; Tue, 30 Oct 2018 22:03:27 +0000 (UTC) X-Greylist: domain auto-whitelisted by SQLgrey-1.7.6 Received: from relay7-d.mail.gandi.net (relay7-d.mail.gandi.net [217.70.183.200]) by smtp1.linuxfoundation.org (Postfix) with ESMTPS id A53E081C for ; Tue, 30 Oct 2018 22:03:26 +0000 (UTC) X-Originating-IP: 208.91.3.26 Received: from sigabrt.benpfaff.org (unknown [208.91.3.26]) (Authenticated sender: blp@ovn.org) by relay7-d.mail.gandi.net (Postfix) with ESMTPSA id 97F6420002; Tue, 30 Oct 2018 22:03:23 +0000 (UTC) From: Ben Pfaff To: dev@openvswitch.org Date: Tue, 30 Oct 2018 15:03:16 -0700 Message-Id: <20181030220318.13998-1-blp@ovn.org> X-Mailer: git-send-email 2.16.1 X-Spam-Status: No, score=-2.6 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_LOW autolearn=ham version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on smtp1.linux-foundation.org Cc: Ben Pfaff Subject: [ovs-dev] [PATCH v2 1/3] ovn-northd: Use structure assignment instead of memcpy(). 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: , MIME-Version: 1.0 Sender: ovs-dev-bounces@openvswitch.org Errors-To: ovs-dev-bounces@openvswitch.org Makes the code easier to read. Signed-off-by: Ben Pfaff --- ovn/northd/ovn-northd.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ovn/northd/ovn-northd.c b/ovn/northd/ovn-northd.c index 439651f80308..bc07a40bd0f8 100644 --- a/ovn/northd/ovn-northd.c +++ b/ovn/northd/ovn-northd.c @@ -339,7 +339,7 @@ add_chassis_queue(struct hmap *set, struct uuid *chassis_uuid, { struct ovn_chassis_qdisc_queues *node = xmalloc(sizeof *node); node->queue_id = queue_id; - memcpy(&node->chassis_uuid, chassis_uuid, sizeof node->chassis_uuid); + node->chassis_uuid = *chassis_uuid; hmap_insert(set, &node->key_node, uuid_hash(chassis_uuid)); } From patchwork Tue Oct 30 22:03:17 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ben Pfaff X-Patchwork-Id: 991132 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=none (p=none dis=none) header.from=ovn.org 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 42l58r204nz9sC2 for ; Wed, 31 Oct 2018 09:04:11 +1100 (AEDT) Received: from mail.linux-foundation.org (localhost [127.0.0.1]) by mail.linuxfoundation.org (Postfix) with ESMTP id 172923DE1; Tue, 30 Oct 2018 22:03:56 +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 5873C3D84 for ; Tue, 30 Oct 2018 22:03:28 +0000 (UTC) X-Greylist: domain auto-whitelisted by SQLgrey-1.7.6 Received: from relay7-d.mail.gandi.net (relay7-d.mail.gandi.net [217.70.183.200]) by smtp1.linuxfoundation.org (Postfix) with ESMTPS id B87AA81C for ; Tue, 30 Oct 2018 22:03:27 +0000 (UTC) X-Originating-IP: 208.91.3.26 Received: from sigabrt.benpfaff.org (unknown [208.91.3.26]) (Authenticated sender: blp@ovn.org) by relay7-d.mail.gandi.net (Postfix) with ESMTPSA id 36E5E20003; Tue, 30 Oct 2018 22:03:24 +0000 (UTC) From: Ben Pfaff To: dev@openvswitch.org Date: Tue, 30 Oct 2018 15:03:17 -0700 Message-Id: <20181030220318.13998-2-blp@ovn.org> X-Mailer: git-send-email 2.16.1 In-Reply-To: <20181030220318.13998-1-blp@ovn.org> References: <20181030220318.13998-1-blp@ovn.org> X-Spam-Status: No, score=-2.6 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_LOW autolearn=ham version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on smtp1.linux-foundation.org Cc: Ben Pfaff Subject: [ovs-dev] [PATCH v2 2/3] ovn-northd: Improve hashing for chassis queues. 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: , MIME-Version: 1.0 Sender: ovs-dev-bounces@openvswitch.org Errors-To: ovs-dev-bounces@openvswitch.org The key for a "struct ovn_chassis_qdisc_queues" is a Chassis UUID and a queue_id, but only the UUID was being hashed, so if there was more than one per chassis then they'd all end up in the same hash bucket, which is needlessly inefficient. (And if there's only one per chassis then why do we bother allocating them at all?) Found by inspection. Signed-off-by: Ben Pfaff Acked-by: Numan Siddique --- ovn/northd/ovn-northd.c | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 deletions(-) diff --git a/ovn/northd/ovn-northd.c b/ovn/northd/ovn-northd.c index bc07a40bd0f8..6cb0b6cc410a 100644 --- a/ovn/northd/ovn-northd.c +++ b/ovn/northd/ovn-northd.c @@ -323,6 +323,12 @@ struct ovn_chassis_qdisc_queues { struct uuid chassis_uuid; }; +static uint32_t +hash_chassis_queue(const struct uuid *chassis_uuid, uint32_t queue_id) +{ + return hash_2words(uuid_hash(chassis_uuid), queue_id); +} + static void destroy_chassis_queues(struct hmap *set) { @@ -340,7 +346,8 @@ add_chassis_queue(struct hmap *set, struct uuid *chassis_uuid, struct ovn_chassis_qdisc_queues *node = xmalloc(sizeof *node); node->queue_id = queue_id; node->chassis_uuid = *chassis_uuid; - hmap_insert(set, &node->key_node, uuid_hash(chassis_uuid)); + hmap_insert(set, &node->key_node, + hash_chassis_queue(chassis_uuid, queue_id)); } static bool @@ -348,7 +355,8 @@ chassis_queueid_in_use(const struct hmap *set, struct uuid *chassis_uuid, uint32_t queue_id) { const struct ovn_chassis_qdisc_queues *node; - HMAP_FOR_EACH_WITH_HASH (node, key_node, uuid_hash(chassis_uuid), set) { + HMAP_FOR_EACH_WITH_HASH (node, key_node, + hash_chassis_queue(chassis_uuid, queue_id), set) { if (uuid_equals(chassis_uuid, &node->chassis_uuid) && node->queue_id == queue_id) { return true; @@ -378,11 +386,11 @@ static void free_chassis_queueid(struct hmap *set, struct sbrec_chassis *chassis, uint32_t queue_id) { + const struct uuid *chassis_uuid = &chassis->header_.uuid; struct ovn_chassis_qdisc_queues *node; HMAP_FOR_EACH_WITH_HASH (node, key_node, - uuid_hash(&chassis->header_.uuid), - set) { - if (uuid_equals(&chassis->header_.uuid, &node->chassis_uuid) + hash_chassis_queue(chassis_uuid, queue_id), set) { + if (uuid_equals(chassis_uuid, &node->chassis_uuid) && node->queue_id == queue_id) { hmap_remove(set, &node->key_node); break; From patchwork Tue Oct 30 22:03:18 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ben Pfaff X-Patchwork-Id: 991133 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=none (p=none dis=none) header.from=ovn.org 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 42l59C0LJ0z9sCf for ; Wed, 31 Oct 2018 09:04:31 +1100 (AEDT) Received: from mail.linux-foundation.org (localhost [127.0.0.1]) by mail.linuxfoundation.org (Postfix) with ESMTP id CE2BF3DE6; Tue, 30 Oct 2018 22:03:56 +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 C09173D84 for ; Tue, 30 Oct 2018 22:03:29 +0000 (UTC) X-Greylist: domain auto-whitelisted by SQLgrey-1.7.6 Received: from relay7-d.mail.gandi.net (relay7-d.mail.gandi.net [217.70.183.200]) by smtp1.linuxfoundation.org (Postfix) with ESMTPS id 4529981E for ; Tue, 30 Oct 2018 22:03:29 +0000 (UTC) X-Originating-IP: 208.91.3.26 Received: from sigabrt.benpfaff.org (unknown [208.91.3.26]) (Authenticated sender: blp@ovn.org) by relay7-d.mail.gandi.net (Postfix) with ESMTPSA id D190220007; Tue, 30 Oct 2018 22:03:26 +0000 (UTC) From: Ben Pfaff To: dev@openvswitch.org Date: Tue, 30 Oct 2018 15:03:18 -0700 Message-Id: <20181030220318.13998-3-blp@ovn.org> X-Mailer: git-send-email 2.16.1 In-Reply-To: <20181030220318.13998-1-blp@ovn.org> References: <20181030220318.13998-1-blp@ovn.org> X-Spam-Status: No, score=-2.6 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_LOW autolearn=ham version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on smtp1.linux-foundation.org Cc: Ben Pfaff Subject: [ovs-dev] [PATCH v2 3/3] ovn-northd: Fix memory leak in free_chassis_queueid(). 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: , MIME-Version: 1.0 Sender: ovs-dev-bounces@openvswitch.org Errors-To: ovs-dev-bounces@openvswitch.org Found by inspection. Signed-off-by: Ben Pfaff Acked-by: Numan Siddique --- ovn/northd/ovn-northd.c | 1 + 1 file changed, 1 insertion(+) diff --git a/ovn/northd/ovn-northd.c b/ovn/northd/ovn-northd.c index 6cb0b6cc410a..e42ceea99264 100644 --- a/ovn/northd/ovn-northd.c +++ b/ovn/northd/ovn-northd.c @@ -393,6 +393,7 @@ free_chassis_queueid(struct hmap *set, struct sbrec_chassis *chassis, if (uuid_equals(chassis_uuid, &node->chassis_uuid) && node->queue_id == queue_id) { hmap_remove(set, &node->key_node); + free(node); break; } }