Re: [PATCH v5 5/5] Use d_for_each_positive_child() in fsnotify.

From: Jan Kara

Date: Fri Nov 20 2026 - 05:08:51 EST


On Thu 19-11-26 13:57:05, NeilBrown wrote:
> 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>

Looks good. Feel free to add:

Reviewed-by: Jan Kara <jack@xxxxxxx>

Honza

> ---
> 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 58566e6b9679..33c5d10f78ba 100644
> --- a/fs/notify/fsnotify.c
> +++ b/fs/notify/fsnotify.c
> @@ -86,16 +86,12 @@ void fsnotify_set_children_dentry_flags(struct inode *inode)
> * their 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
>
--
Jan Kara <jack@xxxxxxxx>
SUSE Labs, CR