Skip to content

Commit

Permalink
datapath: convert to kvmalloc
Browse files Browse the repository at this point in the history
Upstream commit:
    commit ee9c5e67557f9663b27946ba1d3813fb1924b1fe
    Author: Kent Overstreet <[email protected]>
    Date:   Mon Mar 11 23:31:02 2019 -0700

    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/[email protected]
    Signed-off-by: Kent Overstreet <[email protected]>
    Reviewed-by: Matthew Wilcox <[email protected]>
    Cc: Pravin B Shelar <[email protected]>
    Cc: Alexey Dobriyan <[email protected]>
    Cc: Al Viro <[email protected]>
    Cc: Dave Hansen <[email protected]>
    Cc: Eric Paris <[email protected]>
    Cc: Marcelo Ricardo Leitner <[email protected]>
    Cc: Neil Horman <[email protected]>
    Cc: Paul Moore <[email protected]>
    Cc: Shaohua Li <[email protected]>
    Cc: Stephen Smalley <[email protected]>
    Cc: Vlad Yasevich <[email protected]>
    Signed-off-by: Andrew Morton <[email protected]>
    Signed-off-by: Linus Torvalds <[email protected]>

Cc: Kent Overstreet <[email protected]>
Reviewed-by: Yifeng Sun <[email protected]>
Signed-off-by: Greg Rose <[email protected]>
Signed-off-by: Ben Pfaff <[email protected]>
  • Loading branch information
koverstreet authored and blp committed Apr 17, 2019
1 parent a53a7e0 commit 4383e54
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 43 deletions.
1 change: 0 additions & 1 deletion datapath/flow.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@
#include <linux/in6.h>
#include <linux/jiffies.h>
#include <linux/time.h>
#include <linux/flex_array.h>
#include <linux/cpumask.h>
#include <net/inet_ecn.h>
#include <net/ip_tunnels.h>
Expand Down
1 change: 0 additions & 1 deletion datapath/flow_netlink.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@
#include <linux/in6.h>
#include <linux/jiffies.h>
#include <linux/time.h>
#include <linux/flex_array.h>

#include <net/inet_ecn.h>
#include <net/ip_tunnels.h>
Expand Down
51 changes: 12 additions & 39 deletions datapath/flow_table.c
Original file line number Diff line number Diff line change
Expand Up @@ -117,29 +117,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;
Expand Down Expand Up @@ -174,31 +151,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;
Expand Down Expand Up @@ -319,7 +295,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;
Expand Down Expand Up @@ -366,7 +342,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++;
Expand All @@ -385,8 +361,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,
Expand Down Expand Up @@ -419,9 +394,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,
Expand Down
3 changes: 1 addition & 2 deletions datapath/flow_table.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@
#include <linux/in6.h>
#include <linux/jiffies.h>
#include <linux/time.h>
#include <linux/flex_array.h>

#include <net/inet_ecn.h>
#include <net/ip_tunnels.h>
Expand All @@ -48,7 +47,7 @@ struct mask_array {
};

struct table_instance {
struct flex_array *buckets;
struct hlist_head *buckets;
unsigned int n_buckets;
struct rcu_head rcu;
int node_ver;
Expand Down

0 comments on commit 4383e54

Please sign in to comment.