diff options
author | Kent Overstreet <kent.overstreet@gmail.com> | 2019-03-12 02:31:02 -0400 |
---|---|---|
committer | Linus Torvalds <torvalds@linux-foundation.org> | 2019-03-12 13:04:02 -0400 |
commit | ee9c5e67557f9663b27946ba1d3813fb1924b1fe (patch) | |
tree | d747d51b617865467b8bf72c53c0ebd54b81757d /net/openvswitch/flow_table.c | |
parent | 5c01a25a210366362a40dc63f550e72688a60c48 (diff) |
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>
Diffstat (limited to 'net/openvswitch/flow_table.c')
-rw-r--r-- | net/openvswitch/flow_table.c | 51 |
1 files changed, 12 insertions, 39 deletions
diff --git a/net/openvswitch/flow_table.c b/net/openvswitch/flow_table.c index 80ea2a71852e..cfb0098c9a01 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) | |||
111 | return table->count; | 111 | return table->count; |
112 | } | 112 | } |
113 | 113 | ||
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 | |||
137 | static void flow_free(struct sw_flow *flow) | 114 | static void flow_free(struct sw_flow *flow) |
138 | { | 115 | { |
139 | int cpu; | 116 | int cpu; |
@@ -168,31 +145,30 @@ void ovs_flow_free(struct sw_flow *flow, bool deferred) | |||
168 | flow_free(flow); | 145 | flow_free(flow); |
169 | } | 146 | } |
170 | 147 | ||
171 | static void free_buckets(struct flex_array *buckets) | ||
172 | { | ||
173 | flex_array_free(buckets); | ||
174 | } | ||
175 | |||
176 | |||
177 | static void __table_instance_destroy(struct table_instance *ti) | 148 | static void __table_instance_destroy(struct table_instance *ti) |
178 | { | 149 | { |
179 | free_buckets(ti->buckets); | 150 | kvfree(ti->buckets); |
180 | kfree(ti); | 151 | kfree(ti); |
181 | } | 152 | } |
182 | 153 | ||
183 | static struct table_instance *table_instance_alloc(int new_size) | 154 | static struct table_instance *table_instance_alloc(int new_size) |
184 | { | 155 | { |
185 | struct table_instance *ti = kmalloc(sizeof(*ti), GFP_KERNEL); | 156 | struct table_instance *ti = kmalloc(sizeof(*ti), GFP_KERNEL); |
157 | int i; | ||
186 | 158 | ||
187 | if (!ti) | 159 | if (!ti) |
188 | return NULL; | 160 | return NULL; |
189 | 161 | ||
190 | ti->buckets = alloc_buckets(new_size); | 162 | ti->buckets = kvmalloc_array(new_size, sizeof(struct hlist_head), |
191 | 163 | GFP_KERNEL); | |
192 | if (!ti->buckets) { | 164 | if (!ti->buckets) { |
193 | kfree(ti); | 165 | kfree(ti); |
194 | return NULL; | 166 | return NULL; |
195 | } | 167 | } |
168 | |||
169 | for (i = 0; i < new_size; i++) | ||
170 | INIT_HLIST_HEAD(&ti->buckets[i]); | ||
171 | |||
196 | ti->n_buckets = new_size; | 172 | ti->n_buckets = new_size; |
197 | ti->node_ver = 0; | 173 | ti->node_ver = 0; |
198 | ti->keep_flows = false; | 174 | ti->keep_flows = false; |
@@ -249,7 +225,7 @@ static void table_instance_destroy(struct table_instance *ti, | |||
249 | 225 | ||
250 | for (i = 0; i < ti->n_buckets; i++) { | 226 | for (i = 0; i < ti->n_buckets; i++) { |
251 | struct sw_flow *flow; | 227 | struct sw_flow *flow; |
252 | struct hlist_head *head = flex_array_get(ti->buckets, i); | 228 | struct hlist_head *head = &ti->buckets[i]; |
253 | struct hlist_node *n; | 229 | struct hlist_node *n; |
254 | int ver = ti->node_ver; | 230 | int ver = ti->node_ver; |
255 | int ufid_ver = ufid_ti->node_ver; | 231 | int ufid_ver = ufid_ti->node_ver; |
@@ -294,7 +270,7 @@ struct sw_flow *ovs_flow_tbl_dump_next(struct table_instance *ti, | |||
294 | ver = ti->node_ver; | 270 | ver = ti->node_ver; |
295 | while (*bucket < ti->n_buckets) { | 271 | while (*bucket < ti->n_buckets) { |
296 | i = 0; | 272 | i = 0; |
297 | head = flex_array_get(ti->buckets, *bucket); | 273 | head = &ti->buckets[*bucket]; |
298 | hlist_for_each_entry_rcu(flow, head, flow_table.node[ver]) { | 274 | hlist_for_each_entry_rcu(flow, head, flow_table.node[ver]) { |
299 | if (i < *last) { | 275 | if (i < *last) { |
300 | i++; | 276 | i++; |
@@ -313,8 +289,7 @@ struct sw_flow *ovs_flow_tbl_dump_next(struct table_instance *ti, | |||
313 | static struct hlist_head *find_bucket(struct table_instance *ti, u32 hash) | 289 | static struct hlist_head *find_bucket(struct table_instance *ti, u32 hash) |
314 | { | 290 | { |
315 | hash = jhash_1word(hash, ti->hash_seed); | 291 | hash = jhash_1word(hash, ti->hash_seed); |
316 | return flex_array_get(ti->buckets, | 292 | return &ti->buckets[hash & (ti->n_buckets - 1)]; |
317 | (hash & (ti->n_buckets - 1))); | ||
318 | } | 293 | } |
319 | 294 | ||
320 | static void table_instance_insert(struct table_instance *ti, | 295 | static void table_instance_insert(struct table_instance *ti, |
@@ -347,9 +322,7 @@ static void flow_table_copy_flows(struct table_instance *old, | |||
347 | /* Insert in new table. */ | 322 | /* Insert in new table. */ |
348 | for (i = 0; i < old->n_buckets; i++) { | 323 | for (i = 0; i < old->n_buckets; i++) { |
349 | struct sw_flow *flow; | 324 | struct sw_flow *flow; |
350 | struct hlist_head *head; | 325 | struct hlist_head *head = &old->buckets[i]; |
351 | |||
352 | head = flex_array_get(old->buckets, i); | ||
353 | 326 | ||
354 | if (ufid) | 327 | if (ufid) |
355 | hlist_for_each_entry(flow, head, | 328 | hlist_for_each_entry(flow, head, |