netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH resend -next] lib/rhashtable: consider param->min_size when setting initial table size
       [not found] ` <20180716000046.yscgnpr256qhm2qg@gondor.apana.org.au>
@ 2018-07-16 20:26   ` Davidlohr Bueso
  2018-07-18 20:28     ` David Miller
  2018-07-17 22:30   ` [PATCH] " Davidlohr Bueso
  1 sibling, 1 reply; 4+ messages in thread
From: Davidlohr Bueso @ 2018-07-16 20:26 UTC (permalink / raw)
  To: Herbert Xu; +Cc: akpm, tgraf, linux-kernel, Davidlohr Bueso, netdev

rhashtable_init() currently does not take into account the user-passed
min_size parameter unless param->nelem_hint is set as well. As such,
the default size (number of buckets) will always be HASH_DEFAULT_SIZE
even if the smallest allowed size is larger than that. Remediate this
by unconditionally calling into rounded_hashtable_size() and handling
things accordingly.

Signed-off-by: Davidlohr Bueso <dbueso@suse.de>
Acked-by: Herbert Xu <herbert@gondor.apana.org.au>
---
Resending per Herbert's request with Cc to netdev.

 lib/rhashtable.c | 17 +++++++++++------
 1 file changed, 11 insertions(+), 6 deletions(-)

diff --git a/lib/rhashtable.c b/lib/rhashtable.c
index 62d3a976614e..310e29b51507 100644
--- a/lib/rhashtable.c
+++ b/lib/rhashtable.c
@@ -953,8 +953,16 @@ EXPORT_SYMBOL_GPL(rhashtable_walk_stop);
 
 static size_t rounded_hashtable_size(const struct rhashtable_params *params)
 {
-	return max(roundup_pow_of_two(params->nelem_hint * 4 / 3),
-		   (unsigned long)params->min_size);
+	size_t retsize;
+
+	if (params->nelem_hint)
+		retsize = max(roundup_pow_of_two(params->nelem_hint * 4 / 3),
+			      (unsigned long)params->min_size);
+	else
+		retsize = max(HASH_DEFAULT_SIZE,
+			      (unsigned long)params->min_size);
+
+	return retsize;
 }
 
 static u32 rhashtable_jhash2(const void *key, u32 length, u32 seed)
