All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH RFC] libfs: Remove parent dentry locking in offset_iterate_dir()
@ 2023-07-25 18:31 Chuck Lever
  2023-07-28  8:06 ` Christian Brauner
  0 siblings, 1 reply; 2+ messages in thread
From: Chuck Lever @ 2023-07-25 18:31 UTC (permalink / raw)
  To: linux-fsdevel, linux-mm
  Cc: kernel test robot, Chuck Lever, oliver.sang, oe-lkp, ying.huang,
	feng.tang, fengwei.yin

From: Chuck Lever <chuck.lever@oracle.com>

Since offset_iterate_dir() does not walk the parent's d_subdir list
nor does it manipulate the parent's d_child, there doesn't seem to
be a reason to hold the parent's d_lock. The offset_ctx's xarray can
be sufficiently protected with just the RCU read lock.

Flame graph data captured during the git regression run shows a
20% reduction in CPU cycles consumed in offset_find_next().

Reported-by: kernel test robot <oliver.sang@intel.com>
Closes: https://lore.kernel.org/oe-lkp/202307171640.e299f8d5-oliver.sang@intel.com
Signed-off-by: Chuck Lever <chuck.lever@oracle.com>
---
 fs/libfs.c |    9 +++------
 1 file changed, 3 insertions(+), 6 deletions(-)

This is a possible fix for the will-it-scale regression recently
reported by the kernel test robot. It passes the git regression
test over NFS and doesn't seem to perturb xfstests.

I'm not able to run lkp here yet, so anyone who can run the
will-it-scale test, please report the results. Many thanks.


diff --git a/fs/libfs.c b/fs/libfs.c
index fcc0f1f3c2dc..b69c41fb3c63 100644
--- a/fs/libfs.c
+++ b/fs/libfs.c
@@ -406,7 +406,7 @@ static struct dentry *offset_find_next(struct xa_state *xas)
 	child = xas_next_entry(xas, U32_MAX);
 	if (!child)
 		goto out;
-	spin_lock_nested(&child->d_lock, DENTRY_D_LOCK_NESTED);
+	spin_lock(&child->d_lock);
 	if (simple_positive(child))
 		found = dget_dlock(child);
 	spin_unlock(&child->d_lock);
@@ -424,17 +424,14 @@ static bool offset_dir_emit(struct dir_context *ctx, struct dentry *dentry)
 			  inode->i_ino, fs_umode_to_dtype(inode->i_mode));
 }
 
-static void offset_iterate_dir(struct dentry *dir, struct dir_context *ctx)
+static void offset_iterate_dir(struct inode *inode, struct dir_context *ctx)
 {
-	struct inode *inode = d_inode(dir);
 	struct offset_ctx *so_ctx = inode->i_op->get_offset_ctx(inode);
 	XA_STATE(xas, &so_ctx->xa, ctx->pos);
 	struct dentry *dentry;
 
 	while (true) {
-		spin_lock(&dir->d_lock);
 		dentry = offset_find_next(&xas);
-		spin_unlock(&dir->d_lock);
 		if (!dentry)
 			break;
 
@@ -478,7 +475,7 @@ static int offset_readdir(struct file *file, struct dir_context *ctx)
 	if (!dir_emit_dots(file, ctx))
 		return 0;
 
-	offset_iterate_dir(dir, ctx);
+	offset_iterate_dir(d_inode(dir), ctx);
 	return 0;
 }
 



^ permalink raw reply related	[flat|nested] 2+ messages in thread

* Re: [PATCH RFC] libfs: Remove parent dentry locking in offset_iterate_dir()
  2023-07-25 18:31 [PATCH RFC] libfs: Remove parent dentry locking in offset_iterate_dir() Chuck Lever
@ 2023-07-28  8:06 ` Christian Brauner
  0 siblings, 0 replies; 2+ messages in thread
From: Christian Brauner @ 2023-07-28  8:06 UTC (permalink / raw)
  To: Chuck Lever, oliver.sang
  Cc: Christian Brauner, Chuck Lever, oe-lkp, ying.huang, feng.tang,
	fengwei.yin, linux-fsdevel, linux-mm

On Tue, 25 Jul 2023 14:31:04 -0400, Chuck Lever wrote:
> Since offset_iterate_dir() does not walk the parent's d_subdir list
> nor does it manipulate the parent's d_child, there doesn't seem to
> be a reason to hold the parent's d_lock. The offset_ctx's xarray can
> be sufficiently protected with just the RCU read lock.
> 
> Flame graph data captured during the git regression run shows a
> 20% reduction in CPU cycles consumed in offset_find_next().
> 
> [...]

I've picked this up. It would be very nice if we could get a perf test
from lkp for this fix.

---

Applied to the vfs.tmpfs branch of the vfs/vfs.git tree.
Patches in the vfs.tmpfs branch should appear in linux-next soon.

Please report any outstanding bugs that were missed during review in a
new review to the original patch series allowing us to drop it.

It's encouraged to provide Acked-bys and Reviewed-bys even though the
patch has now been applied. If possible patch trailers will be updated.

Note that commit hashes shown below are subject to change due to rebase,
trailer updates or similar. If in doubt, please check the listed branch.

tree:   https://git.kernel.org/pub/scm/linux/kernel/git/vfs/vfs.git
branch: vfs.tmpfs

[1/1] libfs: Remove parent dentry locking in offset_iterate_dir()
      https://git.kernel.org/vfs/vfs/c/01c45fd0472c

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2023-07-28  8:07 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-07-25 18:31 [PATCH RFC] libfs: Remove parent dentry locking in offset_iterate_dir() Chuck Lever
2023-07-28  8:06 ` Christian Brauner

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.