netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Thomas Graf <tgraf@suug.ch>
To: Ying Xue <ying.xue@windriver.com>
Cc: davem@davemloft.net, eric.dumazet@gmail.com, netdev@vger.kernel.org
Subject: Re: [PATCH RFC] lib/rhashtable: allow users to set the minimum shifts of shrinking
Date: Wed, 27 Aug 2014 11:34:12 +0100	[thread overview]
Message-ID: <20140827103412.GC13116@casper.infradead.org> (raw)
In-Reply-To: <1409129851-11630-1-git-send-email-ying.xue@windriver.com>

On 08/27/14 at 04:57pm, Ying Xue wrote:
> diff --git a/lib/rhashtable.c b/lib/rhashtable.c
> index a2c7881..1466e2d 100644
> --- a/lib/rhashtable.c
> +++ b/lib/rhashtable.c
> @@ -293,12 +293,15 @@ EXPORT_SYMBOL_GPL(rhashtable_expand);
>  int rhashtable_shrink(struct rhashtable *ht, gfp_t flags)
>  {
>  	struct bucket_table *ntbl, *tbl = rht_dereference(ht->tbl, ht);
> +	size_t min_shift = ilog2(HASH_MIN_SIZE);
>  	struct rhash_head __rcu **pprev;
>  	unsigned int i;
>  
>  	ASSERT_RHT_MUTEX(ht);
>  
> -	if (tbl->size <= HASH_MIN_SIZE)
> +	if (ht->p.min_shift)
> +		min_shift = max(ht->p.min_shift, min_shift);
> +	if (ht->shift <= min_shift)
>  		return 0;

I like it. Can you translate HASH_MIN_SIZE to .minshift in
rhashtable_init()? That way we only have to deal with .min_shift in
rhashtable_shrink().

Note that shrinking can also be disabled by not providing a
.shrink_decision function in rhashtable_params if the shrinking is
too expensive for your case.

> -static size_t rounded_hashtable_size(unsigned int nelem)
> +static size_t rounded_hashtable_size(struct rhashtable_params *params)
>  {
> -	return max(roundup_pow_of_two(nelem * 4 / 3), HASH_MIN_SIZE);
> +	size_t size = HASH_MIN_SIZE;
> +
> +	if (params->min_shift)
> +		size = max((1UL << params->min_shift), HASH_MIN_SIZE);
> +
> +	return max(roundup_pow_of_two(params->nelem_hint * 4 / 3), size);
>  }

Same here. If you merge the provided .min_shift with HASH_MIN_SIZE
in rhashtable_init() before calculating the size, the above logic
can be simplified a lot.

  reply	other threads:[~2014-08-27 10:34 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-08-27  8:57 [PATCH RFC] lib/rhashtable: allow users to set the minimum shifts of shrinking Ying Xue
2014-08-27 10:34 ` Thomas Graf [this message]
2014-08-28  1:04   ` Ying Xue

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20140827103412.GC13116@casper.infradead.org \
    --to=tgraf@suug.ch \
    --cc=davem@davemloft.net \
    --cc=eric.dumazet@gmail.com \
    --cc=netdev@vger.kernel.org \
    --cc=ying.xue@windriver.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).