All of lore.kernel.org
 help / color / mirror / Atom feed
From: Linus Torvalds <torvalds@linux-foundation.org>
To: torvalds@linux-foundation.org
Cc: brauner@kernel.org, jack@suse.cz, laoar.shao@gmail.com,
	linux-fsdevel@vger.kernel.org, longman@redhat.com,
	viro@zeniv.linux.org.uk, walters@verbum.org,
	wangkai86@huawei.com, willy@infradead.org
Subject: [PATCH] vfs: move dentry shrinking outside the inode lock in 'rmdir()'
Date: Sat, 11 May 2024 11:26:26 -0700	[thread overview]
Message-ID: <20240511182625.6717-2-torvalds@linux-foundation.org> (raw)
In-Reply-To: <CAHk-=whvo+r-VZH7Myr9fid=zspMo2-0BUJw5S=VTm72iEXXvQ@mail.gmail.com>

Yafang Shao reports that he has seen loads that generate billions of
negative dentries in a directory, which then when the directory is
removed causes excessive latencies for other users because the dentry
shrinking is done under the directory inode lock.

There seems to be no actual reason for holding the inode lock any more
by the time we get rid of the now uninteresting negative dentries, and
it's an effect of just code layout (the shared error path).

Reorganize the code trivially to just have a separate success path,
which simplifies the code (since 'd_delete_notify()' is only called in
the success path anyway) and makes it trivial to just move the dentry
shrinking outside the inode lock.

Reported-by: Yafang Shao <laoar.shao@gmail.com>
Link: https://lore.kernel.org/all/20240511022729.35144-1-laoar.shao@gmail.com/
Cc: Al Viro <viro@zeniv.linux.org.uk>
Cc: Christian Brauner <brauner@kernel.org>
Cc: Jan Kara <jack@suse.cz>
Cc: Waiman Long <longman@redhat.com>
Cc: Matthew Wilcox <willy@infradead.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
---

Ok, this is the same patch, just with a commit message.  And I actually
am running a kernel with that patch, so it compiles and boots.

Very limited testing: I created a directory with ten million negative
dentries, and then did a "rmdir" in one terminal window while doing a
"ls" inside that directory in another to kind of reproduce (on a smaller
scale) what Yafang was reporting. 

The "ls" was not affected at all.  But honestly, this was *ONE* single
trivial test, so it's almost completely worthless. 

 fs/namei.c | 9 ++++++---
 1 file changed, 6 insertions(+), 3 deletions(-)

diff --git a/fs/namei.c b/fs/namei.c
index 28e62238346e..474b1ee3266d 100644
--- a/fs/namei.c
+++ b/fs/namei.c
@@ -4217,16 +4217,19 @@ int vfs_rmdir(struct mnt_idmap *idmap, struct inode *dir,
 	if (error)
 		goto out;
 
-	shrink_dcache_parent(dentry);
 	dentry->d_inode->i_flags |= S_DEAD;
 	dont_mount(dentry);
 	detach_mounts(dentry);
+	inode_unlock(dentry->d_inode);
+
+	shrink_dcache_parent(dentry);
+	dput(dentry);
+	d_delete_notify(dir, dentry);
+	return 0;
 
 out:
 	inode_unlock(dentry->d_inode);
 	dput(dentry);
-	if (!error)
-		d_delete_notify(dir, dentry);
 	return error;
 }
 EXPORT_SYMBOL(vfs_rmdir);
-- 
2.44.0.330.g4d18c88175


  reply	other threads:[~2024-05-11 18:28 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               ` Linus Torvalds [this message]
2024-05-11 18:42                 ` [PATCH] vfs: move dentry shrinking outside the inode lock in 'rmdir()' 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     ` [RFC PATCH] fs: dcache: Delete the associated dentry when deleting a file Yafang Shao
2024-05-15  2:36       ` 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=20240511182625.6717-2-torvalds@linux-foundation.org \
    --to=torvalds@linux-foundation.org \
    --cc=brauner@kernel.org \
    --cc=jack@suse.cz \
    --cc=laoar.shao@gmail.com \
    --cc=linux-fsdevel@vger.kernel.org \
    --cc=longman@redhat.com \
    --cc=viro@zeniv.linux.org.uk \
    --cc=walters@verbum.org \
    --cc=wangkai86@huawei.com \
    --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 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.