From: NeilBrown <neilb@suse.de>
To: Peter Zijlstra <peterz@infradead.org>
Cc: Thierry Reding <thierry.reding@gmail.com>,
Shaohua Li <shli@kernel.org>, Ingo Molnar <mingo@kernel.org>,
Thomas Gleixner <tglx@linutronix.de>,
"H. Peter Anvin" <hpa@zytor.com>,
linux-next@vger.kernel.org, linux-kernel@vger.kernel.org
Subject: Re: linux-next: manual merge of the tip tree
Date: Tue, 22 Oct 2013 13:09:53 +1100 [thread overview]
Message-ID: <20131022130953.29fc5ac3@notabene.brown> (raw)
In-Reply-To: <20131017092349.GL2675@laptop.programming.kicks-ass.net>
[-- Attachment #1: Type: text/plain, Size: 2972 bytes --]
On Thu, 17 Oct 2013 11:23:49 +0200 Peter Zijlstra <peterz@infradead.org>
wrote:
> On Thu, Oct 17, 2013 at 12:28:59PM +1100, NeilBrown wrote:
> > I always run with lockdep enabled, and I have done at least basic testing
>
> Very good!
>
> > >
> > > Stuff like:
> > >
> > > + for (i = 0; i < NR_STRIPE_HASH_LOCKS; i++)
> > > + spin_lock_init(conf->hash_locks + i);
> > >
> > > And:
> > >
> > > +static void __lock_all_hash_locks(struct r5conf *conf)
> > > +{
> > > + int i;
> > > + for (i = 0; i < NR_STRIPE_HASH_LOCKS; i++)
> > > + spin_lock(conf->hash_locks + i);
> > > +}
> > >
> > > Tends to complain real loud.
> >
> > Why is that?
> > Because "conf->hash_locks + i" gets used as the "name" of the lockdep map for
> > each one, and when they are all locked it looks like nested locking??
>
> Exactly so; they all share the same class (and name) because they have
> the same init site; so indeed the multiple lock will look like a nested
> lock.
>
> > Do you have a suggestion for how to make this work?
> > Would
> > spin_lock_nested(conf->hash_locks + i, i)
> > do the trick?
>
> spin_lock_nest_lock(conf->hash_locks + i, &conf->device_lock);
Unfortunately this doesn't work as the order is backwards.
hash_lock is taken first, then (when necessary) device lock.
(hash_lock is needed more often, so we split it up to reduce contention.
device lock is needed less often, but sometimes when hash_lock is held).
I've currently got:
spin_lock_init(conf->hash_locks);
for (i = 1; i < NR_STRIPE_HASH_LOCKS; i++)
spin_lock_init(conf->hash_locks + i);
and
spin_lock(conf->hash_locks);
for (i = 1; i < NR_STRIPE_HASH_LOCKS; i++)
spin_lock_nest_lock(conf->hash_locks + i, conf->hash_locks);
spin_lock(&conf->device_lock);
which doesn't trigger any lockdep warnings and isn't too ugly.
Does it seem OK to you?
Thanks,
NeilBrown
>
> Would be the better option; your suggestion might just work because
> NR_STRIP_HASH_LOCKS is 8 and we have exactly 8 subclasses available, but
> any increase to NR_STRIPE_HASH_LOCKS will make things explode again.
>
> The spin_lock_nest_lock() annotation tells that the lock order is
> irrelevant because all such multiple acquisitions are serialized under
> the other lock.
>
> Also, if in future you feel the need to increase NR_STRIP_HASH_LOCKS,
> please keep it <= 64 or so; if you have a need to go above that, please
> yell and we'll see if we can do something smarter.
I've added a comment to this effect in the code.
>
> This is because of:
> - each spin_lock() increases preempt_count and that's 8 bits; we
> wouldn't want to overflow that
> - each consecutive nested spin_lock() increases the total acquisition
> wait-time for all locks. Note that the worst case acquisition time
> for even a single hash lock is gated by the complete acquisition time
> of all of them in this scenario.
[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 828 bytes --]
next prev parent reply other threads:[~2013-10-22 2:09 UTC|newest]
Thread overview: 41+ messages / expand[flat|nested] mbox.gz Atom feed top
2013-10-16 18:51 linux-next: Tree for Oct 16 Thierry Reding
2013-10-16 18:51 ` linux-next: manual merge of the tip tree Thierry Reding
2013-10-16 20:06 ` Peter Zijlstra
2013-10-16 20:14 ` Peter Zijlstra
2013-10-16 20:31 ` NeilBrown
2013-10-16 20:35 ` Peter Zijlstra
2013-10-16 20:51 ` Thierry Reding
2013-10-16 21:00 ` Peter Zijlstra
2013-10-16 20:52 ` Peter Zijlstra
2013-10-17 1:28 ` NeilBrown
2013-10-17 9:23 ` Peter Zijlstra
2013-10-22 2:09 ` NeilBrown [this message]
2013-10-16 20:40 ` Thierry Reding
2013-10-16 20:44 ` Thierry Reding
2013-10-16 21:30 ` Peter Zijlstra
2013-10-17 1:29 ` NeilBrown
2013-10-16 18:51 ` linux-next: manual merge of the kvm-arm tree Thierry Reding
2013-10-16 18:58 ` Marc Zyngier
2013-10-16 19:02 ` Christoffer Dall
2013-10-16 19:04 ` Thierry Reding
2013-10-16 19:09 ` Christoffer Dall
2013-10-17 14:55 ` Gleb Natapov
2013-10-17 16:53 ` Christoffer Dall
2013-10-16 21:48 ` linux-next: Tree for Oct 16 (net/sched/em_ipset.c) Randy Dunlap
2013-10-16 22:39 ` Stephen Hemminger
2013-10-17 0:21 ` Randy Dunlap
2013-10-17 0:29 ` [PATCH net-next] em_ipset: use dev_net() accessor Stephen Hemminger
2013-10-18 20:23 ` David Miller
2013-10-17 0:58 ` linux-next: Tree for Oct 16 Randy Dunlap
2013-10-17 5:12 ` Guenter Roeck
-- strict thread matches above, loose matches on Subject: below --
2013-10-24 16:31 linux-next: Tree for Oct 24 Thierry Reding
2013-10-25 13:03 ` linux-next: manual merge of the c6x tree Thierry Reding
2013-10-25 13:03 ` linux-next: manual merge of the tip tree Thierry Reding
2013-10-25 13:25 ` Will Deacon
2013-10-26 8:40 ` Ingo Molnar
2013-10-26 14:01 ` Will Deacon
2013-10-27 7:12 ` Ingo Molnar
2013-10-27 10:00 ` Russell King - ARM Linux
2013-10-28 7:47 ` Thierry Reding
2013-10-28 8:45 ` Russell King - ARM Linux
2013-10-17 21:23 Mark Brown
2013-10-17 21:50 ` Cyrill Gorcunov
2013-09-30 11:26 linux-next: manual merge of the bcon tree Thierry Reding
2013-09-30 11:26 ` linux-next: manual merge of the tip tree Thierry Reding
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=20131022130953.29fc5ac3@notabene.brown \
--to=neilb@suse.de \
--cc=hpa@zytor.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-next@vger.kernel.org \
--cc=mingo@kernel.org \
--cc=peterz@infradead.org \
--cc=shli@kernel.org \
--cc=tglx@linutronix.de \
--cc=thierry.reding@gmail.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 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.