diff mbox series

[19/22] to_shrink_list(): call only if refcount is 0

Message ID 20231109062056.3181775-19-viro@zeniv.linux.org.uk (mailing list archive)
State New
Headers show
Series [01/22] struct dentry: get rid of randomize_layout idiocy | expand

Commit Message

Al Viro Nov. 9, 2023, 6:20 a.m. UTC
The only thing it does if refcount is not zero is d_lru_del(); no
point, IMO, seeing that plain dput() does nothing of that sort...

Note that 2 of 3 current callers are guaranteed that refcount is 0.

Signed-off-by: Al Viro <viro@zeniv.linux.org.uk>
---
 fs/dcache.c | 7 ++-----
 1 file changed, 2 insertions(+), 5 deletions(-)

Comments

Christian Brauner Nov. 9, 2023, 5:29 p.m. UTC | #1
On Thu, Nov 09, 2023 at 06:20:53AM +0000, Al Viro wrote:
> The only thing it does if refcount is not zero is d_lru_del(); no
> point, IMO, seeing that plain dput() does nothing of that sort...
> 
> Note that 2 of 3 current callers are guaranteed that refcount is 0.
> 
> Signed-off-by: Al Viro <viro@zeniv.linux.org.uk>
> ---

Ok, I don't fully understand this one but I see nothing obviously wrong
with it so,

Acked-by: Christian Brauner <brauner@kernel.org>

>  fs/dcache.c | 7 ++-----
>  1 file changed, 2 insertions(+), 5 deletions(-)
> 
> diff --git a/fs/dcache.c b/fs/dcache.c
> index aa9f7ee7a603..49585f2ad896 100644
> --- a/fs/dcache.c
> +++ b/fs/dcache.c
> @@ -915,8 +915,7 @@ __must_hold(&dentry->d_lock)
>  	if (!(dentry->d_flags & DCACHE_SHRINK_LIST)) {
>  		if (dentry->d_flags & DCACHE_LRU_LIST)
>  			d_lru_del(dentry);
> -		if (!dentry->d_lockref.count)
> -			d_shrink_add(dentry, list);
> +		d_shrink_add(dentry, list);
>  	}
>  }
>  
> @@ -1110,10 +1109,8 @@ EXPORT_SYMBOL(d_prune_aliases);
>  static inline void shrink_kill(struct dentry *victim, struct list_head *list)
>  {
>  	struct dentry *parent = victim->d_parent;
> -	if (parent != victim) {
> -		--parent->d_lockref.count;
> +	if (parent != victim && !--parent->d_lockref.count)
>  		to_shrink_list(parent, list);
> -	}
>  	__dentry_kill(victim);
>  }
>  
> -- 
> 2.39.2
>
diff mbox series

Patch

diff --git a/fs/dcache.c b/fs/dcache.c
index aa9f7ee7a603..49585f2ad896 100644
--- a/fs/dcache.c
+++ b/fs/dcache.c
@@ -915,8 +915,7 @@  __must_hold(&dentry->d_lock)
 	if (!(dentry->d_flags & DCACHE_SHRINK_LIST)) {
 		if (dentry->d_flags & DCACHE_LRU_LIST)
 			d_lru_del(dentry);
-		if (!dentry->d_lockref.count)
-			d_shrink_add(dentry, list);
+		d_shrink_add(dentry, list);
 	}
 }
 
@@ -1110,10 +1109,8 @@  EXPORT_SYMBOL(d_prune_aliases);
 static inline void shrink_kill(struct dentry *victim, struct list_head *list)
 {
 	struct dentry *parent = victim->d_parent;
-	if (parent != victim) {
-		--parent->d_lockref.count;
+	if (parent != victim && !--parent->d_lockref.count)
 		to_shrink_list(parent, list);
-	}
 	__dentry_kill(victim);
 }