From: John Ogness <john.ogness@linutronix.de>
To: Al Viro <viro@ZenIV.linux.org.uk>
Cc: linux-fsdevel@vger.kernel.org,
Linus Torvalds <torvalds@linux-foundation.org>,
Christoph Hellwig <hch@lst.de>,
Thomas Gleixner <tglx@linutronix.de>,
Peter Zijlstra <peterz@infradead.org>,
Sebastian Andrzej Siewior <bigeasy@linutronix.de>,
linux-kernel@vger.kernel.org
Subject: Re: [PATCH 3/4] fs/dcache: Avoid the try_lock loop in d_delete()
Date: Thu, 22 Feb 2018 09:35:42 +0100 [thread overview]
Message-ID: <87bmgh4e1t.fsf@linutronix.de> (raw)
In-Reply-To: <20180222051857.GL30522@ZenIV.linux.org.uk> (Al Viro's message of "Thu, 22 Feb 2018 05:18:57 +0000")
On 2018-02-22, Al Viro <viro@ZenIV.linux.org.uk> wrote:
>> @@ -2378,22 +2420,36 @@ void d_delete(struct dentry * dentry)
>> /*
>> * Are we the only user?
>> */
>> -again:
>> spin_lock(&dentry->d_lock);
>> +again:
>> inode = dentry->d_inode;
>> isdir = S_ISDIR(inode->i_mode);
>> if (dentry->d_lockref.count == 1) {
>> - if (!spin_trylock(&inode->i_lock)) {
>> - spin_unlock(&dentry->d_lock);
>> - cpu_relax();
>> + /*
>> + * Lock the inode. Might drop dentry->d_lock temporarily
>> + * which allows inode to change. Start over if that happens.
>> + */
>> + if (!dentry_lock_inode(dentry))
>> goto again;
>
> IDGI. First of all, why do we need to fetch ->d_inode (and calculate
> isdir) before that dentry_lock_inode() of yours? That's at least
> partially understandable in the current version, where we need inode
> in d_delete() scope, but here it looks bloody odd.
I tried to change the function as little as possible. You are right that
it now looks odd. I seem to have missed the forest for the trees.
> And if you move those fetches past the call of dentry_lock_inode(),
> you suddenly get the life much simpler:
>
> grab d_lock
> if d_count is greater than 1, drop it and bugger off
> while !dentry_lock_inode(dentry)
> ;
> fetch inode
> recheck d_count, in the unlikely case when it's greater than 1,
> drop and bugger off
> clear CANT_MOUNT
> calculate isdir
> unlink_inode
> fsnotify shite
>
> I mean, do we really want to keep rechecking d_count on each loop
> iteration? What does it buy us? Sure, we want to recheck in the end
> for correctness sake, but...
I have been unable to produce a test case where dentry_lock_inode() can
fail. AFAICT it is not possible from userspace. Perhaps some filesystem
could trigger it. But if it would fail, getting the refcount to increase
in the dropped d_lock window is quite easy to reproduce. And in that
case we wouldn't need to keep trying to aquire the inode lock and could
just drop.
> It might make sense to move the loop inside dentry_lock_inode(), IMO.
Agreed. I will change dentry_lock_inode() so that it will only fail if
the refcount changes. If there are inode changes, it will loop
internally. That will change your suggestion to:
grab d_lock
if d_count is greater than 1
drop it and bugger off
if !dentry_lock_inode(dentry)
drop it and bugger off
fetch inode
clear CANT_MOUNT
calculate isdir
unlink_inode
fsnotify shite
John Ogness
next prev parent reply other threads:[~2018-02-22 8:35 UTC|newest]
Thread overview: 22+ messages / expand[flat|nested] mbox.gz Atom feed top
2018-02-16 15:09 [PATCH 0/4] fs/dcache: avoid trylock loops John Ogness
2018-02-16 15:09 ` [PATCH 1/4] fs/dcache: Remove stale comment from dentry_kill() John Ogness
2018-02-16 15:09 ` [PATCH 2/4] fs/dcache: Move dentry_kill() below lock_parent() John Ogness
2018-02-16 15:09 ` [PATCH 3/4] fs/dcache: Avoid the try_lock loop in d_delete() John Ogness
2018-02-16 17:10 ` Peter Zijlstra
2018-02-16 17:30 ` Peter Zijlstra
2018-02-22 5:18 ` Al Viro
2018-02-22 8:35 ` John Ogness [this message]
2018-02-16 15:09 ` [PATCH 4/4] fs/dcache: Avoid the try_lock loops in dentry_kill() John Ogness
2018-02-16 18:03 ` Linus Torvalds
2018-02-16 22:32 ` John Ogness
2018-02-16 22:42 ` Linus Torvalds
2018-02-16 23:05 ` John Ogness
2018-02-16 23:31 ` Linus Torvalds
2018-02-16 23:49 ` John Ogness
2018-02-17 0:06 ` Linus Torvalds
2018-02-19 23:34 ` John Ogness
2018-02-20 0:42 ` Linus Torvalds
2018-02-20 8:39 ` Peter Zijlstra
2018-02-20 8:43 ` Peter Zijlstra
2018-02-22 5:29 ` Al Viro
2018-02-22 5:40 ` Al Viro
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=87bmgh4e1t.fsf@linutronix.de \
--to=john.ogness@linutronix.de \
--cc=bigeasy@linutronix.de \
--cc=hch@lst.de \
--cc=linux-fsdevel@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=peterz@infradead.org \
--cc=tglx@linutronix.de \
--cc=torvalds@linux-foundation.org \
--cc=viro@ZenIV.linux.org.uk \
/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