From: Yafang Shao <laoar.shao@gmail.com>
To: Linus Torvalds <torvalds@linux-foundation.org>
Cc: viro@zeniv.linux.org.uk, brauner@kernel.org, jack@suse.cz,
linux-fsdevel@vger.kernel.org, Wangkai <wangkai86@huawei.com>,
Colin Walters <walters@verbum.org>,
Waiman Long <longman@redhat.com>
Subject: Re: [RFC PATCH] fs: dcache: Delete the associated dentry when deleting a file
Date: Wed, 15 May 2024 10:18:47 +0800 [thread overview]
Message-ID: <CALOAHbCgMvZR-YCJEpEHDCZVwvgASAenoCOOTTX76B_z-jasfw@mail.gmail.com> (raw)
In-Reply-To: <CALOAHbCECWqpFzreANpvQJADicRr=AbP-nAymSEeUzUr3vGZMg@mail.gmail.com>
On Sat, May 11, 2024 at 11:35 AM Yafang Shao <laoar.shao@gmail.com> wrote:
>
> On Sat, May 11, 2024 at 10:54 AM Linus Torvalds
> <torvalds@linux-foundation.org> wrote:
> >
> > On Fri, 10 May 2024 at 19:28, Yafang Shao <laoar.shao@gmail.com> wrote:
> > >
> > > We've devised a solution to address both issues by deleting associated
> > > dentry when removing a file.
> >
> > This patch is buggy. You are modifying d_flags outside the locked region.
> >
> > So at a minimum, the DCACHE_FILE_DELETED bit setting would need to
> > just go into the
> >
> > if (dentry->d_lockref.count == 1) {
> >
> > side of the conditional, since the other side of that conditional
> > already unhashes the dentry which makes this all moot anyway.
> >
> > That said, I think it's buggy in another way too: what if somebody
> > else looks up the dentry before it actually gets unhashed? Then you
> > have another ref to it, and the dentry might live long enough that it
> > then gets re-used for a newly created file (which is why we have those
> > negative dentries in the first place).
> >
> > So you'd have to clear the DCACHE_FILE_DELETED if the dentry is then
> > made live by a file creation or rename or whatever.
> >
> > So that d_flags thing is actually pretty complicated.
> >
> > But since you made all this unconditional anyway, I think having a new
> > dentry flag is unnecessary in the first place, and I suspect you are
> > better off just unhashing the dentry unconditionally instead.
> >
> > IOW, I think the simpler patch is likely just something like this:
>
> It's simpler. I used to contemplate handling it that way, but lack the
> knowledge and courage to proceed, hence I opted for the d_flags
> solution.
> I'll conduct tests on the revised change. Appreciate your suggestion.
>
We have successfully applied a hotfix to a subset of our production
servers, totaling several thousand. The hotfix is as follows:
diff --git a/fs/dcache.c b/fs/dcache.c
index 52e6d5f..30eb733 100644
--- a/fs/dcache.c
+++ b/fs/dcache.c
@@ -2557,14 +2557,14 @@ void d_delete(struct dentry * dentry)
spin_lock(&inode->i_lock);
spin_lock(&dentry->d_lock);
+ __d_drop(dentry);
+
/*
* Are we the only user?
*/
if (dentry->d_lockref.count == 1) {
- dentry->d_flags &= ~DCACHE_CANT_MOUNT;
dentry_unlink_inode(dentry);
} else {
- __d_drop(dentry);
spin_unlock(&dentry->d_lock);
spin_unlock(&inode->i_lock);
}
So far, it has been functioning well without any regressions. We are
planning to roll this update out to our entire fleet, which consists
of hundreds of thousands of servers.
I believe this change is still necessary. Would you prefer to commit
it directly, or should I send an official patch?
If the "unlink-create" issue is a concern, perhaps we can address it
by adding a /sys/kernel/debug/vfs/delete_file_legacy entry?
> >
> > --- a/fs/dcache.c
> > +++ b/fs/dcache.c
> > @@ -2381,6 +2381,7 @@ void d_delete(struct dentry * dentry)
> >
> > spin_lock(&inode->i_lock);
> > spin_lock(&dentry->d_lock);
> > + __d_drop(dentry);
> > /*
> > * Are we the only user?
> > */
> > @@ -2388,7 +2389,6 @@ void d_delete(struct dentry * dentry)
> > dentry->d_flags &= ~DCACHE_CANT_MOUNT;
> > dentry_unlink_inode(dentry);
> > } else {
> > - __d_drop(dentry);
> > spin_unlock(&dentry->d_lock);
> > spin_unlock(&inode->i_lock);
> > }
> >
> > although I think Al needs to ACK this, and I suspect that unhashing
> > the dentry also makes that
> >
> > dentry->d_flags &= ~DCACHE_CANT_MOUNT;
> >
> > pointless (because the dentry won't be reused, so DCACHE_CANT_MOUNT
> > just won't matter).
> >
> > I do worry that there are loads that actually love our current
> > behavior, but maybe it's worth doing the simple unconditional "make
> > d_delete() always unhash" and only worry about whether that causes
> > performance problems for people who commonly create a new file in its
> > place when we get such a report.
> >
> > IOW, the more complex thing might be to actually take other behavior
> > into account (eg "do we have so many negative dentries that we really
> > don't want to create new ones").
>
> This poses a substantial challenge. Despite recurrent discussions
> within the community about improving negative dentry over and over,
> there hasn't been a consensus on how to address it.
>
> >
> > Al - can you please step in and tell us what else I've missed, and why
> > my suggested version of the patch is also broken garbage?
> >
> > Linus
>
>
> --
> Regards
> Yafang
--
Regards
Yafang
next prev parent reply other threads:[~2024-05-15 2:19 UTC|newest]
Thread overview: 43+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-05-11 2:27 [RFC PATCH] fs: dcache: Delete the associated dentry when deleting a file Yafang Shao
2024-05-11 2:53 ` Linus Torvalds
2024-05-11 3:35 ` Yafang Shao
2024-05-11 4:54 ` Waiman Long
2024-05-11 15:58 ` Matthew Wilcox
2024-05-11 16:07 ` Linus Torvalds
2024-05-11 16:13 ` Linus Torvalds
2024-05-11 18:05 ` Linus Torvalds
2024-05-11 18:26 ` [PATCH] vfs: move dentry shrinking outside the inode lock in 'rmdir()' Linus Torvalds
2024-05-11 18:42 ` Linus Torvalds
2024-05-11 19:28 ` Al Viro
2024-05-11 19:55 ` Linus Torvalds
2024-05-11 20:31 ` Al Viro
2024-05-11 21:17 ` Al Viro
2024-05-12 15:45 ` James Bottomley
2024-05-12 16:16 ` Al Viro
2024-05-12 19:59 ` Linus Torvalds
2024-05-12 20:29 ` Linus Torvalds
2024-05-13 5:31 ` Al Viro
2024-05-13 15:58 ` Linus Torvalds
2024-05-13 16:33 ` Al Viro
2024-05-13 16:44 ` Linus Torvalds
2024-05-23 7:18 ` Dave Chinner
2024-05-11 20:02 ` [PATCH v2] " Linus Torvalds
2024-05-12 3:06 ` Yafang Shao
2024-05-12 3:30 ` Al Viro
2024-05-12 3:36 ` Yafang Shao
2024-05-11 19:24 ` [PATCH] " Al Viro
2024-05-15 2:18 ` Yafang Shao [this message]
2024-05-15 2:36 ` [RFC PATCH] fs: dcache: Delete the associated dentry when deleting a file Linus Torvalds
2024-05-15 9:17 ` [PATCH] vfs: " Yafang Shao
2024-05-15 16:05 ` Linus Torvalds
2024-05-16 13:44 ` Oliver Sang
2024-05-22 8:51 ` Oliver Sang
2024-05-23 2:21 ` Yafang Shao
2024-05-22 8:11 ` kernel test robot
2024-05-22 16:00 ` Linus Torvalds
2024-05-22 17:13 ` Matthew Wilcox
2024-05-22 18:11 ` Linus Torvalds
2024-05-11 3:36 ` [RFC PATCH] fs: dcache: " Al Viro
2024-05-11 3:51 ` Yafang Shao
2024-05-11 5:18 ` Al Viro
2024-05-11 5:32 ` Linus Torvalds
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=CALOAHbCgMvZR-YCJEpEHDCZVwvgASAenoCOOTTX76B_z-jasfw@mail.gmail.com \
--to=laoar.shao@gmail.com \
--cc=brauner@kernel.org \
--cc=jack@suse.cz \
--cc=linux-fsdevel@vger.kernel.org \
--cc=longman@redhat.com \
--cc=torvalds@linux-foundation.org \
--cc=viro@zeniv.linux.org.uk \
--cc=walters@verbum.org \
--cc=wangkai86@huawei.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 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).