[PATCH] ceph: skip alias lookup when trimming non-directory caps

Max Kellermann posted 1 patch 2 weeks, 4 days ago
fs/ceph/mds_client.c | 30 ++++++++++++++++++------------
1 file changed, 18 insertions(+), 12 deletions(-)
[PATCH] ceph: skip alias lookup when trimming non-directory caps
Posted by Max Kellermann 2 weeks, 4 days ago
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