netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Thomas Graf <tgraf@suug.ch>
To: Herbert Xu <herbert@gondor.apana.org.au>
Cc: David Miller <davem@davemloft.net>,
	netdev@vger.kernel.org, josh@joshtriplett.org,
	"Paul E. McKenney" <paulmck@linux.vnet.ibm.com>
Subject: Re: [PATCH 2/2] rhashtable: Add arbitrary rehash function
Date: Tue, 10 Mar 2015 18:17:20 +0000	[thread overview]
Message-ID: <20150310181720.GB13155@casper.infradead.org> (raw)
In-Reply-To: <E1YV69U-0003Dq-HS@gondolin.me.apana.org.au>

On 03/10/15 at 09:27am, Herbert Xu wrote:
> This patch adds a rehash function that supports the use of any
> hash function for the new table.  This is needed to support changing
> the random seed value during the lifetime of the hash table.
> 
> However for now the random seed value is still constant and the
> rehash function is simply used to replace the existing expand/shrink
> functions.
> 
> Signed-off-by: Herbert Xu <herbert.xu@redhat.com>

> +static int rhashtable_rehash_one(struct rhashtable *ht, unsigned old_hash)
> +	struct bucket_table *new_tbl = rht_dereference(ht->future_tbl, ht);
> +	struct bucket_table *old_tbl = rht_dereference(ht->tbl, ht);
> +	struct rhash_head __rcu **pprev = &old_tbl->buckets[old_hash];

[...]

I absolutely love the simplification this brings. Looks great. I now
also understand what you meant with entry for entry rehashing.

> +static void rhashtable_rehash(struct rhashtable *ht,
> +			      struct bucket_table *new_tbl)
>  {
> -	ASSERT_BUCKET_LOCK(ht, new_tbl, new_hash);
> +	struct bucket_table *old_tbl = rht_dereference(ht->tbl, ht);
> +	unsigned old_hash;
> +
> +	get_random_bytes(&new_tbl->hash_rnd, sizeof(new_tbl->hash_rnd));
> +
> +	/* Make insertions go into the new, empty table right away. Deletions
> +	 * and lookups will be attempted in both tables until we synchronize.
> +	 * The synchronize_rcu() guarantees for the new table to be picked up
> +	 * so no new additions go into the old table while we relink.
> +	 */
> +	rcu_assign_pointer(ht->future_tbl, new_tbl);

I think you need an rcu_synchronize() here. rhashtable_remove() must
be guaranteed to either see tbl != old_tbl and thus consider both
tables or the rehashing must be guaranteed to not start for an already
started removal. 

> -static void __rhashtable_insert(struct rhashtable *ht, struct rhash_head *obj,
> -				struct bucket_table *tbl,
> -				const struct bucket_table *old_tbl, u32 hash)
> +bool __rhashtable_insert(struct rhashtable *ht, struct rhash_head *obj,
> +			 bool (*compare)(void *, void *), void *arg)

Why make this non-static? We already have rhashtable_lookup_compare_insert()
exported.

> +bool __rhashtable_remove(struct rhashtable *ht, struct bucket_table *tbl,
> +			 struct rhash_head *obj)

Same here.

  reply	other threads:[~2015-03-10 18:17 UTC|newest]

Thread overview: 35+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-01-31 10:21 rhashtable: Move hash_rnd into bucket_table Herbert Xu
2015-01-31 10:23 ` [RFC] rhashtable: rhashtable_rehash Herbert Xu
2015-02-02 11:16   ` Thomas Graf
2015-03-09 10:13     ` Herbert Xu
2015-01-31 11:17 ` rhashtable: Move hash_rnd into bucket_table Thomas Graf
2015-02-03  3:19 ` David Miller
2015-02-03  3:26   ` David Miller
2015-02-03 20:17     ` Herbert Xu
2015-02-03 20:32       ` [PATCH 0/4] rhashtable: Add iterators and use them Herbert Xu
2015-02-03 20:33         ` [PATCH 1/4] rhashtable: Fix potential crash on destroy in rhashtable_shrink Herbert Xu
2015-02-03 20:33         ` [PATCH 2/4] rhashtable: Introduce rhashtable_walk_* Herbert Xu
2015-02-03 20:33         ` [PATCH 3/4] netlink: Use rhashtable walk iterator Herbert Xu
2015-02-05  0:25           ` Thomas Graf
2015-02-03 20:33         ` [PATCH 4/4] netfilter: " Herbert Xu
2015-02-05  4:35         ` [PATCH 0/4] rhashtable: Add iterators and use them David Miller
2015-03-09  9:58       ` rhashtable: Move hash_rnd into bucket_table Herbert Xu
2015-03-09 16:26         ` Daniel Borkmann
2015-03-09 22:21           ` Herbert Xu
2015-03-09 19:51         ` David Miller
2015-03-09 19:55           ` David Miller
2015-03-09 22:26         ` [PATCH 0/2] rhashtable: Arbitrary rehashing Herbert Xu
2015-03-09 22:27           ` [PATCH 1/2] rhashtable: Move hash_rnd into bucket_table Herbert Xu
2015-03-10 17:20             ` Thomas Graf
2015-03-10 21:48               ` Herbert Xu
2015-03-09 22:27           ` [PATCH 2/2] rhashtable: Add arbitrary rehash function Herbert Xu
2015-03-10 18:17             ` Thomas Graf [this message]
2015-03-10 22:01               ` Herbert Xu
2015-03-10 22:43             ` [PATCH v2] " Herbert Xu
2015-03-11 20:37               ` David Miller
2015-03-11 21:07                 ` Herbert Xu
2015-03-09 22:32           ` [PATCH 0/2] rhashtable: Arbitrary rehashing Josh Triplett
2015-03-10 18:20           ` Thomas Graf
2015-03-12 16:46           ` Thomas Graf
2015-03-13  1:54             ` Herbert Xu
2015-03-13  3:02               ` David Miller

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=20150310181720.GB13155@casper.infradead.org \
    --to=tgraf@suug.ch \
    --cc=davem@davemloft.net \
    --cc=herbert@gondor.apana.org.au \
    --cc=josh@joshtriplett.org \
    --cc=netdev@vger.kernel.org \
    --cc=paulmck@linux.vnet.ibm.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).