datapath: Clarify meaning of n_buckets argument to tbl_create().
authorBen Pfaff <blp@nicira.com>
Tue, 28 Dec 2010 00:06:08 +0000 (16:06 -0800)
committerBen Pfaff <blp@nicira.com>
Tue, 28 Dec 2010 17:17:12 +0000 (09:17 -0800)
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 <blp@nicira.com>
Acked-by: Jesse Gross <jesse@nicira.com>
datapath/datapath.c
datapath/table.c
datapath/table.h
datapath/tunnel.c

index 9d6ab86..a2d395c 100644 (file)
@@ -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;
 
index 2806308..8a10532 100644 (file)
@@ -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;
 
index 609d9b1..2fd569b 100644 (file)
@@ -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)
 
index bf0ab56..c78e7dd 100644 (file)
@@ -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;