All of lore.kernel.org
 help / color / mirror / Atom feed
From: Herbert Xu <herbert@gondor.apana.org.au>
To: NeilBrown <neilb@suse.com>
Cc: Thomas Graf <tgraf@suug.ch>,
	netdev@vger.kernel.org, linux-kernel@vger.kernel.org
Subject: Re: [PATCH 6/8] rhashtable: further improve stability of rhashtable_walk
Date: Sat, 5 May 2018 17:42:12 +0800	[thread overview]
Message-ID: <20180505094212.hpqjyv5ijibviuwh@gondor.apana.org.au> (raw)
In-Reply-To: <152540605438.18473.4797800779538116583.stgit@noble>

On Fri, May 04, 2018 at 01:54:14PM +1000, NeilBrown wrote:
> If the sequence:
>    obj = rhashtable_walk_next(iter);
>    rhashtable_walk_stop(iter);
>    rhashtable_remove_fast(ht, &obj->head, params);
>    rhashtable_walk_start(iter);
> 
>  races with another thread inserting or removing
>  an object on the same hash chain, a subsequent
>  rhashtable_walk_next() is not guaranteed to get the "next"
>  object. It is possible that an object could be
>  repeated, or missed.
> 
>  This can be made more reliable by keeping the objects in a hash chain
>  sorted by memory address.  A subsequent rhashtable_walk_next()
>  call can reliably find the correct position in the list, and thus
>  find the 'next' object.
> 
>  It is not possible (certainly not so easy) to achieve this with an
>  rhltable as keeping the hash chain in order is not so easy.  When the
>  first object with a given key is removed, it is replaced in the chain
>  with the next object with the same key, and the address of that
>  object may not be correctly ordered.
>  No current user of rhltable_walk_enter() calls
>  rhashtable_walk_start() more than once, so no current code
>  could benefit from a more reliable walk of rhltables.
> 
>  This patch only attempts to improve walks for rhashtables.
>  - a new object is always inserted after the last object with a
>    smaller address, or at the start
>  - when rhashtable_walk_start() is called, it records that 'p' is not
>    'safe', meaning that it cannot be dereferenced.  The revalidation
>    that was previously done here is moved to rhashtable_walk_next()
>  - when rhashtable_walk_next() is called while p is not NULL and not
>    safe, it walks the chain looking for the first object with an
>    address greater than p and returns that.  If there is none, it moves
>    to the next hash chain.
> 
> Signed-off-by: NeilBrown <neilb@suse.com>

I'm a bit torn on this.  On the hand this is definitely an improvement
over the status quo.  On the other this does not work on rhltable and
we do have a way of fixing it for both rhashtable and rhltable.

Cheers,
-- 
Email: Herbert Xu <herbert@gondor.apana.org.au>
Home Page: http://gondor.apana.org.au/~herbert/
PGP Key: http://gondor.apana.org.au/~herbert/pubkey.txt

  reply	other threads:[~2018-05-05  9:42 UTC|newest]

Thread overview: 36+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-05-04  3:54 [PATCH 0/8] Assorted rhashtable fixes and cleanups NeilBrown
2018-05-04  3:54 ` [PATCH 8/8] rhashtable: don't hold lock on first table throughout insertion NeilBrown
2018-05-05  9:41   ` Herbert Xu
2018-05-05 22:00     ` NeilBrown
2018-05-06  5:20       ` Herbert Xu
2018-05-06 22:24         ` NeilBrown
2018-05-07  9:29           ` Herbert Xu
2018-05-08  0:23             ` NeilBrown
2018-05-04  3:54 ` [PATCH 6/8] rhashtable: further improve stability of rhashtable_walk NeilBrown
2018-05-05  9:42   ` Herbert Xu [this message]
2018-05-05 21:50     ` NeilBrown
2018-05-07  9:30       ` Herbert Xu
2018-05-08  0:54         ` NeilBrown
2018-05-04  3:54 ` [PATCH 1/8] rhashtable: silence RCU warning in rhashtable_test NeilBrown
2018-05-05  9:10   ` Herbert Xu
2018-05-05 21:49     ` NeilBrown
2018-05-04  3:54 ` [PATCH 2/8] rhashtable: remove nulls_base and related code NeilBrown
2018-05-05  9:12   ` Herbert Xu
2018-05-05 21:37     ` NeilBrown
2018-05-07  9:27       ` Herbert Xu
2018-05-08  1:14         ` NeilBrown
2018-05-04  3:54 ` [PATCH 5/8] rhashtable: remove rhashtable_walk_peek() NeilBrown
2018-05-05  9:30   ` Herbert Xu
2018-05-04  3:54 ` [PATCH 7/8] rhashtable: add rhashtable_walk_prev() NeilBrown
2018-05-05  9:43   ` Herbert Xu
2018-05-05 15:40     ` Tom Herbert
2018-05-06 22:16       ` NeilBrown
2018-05-04  3:54 ` [PATCH 4/8] rhashtable: fix race in nested_table_alloc() NeilBrown
2018-05-05  9:29   ` Herbert Xu
2018-05-05 21:48     ` NeilBrown
2018-05-06  5:18       ` Herbert Xu
2018-05-06 22:02         ` NeilBrown
2018-05-04  3:54 ` [PATCH 3/8] rhashtable: use cmpxchg() to protect ->future_tbl NeilBrown
2018-05-05  9:27   ` Herbert Xu
2018-05-05 21:45     ` NeilBrown
2018-05-04 17:07 ` [PATCH 0/8] Assorted rhashtable fixes and cleanups 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=20180505094212.hpqjyv5ijibviuwh@gondor.apana.org.au \
    --to=herbert@gondor.apana.org.au \
    --cc=linux-kernel@vger.kernel.org \
    --cc=neilb@suse.com \
    --cc=netdev@vger.kernel.org \
    --cc=tgraf@suug.ch \
    /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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.