From: NeilBrown <neilb@suse.com>
To: David Laight <David.Laight@ACULAB.COM>,
Thomas Graf <tgraf@suug.ch>,
Herbert Xu <herbert@gondor.apana.org.au>
Cc: "netdev\@vger.kernel.org" <netdev@vger.kernel.org>,
"linux-kernel\@vger.kernel.org" <linux-kernel@vger.kernel.org>
Subject: RE: [PATCH 3/4] rhashtable: use bit_spin_locks to protect hash bucket.
Date: Thu, 04 Apr 2019 11:13:04 +1100 [thread overview]
Message-ID: <87v9zuzkz3.fsf@notabene.neil.brown.name> (raw)
In-Reply-To: <039555b9db9a410c88c7389708d157f1@AcuMS.aculab.com>
[-- Attachment #1: Type: text/plain, Size: 2457 bytes --]
On Wed, Apr 03 2019, David Laight wrote:
> From: NeilBrown
>> Sent: 02 April 2019 22:11
>>
>> On Tue, Apr 02 2019, David Laight wrote:
>>
>> > From: NeilBrown
>> >> Sent: 02 April 2019 00:08
>> >>
>> >> This patch changes rhashtables to use a bit_spin_lock on BIT(1) of the
>> >> bucket pointer to lock the hash chain for that bucket.
>> > ...
>> >> To enhance type checking, a new struct is introduced to represent the
>> >> pointer plus lock-bit
>> >> that is stored in the bucket-table. This is "struct rhash_lock_head"
>> >> and is empty. A pointer to this needs to be cast to either an
>> >> unsigned lock, or a "struct rhash_head *" to be useful.
>> >> Variables of this type are most often called "bkt".
>> >
>> > Did you try using a union of the pointer and an 'unsigned long' ?
>> > Should remove a lot of the casts.
>>
>> It might, but I'm not sure it is what we want.
>> The value is not an unsigned long OR a pointer, it is both blended
>> together. So it really isn't a union.
>> We *want* it to require casts to access, so that it is clear that
>> something unusual is happening, and care is needed.
>
> Right, but you also want to make it hard to forget to do it properly.
> Using a union to access the memory as either a pointer or a long
> is perfectly valid (and is valid with 'strict aliasing' enabled).
> (Rather than the other use of a union to just save space.)
Agreed.... I personally think that a union make it easy to forget.
>
> An interesting thought....
> Are the only valid actions 'lock and read, and 'unlock with optional update' ?
No, there is also "read without locking" - use for lookups with RCU
protection. But yes: the set of valid actions is quite limited.
> If so there are only 2 bits of code that need to understand the encoding.
> If you make the bit number(s) and polarity properties of the architecture
> you should be able to make the stored value an invalid pointer (locked
> and unlocked) on at least some architectures.
I'd rather avoid writing arch-specific code if I can avoid it. It isn't
clear that the value of your proposal justifies the cost.
Over-loading the low-order bits of a pointer is (I think) a well
understood pattern. I'd rather stick with such patterns.
Thanks,
NeilBrown
>
> David
>
> -
> Registered Address Lakeside, Bramley Road, Mount Farm, Milton Keynes, MK1 1PT, UK
> Registration No: 1397386 (Wales)
[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 832 bytes --]
next prev parent reply other threads:[~2019-04-04 0:13 UTC|newest]
Thread overview: 28+ messages / expand[flat|nested] mbox.gz Atom feed top
2019-04-01 23:07 [PATCH 0/4 v2] Convert rhashtable to use bitlocks NeilBrown
2019-04-01 23:07 ` [PATCH 4/4] rhashtable: add lockdep tracking to bucket bit-spin-locks NeilBrown
2019-04-01 23:07 ` [PATCH 3/4] rhashtable: use bit_spin_locks to protect hash bucket NeilBrown
2019-04-02 10:11 ` David Laight
2019-04-02 21:10 ` NeilBrown
2019-04-03 9:26 ` David Laight
2019-04-04 0:13 ` NeilBrown [this message]
2019-04-08 2:34 ` Herbert Xu
2019-04-10 19:34 ` Guenter Roeck
2019-04-11 0:48 ` NeilBrown
2019-04-11 2:15 ` David Miller
2019-04-11 6:13 ` NeilBrown
2019-04-11 6:40 ` NeilBrown
2019-04-11 12:44 ` Guenter Roeck
2019-04-01 23:07 ` [PATCH 1/4] rhashtable: use cmpxchg() in nested_table_alloc() NeilBrown
2019-04-08 2:34 ` Herbert Xu
2019-04-01 23:07 ` [PATCH 2/4] rhashtable: allow rht_bucket_var to return NULL NeilBrown
2019-04-08 2:12 ` [PATCH 0/4 v2] Convert rhashtable to use bitlocks David Miller
2019-04-08 2:35 ` Herbert Xu
-- strict thread matches above, loose matches on Subject: below --
2019-03-25 5:05 [PATCH 0/4] " NeilBrown
2019-03-25 5:05 ` [PATCH 3/4] rhashtable: use bit_spin_locks to protect hash bucket NeilBrown
2019-03-26 5:03 ` Herbert Xu
2019-03-26 15:36 ` Paul E. McKenney
2019-03-27 3:45 ` Herbert Xu
2019-03-26 22:35 ` NeilBrown
2019-03-27 3:45 ` Herbert Xu
2019-03-27 15:04 ` Paul E. McKenney
2019-03-26 5:27 ` Herbert Xu
2019-03-26 22:40 ` NeilBrown
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=87v9zuzkz3.fsf@notabene.neil.brown.name \
--to=neilb@suse.com \
--cc=David.Laight@ACULAB.COM \
--cc=herbert@gondor.apana.org.au \
--cc=linux-kernel@vger.kernel.org \
--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 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).