]> git.ipfire.org Git - thirdparty/kernel/linux.git/commitdiff
dcache: export shrink_dentry_list() and add new helper d_dispose_if_unused()
authorLuis Henriques <luis@igalia.com>
Tue, 16 Sep 2025 13:53:07 +0000 (14:53 +0100)
committerMiklos Szeredi <mszeredi@redhat.com>
Wed, 12 Nov 2025 10:45:03 +0000 (11:45 +0100)
Add and export a new helper d_dispose_if_unused() which is simply a wrapper
around to_shrink_list(), to add an entry to a dispose list if it's not used
anymore.

Also export shrink_dentry_list() to kill all dentries in a dispose list.

Suggested-by: Miklos Szeredi <miklos@szeredi.hu>
Signed-off-by: Luis Henriques <luis@igalia.com>
Signed-off-by: Miklos Szeredi <mszeredi@redhat.com>
fs/dcache.c
include/linux/dcache.h

index 035cccbc927658abf16850a6174ed3661998ee52..bffb1b47a907c3cd96e4a7174f23e8bce365b466 100644 (file)
@@ -1086,6 +1086,15 @@ struct dentry *d_find_alias_rcu(struct inode *inode)
        return de;
 }
 
+void d_dispose_if_unused(struct dentry *dentry, struct list_head *dispose)
+{
+       spin_lock(&dentry->d_lock);
+       if (!dentry->d_lockref.count)
+               to_shrink_list(dentry, dispose);
+       spin_unlock(&dentry->d_lock);
+}
+EXPORT_SYMBOL(d_dispose_if_unused);
+
 /*
  *     Try to kill dentries associated with this inode.
  * WARNING: you must own a reference to inode.
@@ -1096,12 +1105,8 @@ void d_prune_aliases(struct inode *inode)
        struct dentry *dentry;
 
        spin_lock(&inode->i_lock);
-       hlist_for_each_entry(dentry, &inode->i_dentry, d_u.d_alias) {
-               spin_lock(&dentry->d_lock);
-               if (!dentry->d_lockref.count)
-                       to_shrink_list(dentry, &dispose);
-               spin_unlock(&dentry->d_lock);
-       }
+       hlist_for_each_entry(dentry, &inode->i_dentry, d_u.d_alias)
+               d_dispose_if_unused(dentry, &dispose);
        spin_unlock(&inode->i_lock);
        shrink_dentry_list(&dispose);
 }
@@ -1141,6 +1146,7 @@ void shrink_dentry_list(struct list_head *list)
                shrink_kill(dentry);
        }
 }
+EXPORT_SYMBOL(shrink_dentry_list);
 
 static enum lru_status dentry_lru_isolate(struct list_head *item,
                struct list_lru_one *lru, void *arg)
index c83e02b9438940e2cf5c94a0a9aba8d401ee0b77..2bc1339bf6d0362c7059d02845c3dad709954e1d 100644 (file)
@@ -268,6 +268,8 @@ extern void d_tmpfile(struct file *, struct inode *);
 
 extern struct dentry *d_find_alias(struct inode *);
 extern void d_prune_aliases(struct inode *);
+extern void d_dispose_if_unused(struct dentry *, struct list_head *);
+extern void shrink_dentry_list(struct list_head *);
 
 extern struct dentry *d_find_alias_rcu(struct inode *);