Skip to content

Commit ee9c5e6

Browse files
koverstreettorvalds
authored andcommitted
openvswitch: convert to kvmalloc
Patch series "generic radix trees; drop flex arrays". This patch (of 7): 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. Link: http://lkml.kernel.org/r/20181217131929.11727-2-kent.overstreet@gmail.com Signed-off-by: Kent Overstreet <kent.overstreet@gmail.com> Reviewed-by: Matthew Wilcox <willy@infradead.org> Cc: Pravin B Shelar <pshelar@ovn.org> Cc: Alexey Dobriyan <adobriyan@gmail.com> Cc: Al Viro <viro@zeniv.linux.org.uk> Cc: Dave Hansen <dave.hansen@intel.com> Cc: Eric Paris <eparis@parisplace.org> Cc: Marcelo Ricardo Leitner <marcelo.leitner@gmail.com> Cc: Neil Horman <nhorman@tuxdriver.com> Cc: Paul Moore <paul@paul-moore.com> Cc: Shaohua Li <shli@kernel.org> Cc: Stephen Smalley <sds@tycho.nsa.gov> Cc: Vlad Yasevich <vyasevich@gmail.com> Signed-off-by: Andrew Morton <akpm@linux-foundation.org> Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
1 parent 5c01a25 commit ee9c5e6

File tree

4 files changed

+13
-43
lines changed

4 files changed

+13
-43
lines changed

net/openvswitch/flow.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,6 @@
3030
#include <linux/in6.h>
3131
#include <linux/jiffies.h>
3232
#include <linux/time.h>
33-
#include <linux/flex_array.h>
3433
#include <linux/cpumask.h>
3534
#include <net/inet_ecn.h>
3635
#include <net/ip_tunnels.h>

net/openvswitch/flow_netlink.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,6 @@
3030
#include <linux/in6.h>
3131
#include <linux/jiffies.h>
3232
#include <linux/time.h>
33-
#include <linux/flex_array.h>
3433

3534
#include <net/inet_ecn.h>
3635
#include <net/ip_tunnels.h>

net/openvswitch/flow_table.c

Lines changed: 12 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -111,29 +111,6 @@ int ovs_flow_tbl_count(const struct flow_table *table)
111111
return table->count;
112112
}
113113

114-
static struct flex_array *alloc_buckets(unsigned int n_buckets)
115-
{
116-
struct flex_array *buckets;
117-
int i, err;
118-
119-
buckets = flex_array_alloc(sizeof(struct hlist_head),
120-
n_buckets, GFP_KERNEL);
121-
if (!buckets)
122-
return NULL;
123-
124-
err = flex_array_prealloc(buckets, 0, n_buckets, GFP_KERNEL);
125-
if (err) {
126-
flex_array_free(buckets);
127-
return NULL;
128-
}
129-
130-
for (i = 0; i < n_buckets; i++)
131-
INIT_HLIST_HEAD((struct hlist_head *)
132-
flex_array_get(buckets, i));
133-
134-
return buckets;
135-
}
136-
137114
static void flow_free(struct sw_flow *flow)
138115
{
139116
int cpu;
@@ -168,31 +145,30 @@ void ovs_flow_free(struct sw_flow *flow, bool deferred)
168145
flow_free(flow);
169146
}
170147

171-
static void free_buckets(struct flex_array *buckets)
172-
{
173-
flex_array_free(buckets);
174-
}
175-
176-
177148
static void __table_instance_destroy(struct table_instance *ti)
178149
{
179-
free_buckets(ti->buckets);
150+
kvfree(ti->buckets);
180151
kfree(ti);
181152
}
182153

183154
static struct table_instance *table_instance_alloc(int new_size)
184155
{
185156
struct table_instance *ti = kmalloc(sizeof(*ti), GFP_KERNEL);
157+
int i;
186158

187159
if (!ti)
188160
return NULL;
189161

190-
ti->buckets = alloc_buckets(new_size);
191-
162+
ti->buckets = kvmalloc_array(new_size, sizeof(struct hlist_head),
163+
GFP_KERNEL);
192164
if (!ti->buckets) {
193165
kfree(ti);
194166
return NULL;
195167
}
168+
169+
for (i = 0; i < new_size; i++)
170+
INIT_HLIST_HEAD(&ti->buckets[i]);
171+
196172
ti->n_buckets = new_size;
197173
ti->node_ver = 0;
198174
ti->keep_flows = false;
@@ -249,7 +225,7 @@ static void table_instance_destroy(struct table_instance *ti,
249225

250226
for (i = 0; i < ti->n_buckets; i++) {
251227
struct sw_flow *flow;
252-
struct hlist_head *head = flex_array_get(ti->buckets, i);
228+
struct hlist_head *head = &ti->buckets[i];
253229
struct hlist_node *n;
254230
int ver = ti->node_ver;
255231
int ufid_ver = ufid_ti->node_ver;
@@ -294,7 +270,7 @@ struct sw_flow *ovs_flow_tbl_dump_next(struct table_instance *ti,
294270
ver = ti->node_ver;
295271
while (*bucket < ti->n_buckets) {
296272
i = 0;
297-
head = flex_array_get(ti->buckets, *bucket);
273+
head = &ti->buckets[*bucket];
298274
hlist_for_each_entry_rcu(flow, head, flow_table.node[ver]) {
299275
if (i < *last) {
300276
i++;
@@ -313,8 +289,7 @@ struct sw_flow *ovs_flow_tbl_dump_next(struct table_instance *ti,
313289
static struct hlist_head *find_bucket(struct table_instance *ti, u32 hash)
314290
{
315291
hash = jhash_1word(hash, ti->hash_seed);
316-
return flex_array_get(ti->buckets,
317-
(hash & (ti->n_buckets - 1)));
292+
return &ti->buckets[hash & (ti->n_buckets - 1)];
318293
}
319294

320295
static void table_instance_insert(struct table_instance *ti,
@@ -347,9 +322,7 @@ static void flow_table_copy_flows(struct table_instance *old,
347322
/* Insert in new table. */
348323
for (i = 0; i < old->n_buckets; i++) {
349324
struct sw_flow *flow;
350-
struct hlist_head *head;
351-
352-
head = flex_array_get(old->buckets, i);
325+
struct hlist_head *head = &old->buckets[i];
353326

354327
if (ufid)
355328
hlist_for_each_entry(flow, head,

net/openvswitch/flow_table.h

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,15 +29,14 @@
2929
#include <linux/in6.h>
3030
#include <linux/jiffies.h>
3131
#include <linux/time.h>
32-
#include <linux/flex_array.h>
3332

3433
#include <net/inet_ecn.h>
3534
#include <net/ip_tunnels.h>
3635

3736
#include "flow.h"
3837

3938
struct table_instance {
40-
struct flex_array *buckets;
39+
struct hlist_head *buckets;
4140
unsigned int n_buckets;
4241
struct rcu_head rcu;
4342
int node_ver;

0 commit comments

Comments
 (0)