diff mbox series

[RFC,1/2] fs/dcache: make cond_resched in __dentry_kill optional

Message ID 20220331190827.48241-2-stephen.s.brennan@oracle.com (mailing list archive)
State New, archived
Headers show
Series fs/dcache: Per directory amortized negative dentry pruning | expand

Commit Message

Stephen Brennan March 31, 2022, 7:08 p.m. UTC
Some callers of __dentry_kill may be killing single dentries, where a
cond_resched is not strictly necessary (and may result in undesirable
sleeps). Add a check_resched flag so the caller may request that we
do not call cond_resched().

Signed-off-by: Stephen Brennan <stephen.s.brennan@oracle.com>
---
 fs/dcache.c | 15 ++++++++-------
 1 file changed, 8 insertions(+), 7 deletions(-)
diff mbox series

Patch

diff --git a/fs/dcache.c b/fs/dcache.c
index 93f4f5ee07bf..b1480433ddc5 100644
--- a/fs/dcache.c
+++ b/fs/dcache.c
@@ -575,7 +575,7 @@  static inline void dentry_unlist(struct dentry *dentry, struct dentry *parent)
 	}
 }
 
-static void __dentry_kill(struct dentry *dentry)
+static void __dentry_kill(struct dentry *dentry, bool check_resched)
 {
 	struct dentry *parent = NULL;
 	bool can_free = true;
@@ -619,7 +619,8 @@  static void __dentry_kill(struct dentry *dentry)
 	spin_unlock(&dentry->d_lock);
 	if (likely(can_free))
 		dentry_free(dentry);
-	cond_resched();
+	if (check_resched)
+		cond_resched();
 }
 
 static struct dentry *__lock_parent(struct dentry *dentry)
@@ -730,7 +731,7 @@  static struct dentry *dentry_kill(struct dentry *dentry)
 			goto slow_positive;
 		}
 	}
-	__dentry_kill(dentry);
+	__dentry_kill(dentry, true);
 	return parent;
 
 slow_positive:
@@ -742,7 +743,7 @@  static struct dentry *dentry_kill(struct dentry *dentry)
 	if (unlikely(dentry->d_lockref.count != 1)) {
 		dentry->d_lockref.count--;
 	} else if (likely(!retain_dentry(dentry))) {
-		__dentry_kill(dentry);
+		__dentry_kill(dentry, true);
 		return parent;
 	}
 	/* we are keeping it, after all */
@@ -1109,7 +1110,7 @@  void d_prune_aliases(struct inode *inode)
 		if (!dentry->d_lockref.count) {
 			struct dentry *parent = lock_parent(dentry);
 			if (likely(!dentry->d_lockref.count)) {
-				__dentry_kill(dentry);
+				__dentry_kill(dentry, true);
 				dput(parent);
 				goto restart;
 			}
@@ -1198,7 +1199,7 @@  void shrink_dentry_list(struct list_head *list)
 		parent = dentry->d_parent;
 		if (parent != dentry)
 			__dput_to_list(parent, list);
-		__dentry_kill(dentry);
+		__dentry_kill(dentry, true);
 	}
 }
 
@@ -1645,7 +1646,7 @@  void shrink_dcache_parent(struct dentry *parent)
 				parent = data.victim->d_parent;
 				if (parent != data.victim)
 					__dput_to_list(parent, &data.dispose);
-				__dentry_kill(data.victim);
+				__dentry_kill(data.victim, true);
 			}
 		}
 		if (!list_empty(&data.dispose))