mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Max Kellermann <max.kellermann@ionos.com>
To: idryomov@gmail.com, amarkuze@redhat.com, xiubo.li@clyso.com,
	ceph-devel@vger.kernel.org, linux-kernel@vger.kernel.org
Cc: Max Kellermann <max.kellermann@ionos.com>
Subject: [PATCH] ceph: skip alias lookup when trimming non-directory caps
Date: Mon,  7 Sep 2026 23:23:25 +0200	[thread overview]
Message-ID: <20260907212325.508739-1-max.kellermann@ionos.com> (raw)

drop_negative_children() only does anything for directories; for
other inodes it returns true unconditionally.  The d_find_any_alias()
and dput() pair around it is therefore pure overhead for regular
files: an extra `i_lock`, a dget()/dput(), and a ceph_d_delete()
check for zero-refcount dentries.

Only look up aliases for directories and prune other inodes
directly.  d_prune_aliases() kills the same dentries either way.

Side effect: a non-directory inode without any alias now counts as
trimmed if the iterator holds the last reference.  That is okay,
since with inode_just_drop it is evicted as soon as that reference
goes away.

Signed-off-by: Max Kellermann <max.kellermann@ionos.com>
---
 fs/ceph/mds_client.c | 30 ++++++++++++++++++------------
 1 file changed, 18 insertions(+), 12 deletions(-)

diff --git a/fs/ceph/mds_client.c b/fs/ceph/mds_client.c
index 085ae0cfb5f7..81cb1e9b9769 100644
--- a/fs/ceph/mds_client.c
+++ b/fs/ceph/mds_client.c
@@ -2315,22 +2315,28 @@ static int trim_caps_cb(struct inode *inode, int mds, void *arg)
 		ceph_remove_cap(mdsc, cap, ci, true);
 		(*remaining)--;
 	} else {
-		struct dentry *dentry;
+		int count;
+
 		/* try dropping referring dentries */
 		spin_unlock(&ci->i_ceph_lock);
-		dentry = d_find_any_alias(inode);
-		if (dentry && drop_negative_children(dentry)) {
-			int count;
-			dput(dentry);
-			d_prune_aliases(inode);
-			count = icount_read_once(inode);
-			if (count == 1)
-				(*remaining)--;
-			doutc(cl, "%p %llx.%llx cap %p pruned, count now %d\n",
-			      inode, ceph_vinop(inode), cap, count);
-		} else {
+		if (S_ISDIR(inode->i_mode)) {
+			struct dentry *dentry = d_find_any_alias(inode);
+			bool prune;
+
+			if (!dentry)
+				return 0;
+			prune = drop_negative_children(dentry);
 			dput(dentry);
+			if (!prune)
+				return 0;
 		}
+		/* The iterator's inode reference is sufficient to prune aliases. */
+		d_prune_aliases(inode);
+		count = icount_read_once(inode);
+		if (count == 1)
+			(*remaining)--;
+		doutc(cl, "%p %llx.%llx cap %p pruned, count now %d\n",
+		      inode, ceph_vinop(inode), cap, count);
 		return 0;
 	}
 
-- 
2.47.3


                 reply	other threads:[~2026-09-07 21:23 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

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=20260907212325.508739-1-max.kellermann@ionos.com \
    --to=max.kellermann@ionos.com \
    --cc=amarkuze@redhat.com \
    --cc=ceph-devel@vger.kernel.org \
    --cc=idryomov@gmail.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=xiubo.li@clyso.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

all inboxes | Powered by JetHome®