[PATCH v4 5/5] Use d_for_each_positive_child() in fsnotify.
From: NeilBrown
Date: Sun Oct 18 2026 - 20:11:44 EST
From: NeilBrown <neil@xxxxxxxxxx>
fsnotify has been reported as source of soft-lockups when iterating a
long ->d_children list. Change it to use d_for_each_positive_child()
which will call cond_resched() as needed to avoid soft-lockups.
Link https://lwn.net/Articles/1079407/
Signed-off-by: NeilBrown <neil@xxxxxxxxxx>
---
fs/notify/fsnotify.c | 6 +-----
1 file changed, 1 insertion(+), 5 deletions(-)
diff --git a/fs/notify/fsnotify.c b/fs/notify/fsnotify.c
index 465e875dec57..62c17e4e4798 100644
--- a/fs/notify/fsnotify.c
+++ b/fs/notify/fsnotify.c
@@ -86,16 +86,12 @@ void fsnotify_set_children_dentry_flags(struct inode *inode)
* d_flags to indicate parental interest (their parent is the
* original inode)
*/
- spin_lock(&alias->d_lock);
- hlist_for_each_entry(child, &alias->d_children, d_sib) {
- if (!child->d_inode)
- continue;
+ d_for_each_positive_child(child, alias) {
spin_lock_nested(&child->d_lock, DENTRY_D_LOCK_NESTED);
child->d_flags |= DCACHE_FSNOTIFY_PARENT_WATCHED;
spin_unlock(&child->d_lock);
}
- spin_unlock(&alias->d_lock);
dput(alias);
}
--
2.50.0.107.gf914562f5916.dirty