From patchwork Mon Dec 17 13:19:23 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kent Overstreet X-Patchwork-Id: 1014478 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=gmail.com Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.b="j/lTDE27"; dkim-atps=neutral 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 43JMGl75Bxz9sCh for ; Tue, 18 Dec 2018 00:20:47 +1100 (AEDT) Received: from mail.linux-foundation.org (localhost [127.0.0.1]) by mail.linuxfoundation.org (Postfix) with ESMTP id DCAC8CC8; Mon, 17 Dec 2018 13:19:42 +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 6FFB6CC7 for ; Mon, 17 Dec 2018 13:19:41 +0000 (UTC) X-Greylist: whitelisted by SQLgrey-1.7.6 Received: from mail-wr1-f67.google.com (mail-wr1-f67.google.com [209.85.221.67]) by smtp1.linuxfoundation.org (Postfix) with ESMTPS id 74E6D782 for ; Mon, 17 Dec 2018 13:19:40 +0000 (UTC) Received: by mail-wr1-f67.google.com with SMTP id u4so11269600wrp.3 for ; Mon, 17 Dec 2018 05:19:40 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=CdZbaGumofDlzZscmjO4/1rMOKWdjFWAqxsY9I7b5SE=; b=j/lTDE27lH7MxG4lMbX9tzV+iq68peIvXYgGh3qJ3uCOBOedbAVAYxsEC1DyuAIR3u Rd0IZXh5AltOP9wibZwA6iLMh3V8Sba3CU0726CcMsoF7I1zx2w7LYBprxXUvgyTwYN+ aBcZcymzlgsj+wrO268Q67tCbuFoGKVTVy/fnRaYCbt2I5TkcR3r5i3CgCJD/K78ccM0 AZsJq4fz/ANgnWAOrNeAyS7AF8WoB7cBJOYWcVvRskAx6MBFcdmArYSwY2XhPctUka5N FN0nksOHeFCI00KgutFOog0J2WT/bCycAdWNIe8OaEueu4EpXTETRt2J7fdvrGo5VDLN H0Jg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=CdZbaGumofDlzZscmjO4/1rMOKWdjFWAqxsY9I7b5SE=; b=XSumDBjzkawvGGvZ4RWmaOhlP6DTi21xb9khHI4/f1q5C2twnxQ4Yt1Z87kNPaIO1a YgIs5xZQ7zPbbd8ZPGnLAUJ5xLjbeggXcQ4UUWrMq1Y9rzMnOF/oyXpW7mjm9U9o2Yjk jwGYBhN57zrdVi9MRprTu48fM9qgO6JRqXRP9J8b3YCot0fXV1WsEt+pS7T+O0+kjUVh 1ox74C1lwgxWftmEqNqhOeGHH7HJh6lX8gd8g48PQ86RV0ljfRCCHy8wsWgaMCLeqabC UrYXimQUz/Zo3lDkslOl7vgeBvL7n6xxQgT8R36nlcHriUjQJU+xsUfKtObs7acRdP5F UtNw== X-Gm-Message-State: AA+aEWau2uyfZ4/5iEEb6hi7cQrrBsqWNfXrGUrPz7hv6r0OUvaAodJG C9NYavLFrKcuxvBjUOATDg== X-Google-Smtp-Source: AFSGD/V2wUyAUQq2JOXad5CS2vvNODEyhSBTqFjav3CiduetD60Q8cj9lFNxNDB26MVkgM1o27nR6w== X-Received: by 2002:adf:f189:: with SMTP id h9mr10660364wro.35.1545052778948; Mon, 17 Dec 2018 05:19:38 -0800 (PST) Received: from kmo-pixel.syslink.intern ([93.240.4.121]) by smtp.gmail.com with ESMTPSA id x20sm20406120wme.6.2018.12.17.05.19.37 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 17 Dec 2018 05:19:38 -0800 (PST) From: Kent Overstreet To: akpm@linux-foundation.org, linux-kernel@vger.kernel.org Date: Mon, 17 Dec 2018 08:19:23 -0500 Message-Id: <20181217131929.11727-2-kent.overstreet@gmail.com> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20181217131929.11727-1-kent.overstreet@gmail.com> References: <20181217131929.11727-1-kent.overstreet@gmail.com> MIME-Version: 1.0 X-Spam-Status: No, score=-2.0 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, FREEMAIL_FROM, RCVD_IN_DNSWL_NONE autolearn=ham version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on smtp1.linux-foundation.org Cc: dev@openvswitch.org, Kent Overstreet , Matthew Wilcox Subject: [ovs-dev] [PATCH 1/7] openvswitch: convert to kvmalloc 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 There was no real need for this code to be using flexarrays, it's just implementing a hash table - ideally it would be using rhashtables, but that conversion would be significantly more complicated. Signed-off-by: Kent Overstreet Cc: Pravin B Shelar Cc: dev@openvswitch.org Reviewed-by: Matthew Wilcox --- net/openvswitch/flow.h | 1 - net/openvswitch/flow_netlink.h | 1 - net/openvswitch/flow_table.c | 51 ++++++++-------------------------- net/openvswitch/flow_table.h | 3 +- 4 files changed, 13 insertions(+), 43 deletions(-) diff --git a/net/openvswitch/flow.h b/net/openvswitch/flow.h index c670dd24b8..4f06278166 100644 --- a/net/openvswitch/flow.h +++ b/net/openvswitch/flow.h @@ -30,7 +30,6 @@ #include #include #include -#include #include #include #include diff --git a/net/openvswitch/flow_netlink.h b/net/openvswitch/flow_netlink.h index 6657606b2b..66f9553758 100644 --- a/net/openvswitch/flow_netlink.h +++ b/net/openvswitch/flow_netlink.h @@ -30,7 +30,6 @@ #include #include #include -#include #include #include diff --git a/net/openvswitch/flow_table.c b/net/openvswitch/flow_table.c index 80ea2a7185..cfb0098c9a 100644 --- a/net/openvswitch/flow_table.c +++ b/net/openvswitch/flow_table.c @@ -111,29 +111,6 @@ int ovs_flow_tbl_count(const struct flow_table *table) return table->count; } -static struct flex_array *alloc_buckets(unsigned int n_buckets) -{ - struct flex_array *buckets; - int i, err; - - buckets = flex_array_alloc(sizeof(struct hlist_head), - n_buckets, GFP_KERNEL); - if (!buckets) - return NULL; - - err = flex_array_prealloc(buckets, 0, n_buckets, GFP_KERNEL); - if (err) { - flex_array_free(buckets); - return NULL; - } - - for (i = 0; i < n_buckets; i++) - INIT_HLIST_HEAD((struct hlist_head *) - flex_array_get(buckets, i)); - - return buckets; -} - static void flow_free(struct sw_flow *flow) { int cpu; @@ -168,31 +145,30 @@ void ovs_flow_free(struct sw_flow *flow, bool deferred) flow_free(flow); } -static void free_buckets(struct flex_array *buckets) -{ - flex_array_free(buckets); -} - - static void __table_instance_destroy(struct table_instance *ti) { - free_buckets(ti->buckets); + kvfree(ti->buckets); kfree(ti); } static struct table_instance *table_instance_alloc(int new_size) { struct table_instance *ti = kmalloc(sizeof(*ti), GFP_KERNEL); + int i; if (!ti) return NULL; - ti->buckets = alloc_buckets(new_size); - + ti->buckets = kvmalloc_array(new_size, sizeof(struct hlist_head), + GFP_KERNEL); if (!ti->buckets) { kfree(ti); return NULL; } + + for (i = 0; i < new_size; i++) + INIT_HLIST_HEAD(&ti->buckets[i]); + ti->n_buckets = new_size; ti->node_ver = 0; ti->keep_flows = false; @@ -249,7 +225,7 @@ static void table_instance_destroy(struct table_instance *ti, for (i = 0; i < ti->n_buckets; i++) { struct sw_flow *flow; - struct hlist_head *head = flex_array_get(ti->buckets, i); + struct hlist_head *head = &ti->buckets[i]; struct hlist_node *n; int ver = ti->node_ver; int ufid_ver = ufid_ti->node_ver; @@ -294,7 +270,7 @@ struct sw_flow *ovs_flow_tbl_dump_next(struct table_instance *ti, ver = ti->node_ver; while (*bucket < ti->n_buckets) { i = 0; - head = flex_array_get(ti->buckets, *bucket); + head = &ti->buckets[*bucket]; hlist_for_each_entry_rcu(flow, head, flow_table.node[ver]) { if (i < *last) { i++; @@ -313,8 +289,7 @@ struct sw_flow *ovs_flow_tbl_dump_next(struct table_instance *ti, static struct hlist_head *find_bucket(struct table_instance *ti, u32 hash) { hash = jhash_1word(hash, ti->hash_seed); - return flex_array_get(ti->buckets, - (hash & (ti->n_buckets - 1))); + return &ti->buckets[hash & (ti->n_buckets - 1)]; } static void table_instance_insert(struct table_instance *ti, @@ -347,9 +322,7 @@ static void flow_table_copy_flows(struct table_instance *old, /* Insert in new table. */ for (i = 0; i < old->n_buckets; i++) { struct sw_flow *flow; - struct hlist_head *head; - - head = flex_array_get(old->buckets, i); + struct hlist_head *head = &old->buckets[i]; if (ufid) hlist_for_each_entry(flow, head, diff --git a/net/openvswitch/flow_table.h b/net/openvswitch/flow_table.h index 2dd9900f53..de5ec6cf51 100644 --- a/net/openvswitch/flow_table.h +++ b/net/openvswitch/flow_table.h @@ -29,7 +29,6 @@ #include #include #include -#include #include #include @@ -37,7 +36,7 @@ #include "flow.h" struct table_instance { - struct flex_array *buckets; + struct hlist_head *buckets; unsigned int n_buckets; struct rcu_head rcu; int node_ver;