linux-fsdevel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: "Tobin C. Harding" <me@tobin.cc>
To: Matthew Wilcox <willy@infradead.org>
Cc: linux-fsdevel@vger.kernel.org
Subject: Re: dcache locking question
Date: Fri, 15 Mar 2019 12:38:05 +1100	[thread overview]
Message-ID: <20190315013805.GA23541@eros.localdomain> (raw)
In-Reply-To: <20190314230904.GO19508@bombadil.infradead.org>

On Thu, Mar 14, 2019 at 04:09:05PM -0700, Matthew Wilcox wrote:
> On Fri, Mar 15, 2019 at 09:56:32AM +1100, Tobin C. Harding wrote:
> > Could someone please explain to me how the locking order commented at
> > the top of the file is not violated in the following:
> > 
> > >From top of fs/dcache.c
> > 
> >  * If there is an ancestor relationship:
> >  * dentry->d_parent->...->d_parent->d_lock
> >  *   ...
> >  *     dentry->d_parent->d_lock
> >  *       dentry->d_lock
> > 
> > 
> > dentry_kill() appears to require caller to hold the dentry->d_lock yet
> > it locks the parent with spin_trylock(&parent->d_lock), if this
> > fails it calls __lock_parent() which releases the dentry->d_lock before
> > locking the parent and re-acquiring [1] the dentry->d_lock .  Is this not
> > locking in two different orders? 
> 
> What you're describing here is how we work around having to lock in the
> wrong order.  There are "a few" places in the kernel where we do this.
> Calling spin_trylock() won't deadlock -- it'll just return failure.
> At that point, we drop the child, spin waiting for the parent, then lock
> the child.
> 
> > [1] I do not fully understand the spin_lock_nested() macro.
> 
> It describes to lockdep that, while it looks like we're acquiring a lock
> that we already own, there's actually a hierarchy of locks that are in
> the same lock class; we're attempting to acquire a lock in "subclass N".
> N is allowed to be between 0-7, inclusive.

ok, cool.  Thanks for taking the time to explain this.

	Tobin
	

  reply	other threads:[~2019-03-15  1:38 UTC|newest]

Thread overview: 17+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-03-14 22:56 dcache locking question Tobin C. Harding
2019-03-14 23:09 ` Matthew Wilcox
2019-03-15  1:38   ` Tobin C. Harding [this message]
2019-03-14 23:19 ` Tobin C. Harding
2019-03-15  1:50   ` Al Viro
2019-03-15 17:38     ` Eric Biggers
2019-03-15 18:54       ` Al Viro
2019-03-16 22:31         ` Paul E. McKenney
2019-03-17  0:18           ` Al Viro
2019-03-17  0:50             ` Paul E. McKenney
2019-03-17  2:20               ` James Bottomley
2019-03-17  3:06                 ` Al Viro
2019-03-17  4:23                   ` James Bottomley
2019-03-18  0:35                     ` Paul E. McKenney
2019-03-18 16:26                       ` James Bottomley
2019-03-18 17:11                         ` Paul E. McKenney
2019-03-19 15:45                           ` Paul E. McKenney

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=20190315013805.GA23541@eros.localdomain \
    --to=me@tobin.cc \
    --cc=linux-fsdevel@vger.kernel.org \
    --cc=willy@infradead.org \
    /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).