netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] rhashtable: don't attempt to grow when at max_size
@ 2015-04-23 14:38 Johannes Berg
  2015-04-23 15:59 ` David Miller
  2015-04-23 20:46 ` [PATCH] rhashtable: don't attempt to grow when at max_size Thomas Graf
  0 siblings, 2 replies; 26+ messages in thread
From: Johannes Berg @ 2015-04-23 14:38 UTC (permalink / raw)
  To: netdev; +Cc: Patrick McHardy, Thomas Graf, Johannes Berg

From: Johannes Berg <johannes.berg@intel.com>

The conversion of mac80211's station table to rhashtable had a bug
that I found by accident in code review, that hadn't been found as
rhashtable apparently managed to have a maximum hash chain length
of one (!) in all our testing.

In order to test the bug and verify the fix I set my rhashtable's
max_size very low (4) in order to force getting hash collisions.

At that point, rhashtable WARNed in rhashtable_insert_rehash() but
didn't actually reject the hash table insertion. This caused it to
lose insertions - my master list of stations would have 9 entries,
but the rhashtable only had 5. This may warrant a deeper look, but
that WARN_ON() just shouldn't happen.

Fix this by not returning true from rht_grow_above_100() when the
rhashtable's max_size has been reached - in this case the user is
explicitly configuring it to be at most that big, so even if it's
now above 100% it shouldn't attempt to resize.

This fixes the "lost insertion" issue and consequently allows my
code to display its error (and verify my fix for it.)

Signed-off-by: Johannes Berg <johannes.berg@intel.com>
---
 include/linux/rhashtable.h | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/include/linux/rhashtable.h b/include/linux/rhashtable.h
index e23d242d1230..dbcbcc59aa92 100644
--- a/include/linux/rhashtable.h
+++ b/include/linux/rhashtable.h
@@ -282,7 +282,8 @@ static inline bool rht_shrink_below_30(const struct rhashtable *ht,
 static inline bool rht_grow_above_100(const struct rhashtable *ht,
 				      const struct bucket_table *tbl)
 {
-	return atomic_read(&ht->nelems) > tbl->size;
+	return atomic_read(&ht->nelems) > tbl->size &&
+		(!ht->p.max_size || tbl->size < ht->p.max_size);
 }
 
 /* The bucket lock is selected based on the hash and protects mutations
-- 
2.1.4

^ permalink raw reply related	[flat|nested] 26+ messages in thread

end of thread, other threads:[~2015-05-19 10:27 UTC | newest]

Thread overview: 26+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2015-04-23 14:38 [PATCH] rhashtable: don't attempt to grow when at max_size Johannes Berg
2015-04-23 15:59 ` David Miller
2015-04-23 16:09   ` Johannes Berg
2015-04-23 16:16     ` Daniel Borkmann
2015-04-24  0:57   ` rhashtable: Add cap on number of elements in hash table Herbert Xu
2015-04-24  7:01     ` Johannes Berg
2015-04-24  8:04       ` Herbert Xu
2015-04-24  8:06     ` Thomas Graf
2015-04-24  8:12       ` Herbert Xu
2015-04-24  8:15         ` Thomas Graf
2015-04-24  8:22           ` Herbert Xu
2015-04-24 15:38             ` David Miller
2015-05-13  8:06     ` Herbert Xu
2015-05-15  2:22       ` David Miller
2015-05-15  3:06         ` Herbert Xu
2015-05-15  3:46           ` David Miller
2015-05-15  6:30             ` Herbert Xu
2015-05-16 22:09               ` David Miller
2015-05-17  1:38                 ` Herbert Xu
2015-05-18 20:12                   ` David Miller
2015-05-18 22:35                     ` Herbert Xu
2015-05-19 10:25                       ` David Laight
2015-05-15  3:30       ` [v2 PATCH] " Herbert Xu
2015-05-16 22:08         ` David Miller
2015-04-23 20:46 ` [PATCH] rhashtable: don't attempt to grow when at max_size Thomas Graf
2015-04-23 20:49   ` Johannes Berg

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).