linux-fsdevel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] vfs: Remove unnecessary list_for_each_entry_safe() from evict_inodes()
@ 2025-07-09  9:06 Jan Kara
  2025-07-09 13:14 ` Matthew Wilcox
  2025-07-10  7:38 ` Christian Brauner
  0 siblings, 2 replies; 3+ messages in thread
From: Jan Kara @ 2025-07-09  9:06 UTC (permalink / raw)
  To: Christian Brauner; +Cc: Al Viro, linux-fsdevel, Jan Kara

evict_inodes() uses list_for_each_entry_safe() to iterate sb->s_inodes
list. However, since we use i_lru list entry for our local temporary
list of inodes to destroy, the inode is guaranteed to stay in
sb->s_inodes list while we hold sb->s_inode_list_lock. So there is no
real need for safe iteration variant and we can use
list_for_each_entry() just fine.

Signed-off-by: Jan Kara <jack@suse.cz>
---
 fs/inode.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

Small cleanup I have sitting in my tree for ages and which I think is still
worth it.

diff --git a/fs/inode.c b/fs/inode.c
index 99318b157a9a..3e990330bb05 100644
--- a/fs/inode.c
+++ b/fs/inode.c
@@ -865,12 +865,12 @@ static void dispose_list(struct list_head *head)
  */
 void evict_inodes(struct super_block *sb)
 {
-	struct inode *inode, *next;
+	struct inode *inode;
 	LIST_HEAD(dispose);
 
 again:
 	spin_lock(&sb->s_inode_list_lock);
-	list_for_each_entry_safe(inode, next, &sb->s_inodes, i_sb_list) {
+	list_for_each_entry(inode, &sb->s_inodes, i_sb_list) {
 		if (atomic_read(&inode->i_count))
 			continue;
 
-- 
2.43.0


^ permalink raw reply related	[flat|nested] 3+ messages in thread

* Re: [PATCH] vfs: Remove unnecessary list_for_each_entry_safe() from evict_inodes()
  2025-07-09  9:06 [PATCH] vfs: Remove unnecessary list_for_each_entry_safe() from evict_inodes() Jan Kara
@ 2025-07-09 13:14 ` Matthew Wilcox
  2025-07-10  7:38 ` Christian Brauner
  1 sibling, 0 replies; 3+ messages in thread
From: Matthew Wilcox @ 2025-07-09 13:14 UTC (permalink / raw)
  To: Jan Kara; +Cc: Christian Brauner, Al Viro, linux-fsdevel

On Wed, Jul 09, 2025 at 11:06:36AM +0200, Jan Kara wrote:
> evict_inodes() uses list_for_each_entry_safe() to iterate sb->s_inodes
> list. However, since we use i_lru list entry for our local temporary
> list of inodes to destroy, the inode is guaranteed to stay in
> sb->s_inodes list while we hold sb->s_inode_list_lock. So there is no
> real need for safe iteration variant and we can use
> list_for_each_entry() just fine.

Yes, agreed, this is safe.  I thought it wasn't, because (a) we call
inode_lru_list_del(), but that's a different list (i_lru, not i_sb_list)
and (b) we call dispose() which calls evict(), but if we do that, we
restart the list walk.

> Signed-off-by: Jan Kara <jack@suse.cz>

Reviewed-by: Matthew Wilcox (Oracle) <willy@infradead.org>

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH] vfs: Remove unnecessary list_for_each_entry_safe() from evict_inodes()
  2025-07-09  9:06 [PATCH] vfs: Remove unnecessary list_for_each_entry_safe() from evict_inodes() Jan Kara
  2025-07-09 13:14 ` Matthew Wilcox
@ 2025-07-10  7:38 ` Christian Brauner
  1 sibling, 0 replies; 3+ messages in thread
From: Christian Brauner @ 2025-07-10  7:38 UTC (permalink / raw)
  To: Jan Kara; +Cc: Christian Brauner, Al Viro, linux-fsdevel

On Wed, 09 Jul 2025 11:06:36 +0200, Jan Kara wrote:
> evict_inodes() uses list_for_each_entry_safe() to iterate sb->s_inodes
> list. However, since we use i_lru list entry for our local temporary
> list of inodes to destroy, the inode is guaranteed to stay in
> sb->s_inodes list while we hold sb->s_inode_list_lock. So there is no
> real need for safe iteration variant and we can use
> list_for_each_entry() just fine.
> 
> [...]

Applied to the vfs-6.17.misc branch of the vfs/vfs.git tree.
Patches in the vfs-6.17.misc branch should appear in linux-next soon.

Please report any outstanding bugs that were missed during review in a
new review to the original patch series allowing us to drop it.

It's encouraged to provide Acked-bys and Reviewed-bys even though the
patch has now been applied. If possible patch trailers will be updated.

Note that commit hashes shown below are subject to change due to rebase,
trailer updates or similar. If in doubt, please check the listed branch.

tree:   https://git.kernel.org/pub/scm/linux/kernel/git/vfs/vfs.git
branch: vfs-6.17.misc

[1/1] vfs: Remove unnecessary list_for_each_entry_safe() from evict_inodes()
      https://git.kernel.org/vfs/vfs/c/3bc4e4410830

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2025-07-10  7:38 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-07-09  9:06 [PATCH] vfs: Remove unnecessary list_for_each_entry_safe() from evict_inodes() Jan Kara
2025-07-09 13:14 ` Matthew Wilcox
2025-07-10  7:38 ` Christian Brauner

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).