Received: by 2002:ac0:a594:0:0:0:0:0 with SMTP id m20-v6csp783004imm; Wed, 23 May 2018 05:35:13 -0700 (PDT) X-Google-Smtp-Source: AB8JxZqEP9I6GGHGbT6/xAA29bTLtMxjmfayVKDS3te315mJIyv8nNjMsJvu7ny/i3GL60os2hDu X-Received: by 2002:a63:6185:: with SMTP id v127-v6mr1931785pgb.301.1527078907195; Wed, 23 May 2018 05:35:07 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1527078907; cv=none; d=google.com; s=arc-20160816; b=fP1mtSKOQgodNYCij9ozJR+cB0PmO3Ysp8uAlG1O0g1VMF8rV4NyxfD1xkolM3f+iP q5BdrLoXgYjBVBUzRaCOa9iml6jL3wqRlRUKf0P6RS9kH46hyLNBE9Rl/SttsjFTL9a+ GSr1k6kyMCiTwOIMj46Uefqc3MR5z62lYJPBriA13bVAqTfRJDRA9O5ARfibBbsDcxuJ PQ2GX8wBnwn+9Yi7QwkNKSJIBqrv2SRPhGDoUHtDHspkjVKXV6jilC9+FnDjkmpA5ofd BRO/TMNG9x13chTJ7HdcpM9va1IYsslYc/4t5D1drC+Y/5OrD+sCnfQA55KKbx+70o9d jkIw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:user-agent:in-reply-to :content-disposition:mime-version:references:message-id:subject:cc :to:from:date:dkim-signature:arc-authentication-results; bh=pVq97Uiq0a1oeN11rmCX4Cl78IJme5wVQuxjcZr4ztE=; b=knd10cDbvBYS99ZjJ0tVQ08mL96fHxZAWk9tVTh8vKkXkVUJ7AjfKkafroa+SgYdtk GZeRtOecFUBV5xK3EaW0Outsn540WFqS4QN/B9EBoNq46Hfy2Lqx5idniw/LgKTEZezZ sjACGJpSpWaph+H+nAkKSlGiTFyvf3ppNkslELRxZ831dacLccW374hLZpTuuOt08WHi noumTVs8MwiQQuvZM/XH2ldXn6e4mX87RLihmC8dYhmQeDrDWyYigHRHDAnBGzs6k/10 5jUhA+WT39FRzUtHQzKfWtVgfKzu8iZFRFveowgouSComtIqrgULluuAXyjZzxft0pLE WyzQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@infradead.org header.s=bombadil.20170209 header.b=WWMHc6lo; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id 34-v6si18243908plb.230.2018.05.23.05.34.51; Wed, 23 May 2018 05:35:06 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=fail header.i=@infradead.org header.s=bombadil.20170209 header.b=WWMHc6lo; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S932715AbeEWMeF (ORCPT + 99 others); Wed, 23 May 2018 08:34:05 -0400 Received: from bombadil.infradead.org ([198.137.202.133]:41964 "EHLO bombadil.infradead.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S932070AbeEWMeD (ORCPT ); Wed, 23 May 2018 08:34:03 -0400 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=bombadil.20170209; h=In-Reply-To:Content-Type:MIME-Version :References:Message-ID:Subject:Cc:To:From:Date:Sender:Reply-To: Content-Transfer-Encoding:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Id: List-Help:List-Unsubscribe:List-Subscribe:List-Post:List-Owner:List-Archive; bh=pVq97Uiq0a1oeN11rmCX4Cl78IJme5wVQuxjcZr4ztE=; b=WWMHc6logkbN0vVLtpKDWb+7L KnhErISJwknQaSUCN9A9W1JnPxDdImVcbNNOpQwDRk/Hjm4yCAPB7NxVSR8MNygpkX727MVhcATJe lVwC0aODVmLfp4LmTPMgmIqhhAoq2y1ui1b53pS52qSBsmhYEBUu+JKGKlO9PWmMXFD1jXOmqbQZX z7clYHHcGxkQiVbrrL8hPUZak9l9DpSGdSNrx84DE+agPREvjMLlJ48cgwKJY/FxfMM91mOLA8iBW cSBOEsoIxghIVjyCcgKrwlYu9FknD2oLakH/hlYzSgmR2tvhhlvOqHkQJmrZOqGHpzgwGo2p7WVKH pRGJWCnQg==; Received: from willy by bombadil.infradead.org with local (Exim 4.90_1 #2 (Red Hat Linux)) id 1fLSxt-0000Oy-RM; Wed, 23 May 2018 12:34:01 +0000 Date: Wed, 23 May 2018 05:34:01 -0700 From: Matthew Wilcox To: Kent Overstreet Cc: linux-kernel@vger.kernel.org, viro@zeniv.linux.org.uk, akpm@linux-foundation.org, gregkh@linuxfoundation.org, linux-security-module@vger.kernel.org, selinux@tycho.nsa.gov, dev@openvswitch.org, shli@kernel.org, linux-raid@vger.kernel.org Subject: Re: [PATCH 4/6] openvswitch: convert to genradix Message-ID: <20180523123401.GB19987@bombadil.infradead.org> References: <20180523011821.12165-1-kent.overstreet@gmail.com> <20180523011821.12165-4-kent.overstreet@gmail.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20180523011821.12165-4-kent.overstreet@gmail.com> User-Agent: Mutt/1.9.2 (2017-12-15) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Tue, May 22, 2018 at 09:18:19PM -0400, Kent Overstreet wrote: > the new generic radix trees have a simpler API and implementation, and > no limitations on number of elements, so all flex_array users are being > converted This doesn't really feel like it should be a flexarray / genradix user. It just wants to allocate a lot of buckets and use them. Maybe kvmalloc is the right approach for this user of flexarray? Signed-off-by: Matthew Wilcox net/openvswitch/flow.h | 1 - net/openvswitch/flow_netlink.h | 1 - net/openvswitch/flow_table.c | 49 +++++++++++------------------------------- net/openvswitch/flow_table.h | 3 +-- 4 files changed, 13 insertions(+), 41 deletions(-) diff --git a/net/openvswitch/flow.h b/net/openvswitch/flow.h index c670dd24b8b7..4f06278166d9 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 6657606b2b47..66f9553758a5 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 80ea2a71852e..909372bd2621 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(sizeof(struct hlist_head) * new_size, + 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, @@ -349,7 +324,7 @@ static void flow_table_copy_flows(struct table_instance *old, struct sw_flow *flow; struct hlist_head *head; - head = flex_array_get(old->buckets, i); + 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 2dd9900f533d..de5ec6cf5174 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;