@@ -1010,8 +1018,6 @@ int rhashtable_init(struct rhashtable *ht,
 	struct bucket_table *tbl;
 	size_t size;
 
-	size = HASH_DEFAULT_SIZE;
-
 	if ((!params->key_len && !params->obj_hashfn) ||
 	    (params->obj_hashfn && !params->obj_cmpfn))
 		return -EINVAL;
@@ -1035,8 +1041,7 @@ int rhashtable_init(struct rhashtable *ht,
 
 	ht->p.min_size = max_t(u16, ht->p.min_size, HASH_MIN_SIZE);
 
-	if (params->nelem_hint)
-		size = rounded_hashtable_size(&ht->p);
+	size = rounded_hashtable_size(&ht->p);
 
 	if (params->locks_mul)
 		ht->p.locks_mul = roundup_pow_of_two(params->locks_mul);
-- 
2.16.4

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

* Re: [PATCH] lib/rhashtable: consider param->min_size when setting initial table size
       [not found] ` <20180716000046.yscgnpr256qhm2qg@gondor.apana.org.au>
  2018-07-16 20:26   ` [PATCH resend -next] lib/rhashtable: consider param->min_size when setting initial table size Davidlohr Bueso
@ 2018-07-17 22:30   ` Davidlohr Bueso
  2018-07-18  1:58     ` Andrew Morton
  1 sibling, 1 reply; 4+ messages in thread
From: Davidlohr Bueso @ 2018-07-17 22:30 UTC (permalink / raw)
  To: Herbert Xu; +Cc: akpm, tgraf, linux-kernel, Davidlohr Bueso, netdev

On Mon, 16 Jul 2018, Herbert Xu wrote:

>On Fri, Jul 13, 2018 at 11:25:16PM -0700, Davidlohr Bueso wrote:
>> rhashtable_init() currently does not take into account the user-passed
>> min_size parameter unless param->nelem_hint is set as well. As such,
>> the default size (number of buckets) will always be HASH_DEFAULT_SIZE
>> even if the smallest allowed size is larger than that. Remediate this
>> by unconditionally calling into rounded_hashtable_size() and handling
>> things accordingly.
>>
>> Signed-off-by: Davidlohr Bueso <dbueso@suse.de>
>
>Acked-by: Herbert Xu <herbert@gondor.apana.org.au>
>
>Normally these patches go through netdev so could you please resend
>it with my ack to netdev@vger.kernel.org?

So I've done the resend, but at least would think that routing the
patch through Andrew would work best as he picked up the rhashtable
changes regarding ipc and this touches the same call.

Thanks,
Davidlohr

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

* Re: [PATCH] lib/rhashtable: consider param->min_size when setting initial table size
  2018-07-17 22:30   ` [PATCH] " Davidlohr Bueso
@ 2018-07-18  1:58     ` Andrew Morton
  0 siblings, 0 replies; 4+ messages in thread
From: Andrew Morton @ 2018-07-18  1:58 UTC (permalink / raw)
  To: Davidlohr Bueso; +Cc: Herbert Xu, tgraf, linux-kernel, Davidlohr Bueso, netdev

On Tue, 17 Jul 2018 15:30:57 -0700 Davidlohr Bueso <dave@stgolabs.net> wrote:

> On Mon, 16 Jul 2018, Herbert Xu wrote:
> 
> >On Fri, Jul 13, 2018 at 11:25:16PM -0700, Davidlohr Bueso wrote:
> >> rhashtable_init() currently does not take into account the user-passed
> >> min_size parameter unless param->nelem_hint is set as well. As such,
> >> the default size (number of buckets) will always be HASH_DEFAULT_SIZE
> >> even if the smallest allowed size is larger than that. Remediate this
> >> by unconditionally calling into rounded_hashtable_size() and handling
> >> things accordingly.
> >>
> >> Signed-off-by: Davidlohr Bueso <dbueso@suse.de>
> >
> >Acked-by: Herbert Xu <herbert@gondor.apana.org.au>
> >
> >Normally these patches go through netdev so could you please resend
> >it with my ack to netdev@vger.kernel.org?
> 
> So I've done the resend, but at least would think that routing the
> patch through Andrew would work best as he picked up the rhashtable
> changes regarding ipc and this touches the same call.
> 

Either approach works.

Reviewed-by: Andrew Morton <akpm@linux-foundation.org>

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

* Re: [PATCH resend -next] lib/rhashtable: consider param->min_size when setting initial table size
  2018-07-16 20:26   ` [PATCH resend -next] lib/rhashtable: consider param->min_size when setting initial table size Davidlohr Bueso
@ 2018-07-18 20:28     ` David Miller
  0 siblings, 0 replies; 4+ messages in thread
From: David Miller @ 2018-07-18 20:28 UTC (permalink / raw)
  To: dave; +Cc: herbert, akpm, tgraf, linux-kernel, dbueso, netdev

From: Davidlohr Bueso <dave@stgolabs.net>
Date: Mon, 16 Jul 2018 13:26:13 -0700

> rhashtable_init() currently does not take into account the user-passed
> min_size parameter unless param->nelem_hint is set as well. As such,
> the default size (number of buckets) will always be HASH_DEFAULT_SIZE
> even if the smallest allowed size is larger than that. Remediate this
> by unconditionally calling into rounded_hashtable_size() and handling
> things accordingly.
> 
> Signed-off-by: Davidlohr Bueso <dbueso@suse.de>
> Acked-by: Herbert Xu <herbert@gondor.apana.org.au>
> ---
> Resending per Herbert's request with Cc to netdev.

Applied and queued up for -stable, thanks.

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

end of thread, other threads:[~2018-07-18 20:28 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
     [not found] <20180714062516.30433-1-dave@stgolabs.net>
     [not found] ` <20180716000046.yscgnpr256qhm2qg@gondor.apana.org.au>
2018-07-16 20:26   ` [PATCH resend -next] lib/rhashtable: consider param->min_size when setting initial table size Davidlohr Bueso
2018-07-18 20:28     ` David Miller
2018-07-17 22:30   ` [PATCH] " Davidlohr Bueso
2018-07-18  1:58     ` Andrew Morton

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).