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>
/* 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;
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;
* @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;
}
err = -ENOMEM;
- new_table = tbl_create(n_buckets);
+ new_table = tbl_create(TBL_MIN_BUCKETS);
if (!new_table)
goto error;
#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)
if (!port_table) {
struct tbl *new_table;
- new_table = tbl_create(0);
+ new_table = tbl_create(TBL_MIN_BUCKETS);
if (!new_table)
return -ENOMEM;