From c6fadeb1f0488997b44e85a00a8887756232156d Mon Sep 17 00:00:00 2001 From: Ben Pfaff Date: Mon, 27 Dec 2010 16:06:08 -0800 Subject: [PATCH] datapath: Clarify meaning of n_buckets argument to tbl_create(). The n_buckets argument to tbl_create() can be zero, but the comment didn't mention that. However, there's no reason that the caller can't just pass in a correct size, so this commit changes them to do that. Also, TBL_L1_SIZE was conceptually wrong as the minimum size: the minimum size is one L2 page, e.g. TBL_L2_SIZE. But TBL_MIN_BUCKETS seems like a better all-around way to indicate the minimum size, so this commit also introduces that macro and uses it. Jesse Gross pointed out inconsistencies in this area. Signed-off-by: Ben Pfaff Acked-by: Jesse Gross --- datapath/datapath.c | 4 ++-- datapath/table.c | 7 ++----- datapath/table.h | 3 +++ datapath/tunnel.c | 2 +- 4 files changed, 8 insertions(+), 8 deletions(-) diff --git a/datapath/datapath.c b/datapath/datapath.c index 9d6ab863a..a2d395cef 100644 --- a/datapath/datapath.c +++ b/datapath/datapath.c @@ -252,7 +252,7 @@ static int create_dp(int dp_idx, const char __user *devnamep) /* Allocate table. */ err = -ENOMEM; - rcu_assign_pointer(dp->table, tbl_create(0)); + rcu_assign_pointer(dp->table, tbl_create(TBL_MIN_BUCKETS)); if (!dp->table) goto err_free_dp; @@ -653,7 +653,7 @@ static int flush_flows(struct datapath *dp) struct tbl *old_table = get_table_protected(dp); struct tbl *new_table; - new_table = tbl_create(0); + new_table = tbl_create(TBL_MIN_BUCKETS); if (!new_table) return -ENOMEM; diff --git a/datapath/table.c b/datapath/table.c index 280630854..8a1053240 100644 --- a/datapath/table.c +++ b/datapath/table.c @@ -90,16 +90,13 @@ static struct tbl_bucket ***alloc_buckets(unsigned int n_buckets) * @n_buckets: number of buckets in the new table * * Creates and returns a new hash table, or %NULL if memory cannot be - * allocated. @n_buckets must be a power of 2 in the range %TBL_L1_SIZE to + * allocated. @n_buckets must be a power of 2 in the range %TBL_MIN_BUCKETS to * %TBL_MAX_BUCKETS. */ struct tbl *tbl_create(unsigned int n_buckets) { struct tbl *table; - if (!n_buckets) - n_buckets = TBL_L1_SIZE; - table = kzalloc(sizeof *table, GFP_KERNEL); if (!table) goto err; @@ -273,7 +270,7 @@ struct tbl *tbl_expand(struct tbl *table) } err = -ENOMEM; - new_table = tbl_create(n_buckets); + new_table = tbl_create(TBL_MIN_BUCKETS); if (!new_table) goto error; diff --git a/datapath/table.h b/datapath/table.h index 609d9b14b..2fd569b6e 100644 --- a/datapath/table.h +++ b/datapath/table.h @@ -47,6 +47,9 @@ struct tbl { #define TBL_L1_SIZE (1 << TBL_L1_BITS) #define TBL_L1_SHIFT TBL_L2_BITS +/* For 4 kB pages, this is 1,024 on 32-bit or 512 on 64-bit. */ +#define TBL_MIN_BUCKETS TBL_L2_SIZE + /* For 4 kB pages, this is 1,048,576 on 32-bit or 262,144 on 64-bit. */ #define TBL_MAX_BUCKETS (TBL_L1_SIZE * TBL_L2_SIZE) diff --git a/datapath/tunnel.c b/datapath/tunnel.c index bf0ab56bd..c78e7ddf2 100644 --- a/datapath/tunnel.c +++ b/datapath/tunnel.c @@ -237,7 +237,7 @@ static int add_port(struct vport *vport) if (!port_table) { struct tbl *new_table; - new_table = tbl_create(0); + new_table = tbl_create(TBL_MIN_BUCKETS); if (!new_table) return -ENOMEM; -- 2.43.0