Skip to contentSkip to conversation

nft hash set expansion problem

PATCH Josh Hunt 3 participants 5 messages Feb 8, 2015 – Feb 9, 2015

Subsystems (5)
lore
Share & tools
lore

Josh Hunt

author
#0 lore raw

Nft hash sets are unable to expand past the initial # of buckets. This is b/c nft hash sets don't define the max_shift parameter and so rht_grow_above_75():

        return atomic_read(&ht->nelems) > (new_size / 4 * 3) &&
               (ht->p.max_shift && atomic_read(&ht->shift) < 

ht->p.max_shift);

can't return true.

It's not clear to me if this is intentional; requiring users of rhashtables define a max_shift in order to support expansion, or a bug in the grow decision function?

Here's a possible fix if it's the latter. Let me know and I can submit something formal if that's the case.

lib/rhashtable.c +1 -1
index e96fc00..2c51617 100644
@@ -250,7 +250,7 @@ bool rht_grow_above_75(const struct rhashtable *ht, size_t new_size)
 {
        /* Expand table when exceeding 75% load */
        return atomic_read(&ht->nelems) > (new_size / 4 * 3) &&
-              (ht->p.max_shift && atomic_read(&ht->shift) < ht->p.max_shift);
+              (ht->p.max_shift ? atomic_read(&ht->shift) < ht->p.max_shift : 1);
 }
 EXPORT_SYMBOL_GPL(rht_grow_above_75);
 

Thanks
Josh

#1 lore raw
Quoted 1 line · Josh Hunt

Nft hash sets are unable to expand past the initial # of buckets. This is b/c nft hash sets don't define the max_shift parameter and so rht_grow_above_75():

...

lib/rhashtable.c bool rht_grow_above_75(const struct rhashtable *ht, size_t new_size) · line 255

Quoted 12 lines
lib/rhashtable.c +1 -1
index e96fc00..2c51617 100644
@@ -250,7 +250,7 @@ bool rht_grow_above_75(const struct rhashtable *ht, size_t new_size)
  {
         /* Expand table when exceeding 75% load */
         return atomic_read(&ht->nelems) > (new_size / 4 * 3) &&
-              (ht->p.max_shift && atomic_read(&ht->shift) < ht->p.max_shift);
+              (ht->p.max_shift ? atomic_read(&ht->shift) < ht->p.max_shift : 1);
  }
  EXPORT_SYMBOL_GPL(rht_grow_above_75);

This seems not correct as we want to have an upper limit for rhashtable expansions. It's better to define a max_shift for nftables, instead.

author
#2 lore raw
Quoted 16 lines · Daniel Borkmann
Quoted 3 lines · Josh Hunt

Nft hash sets are unable to expand past the initial # of buckets. This is b/c nft hash sets don't define the max_shift parameter and so rht_grow_above_75():

...

Quoted 11 lines
lib/rhashtable.c +0 -1
index e96fc00..2c51617 100644
@@ -250,7 +250,7 @@ bool rht_grow_above_75(const struct rhashtable
 *ht, size_t new_size)
  {
         /* Expand table when exceeding 75% load */
         return atomic_read(&ht->nelems) > (new_size / 4 * 3) &&
-              (ht->p.max_shift && atomic_read(&ht->shift) <
 ht->p.max_shift);
Quoted 8 lines
Quoted 4 lines
lib/rhashtable.c +1 -0
+              (ht->p.max_shift ? atomic_read(&ht->shift) <
 ht->p.max_shift : 1);
  }
  EXPORT_SYMBOL_GPL(rht_grow_above_75);

This seems not correct as we want to have an upper limit for rhashtable expansions. It's better to define a max_shift for nftables, instead.

Thanks Daniel that's what I wanted to know. I'll fix this on the nft_hash side.

Josh

maintainer
#3 lore raw
Quoted 7 lines · Josh Hunt
Quoted 3 lines · Daniel Borkmann

This seems not correct as we want to have an upper limit for rhashtable expansions. It's better to define a max_shift for nftables, instead.

Thanks Daniel that's what I wanted to know. I'll fix this on the nft_hash side.

I agree it does not make sense to allow unlimited growth. Can you enforce a max_shift > 0 in rhashtable_init() while you are at it?

author
#4 lore raw
Quoted 6 lines · Thomas Graf
Quoted 5 lines · Josh Hunt
Quoted 3 lines · Daniel Borkmann

This seems not correct as we want to have an upper limit for rhashtable expansions. It's better to define a max_shift for nftables, instead.

Quoted 7 lines
Quoted 2 lines

Thanks Daniel that's what I wanted to know. I'll fix this on the nft_hash side.

I agree it does not make sense to allow unlimited growth. Can you enforce a max_shift > 0 in rhashtable_init() while you are at it?

Yeah I'll do that as well.