]> git.ipfire.org Git - thirdparty/kernel/linux.git/commitdiff
kill d_dispose_if_unused()
authorAl Viro <viro@zeniv.linux.org.uk>
Mon, 13 Apr 2026 03:39:16 +0000 (23:39 -0400)
committerAl Viro <viro@zeniv.linux.org.uk>
Fri, 5 Jun 2026 04:34:55 +0000 (00:34 -0400)
Rename to_shrink_list() into __move_to_shrink_list(), document and
export it.  Switch d_dispose_if_unused() users to that and kill
d_dispose_if_unused() itself.

Signed-off-by: Al Viro <viro@zeniv.linux.org.uk>
Documentation/filesystems/porting.rst
fs/dcache.c
fs/fuse/dir.c
include/linux/dcache.h

index 36fecc7a3d972c7e5659fd4c3c9a2cd4117372d3..003ab084ad48f388e37bd391b290fbd990b38583 100644 (file)
@@ -1391,3 +1391,14 @@ either form of manual loop.
 **mandatory**
 
 d_alloc_parallel() no longer requires a waitqueue_head.
+
+---
+
+**mandatory**
+
+d_dispose_if_unused() is gone; use __move_to_shrink_list() if you really
+need that functionality, but watch out for memory safety issues - just
+as with d_dispose_if_unused() these are not trivial; with this variant
+of API it's more explicit, since grabbing ->d_lock is caller-side, but
+d_dispose_if_unused() had all the same issues.  It's a low-level primitive;
+use only if you have no alternative.
index 7a0c8349b5a1a72765b4d540aba283cb5b874c01..ea26bd2dd2b27cc85a25890f7334399240cc625b 100644 (file)
@@ -988,7 +988,24 @@ void d_make_discardable(struct dentry *dentry)
 }
 EXPORT_SYMBOL(d_make_discardable);
 
-static bool to_shrink_list(struct dentry *dentry, struct list_head *list)
+/**
+ * __move_to_shrink_list - try to place a dentry into a shrink list
+ * @dentry:    dentry to try putting into shrink list
+ * @list:      the list to put @dentry into.
+ * Returns:    true @dentry had been placed into @list, false otherwise
+ *
+ * If @dentry is idle and not already include into a shrink list, move
+ * it into @list and return %true; otherwise do nothing and return %false.
+ *
+ * Caller must be holding @dentry->d_lock.  There must have been no calls of
+ * dentry_free(@dentry) prior to the beginning of the RCU read-side critical
+ * area in which __move_to_shrink_list(@dentry, @list) is called.
+ *
+ * @list should be thread-private and eventually emptied by passing it to
+ * shrink_dentry_list().
+ */
+
+bool __move_to_shrink_list(struct dentry *dentry, struct list_head *list)
 __must_hold(&dentry->d_lock)
 {
        if (likely(!dentry->d_lockref.count &&
@@ -1000,6 +1017,7 @@ __must_hold(&dentry->d_lock)
        }
        return false;
 }
+EXPORT_SYMBOL(__move_to_shrink_list);
 
 void dput_to_list(struct dentry *dentry, struct list_head *list)
 {
@@ -1009,7 +1027,7 @@ void dput_to_list(struct dentry *dentry, struct list_head *list)
                return;
        }
        rcu_read_unlock();
-       to_shrink_list(dentry, list);
+       __move_to_shrink_list(dentry, list);
        spin_unlock(&dentry->d_lock);
 }
 
@@ -1170,24 +1188,6 @@ struct dentry *d_find_alias_rcu(struct inode *inode)
        return de;
 }
 
-/**
- * d_dispose_if_unused - move unreferenced dentries to shrink list
- * @dentry: dentry in question
- * @dispose: head of shrink list
- *
- * If dentry has no external references, move it to shrink list.
- *
- * NOTE!!! The caller is responsible for preventing eviction of the dentry by
- * holding dentry->d_inode->i_lock or equivalent.
- */
-void d_dispose_if_unused(struct dentry *dentry, struct list_head *dispose)
-{
-       spin_lock(&dentry->d_lock);
-       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.
@@ -1198,8 +1198,11 @@ void d_prune_aliases(struct inode *inode)
        struct dentry *dentry;
 
        spin_lock(&inode->i_lock);
-       for_each_alias(dentry, inode)
-               d_dispose_if_unused(dentry, &dispose);
+       for_each_alias(dentry, inode) {
+               spin_lock(&dentry->d_lock);
+               __move_to_shrink_list(dentry, &dispose);
+               spin_unlock(&dentry->d_lock);
+       }
        spin_unlock(&inode->i_lock);
        shrink_dentry_list(&dispose);
 }
@@ -1592,7 +1595,7 @@ static enum d_walk_ret select_collect(void *_data, struct dentry *dentry)
                goto out;
 
        if (dentry->d_lockref.count <= 0) {
-               to_shrink_list(dentry, &data->dispose);
+               __move_to_shrink_list(dentry, &data->dispose);
                data->found++;
        }
        /*
@@ -1624,7 +1627,7 @@ static enum d_walk_ret select_collect2(void *_data, struct dentry *dentry)
                goto out;
 
        if (dentry->d_lockref.count <= 0) {
-               if (!to_shrink_list(dentry, &data->dispose)) {
+               if (!__move_to_shrink_list(dentry, &data->dispose)) {
                        rcu_read_lock();
                        data->victim = dentry;
                        return D_WALK_QUIT;
index b658b6baf72fe9149c2e79e33f8e4d6fd4b4b1cf..d8e8ea7280bc65c244b89ebf867f1284108733fe 100644 (file)
@@ -177,8 +177,8 @@ static void fuse_dentry_tree_work(struct work_struct *work)
                        spin_lock(&fd->dentry->d_lock);
                        /* If dentry is still referenced, let next dput release it */
                        fd->dentry->d_flags |= DCACHE_OP_DELETE;
+                       __move_to_shrink_list(fd->dentry, &dispose);
                        spin_unlock(&fd->dentry->d_lock);
-                       d_dispose_if_unused(fd->dentry, &dispose);
                        if (need_resched()) {
                                spin_unlock(&dentry_hash[i].lock);
                                cond_resched();
index a3409de3f490b0090c692175aad70e04b3414275..4b1ff99608e01ce2ebd89e722e22218b9c35e6f5 100644 (file)
@@ -280,7 +280,7 @@ 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 bool __move_to_shrink_list(struct dentry *, struct list_head *);
 extern void shrink_dentry_list(struct list_head *);
 
 extern struct dentry *d_find_alias_rcu(struct inode *);