vfs: Remove unnecessary list_for_each_entry_safe() variants
Jan Kara
reviewerPATCH 1/1 vfs: Remove unnecessary list_for_each_entry_safe() variants
evict_inodes() and invalidate_inodes() use 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.
--- fs/inode.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-)
fs/inode.c +4 -4
@@ -601,12 +601,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 ;
@@ -651,11 +651,11 @@ void evict_inodes(struct super_block *sb)int invalidate_inodes (struct super_block *sb,bool kill_dirty) {int busy =0 ; -struct inode *inode, *next; +struct inode *inode;LIST_HEAD (dispose);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) {spin_lock (&inode->i_lock);if (inode->i_state & (I_NEW |I_FREEING |I_WILL_FREE )) {spin_unlock (&inode->i_lock);
Signature · 1 line
2.10.2
Quoted 7 lines · Jan Kara
evict_inodes()andinvalidate_inodes()uselist_for_each_entry_safe()to iteratesb->s_inodeslist. However, since we usei_lrulist entry for our local temporary list of inodes to destroy, the inode is guaranteed to stay insb->s_inodeslist while we holdsb->s_inode_list_lock. So there is no real need for safe iteration variant and we can uselist_for_each_entry()just fine.
This is a pretty "subtle" change, IMHO, with little benefit. IMHO, using the "_safe" variant makes it more clear to the reader that the inode is being deleted from the list. At a minimum, I'd think there should be a comment at list_for_each_entry() to the effect that the inode is not going to be deleted, so list_for_each_entry_safe() is not needed. Otherwise, if the inode lifetime changes in some manner in the future this may introduce hard-to-find corruption of freed memory.
Cheers, Andreas
Quoted 41 lines
Signed-off-by Jan Kara <[email protected]>---
fs/inode.c| 8 ++++----1 file changed, 4 insertions(+), 4 deletions(-)fs/inode.c +1
-1@@ -601,12 +601,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);fs/inode.c +1
-1-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;fs/inode.c +2
-3@@ -651,11 +651,11 @@ void evict_inodes(struct super_block *sb)int invalidate_inodes (struct super_block *sb,bool kill_dirty) {int busy =0 ; -struct inode *inode, *next; +struct inode *inode;LIST_HEAD (dispose);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) {spin_lock (&inode->i_lock);if (inode->i_state & (I_NEW |I_FREEING |I_WILL_FREE )) {spin_unlock (&inode->i_lock); --2.10.2
Quoted 4 lines
--
To unsubscribe from this list: send the line "unsubscribe linux-fsdevel" in the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html
Cheers, Andreas
Jan Kara
reviewerQuoted 9 lines · Andreas Dilger
Quoted 7 lines · Jan Kara
evict_inodes()andinvalidate_inodes()uselist_for_each_entry_safe()to iteratesb->s_inodeslist. However, since we usei_lrulist entry for our local temporary list of inodes to destroy, the inode is guaranteed to stay insb->s_inodeslist while we holdsb->s_inode_list_lock. So there is no real need for safe iteration variant and we can uselist_for_each_entry()just fine.
Quoted 7 lines
This is a pretty "subtle" change, IMHO, with little benefit. IMHO, using the "
_safe" variant makes it more clear to the reader that the inode is being deleted from the list. At a minimum, I'd think there should be a comment atlist_for_each_entry()to the effect that the inode is not going to be deleted, solist_for_each_entry_safe()is not needed. Otherwise, if the inode lifetime changes in some manner in the future this may introduce hard-to-find corruption of freed memory.
Well, but the inode is not deleted from the list we iterate (and that is pretty obvious from the loop body) so using a _safe variant looks just confusing to me... I can add a comment if people think that will help readability of the code.
Honza
Quoted 56 lines
Cheers, Andreas
Quoted 41 lines
Signed-off-by Jan Kara <[email protected]>---
fs/inode.c| 8 ++++----1 file changed, 4 insertions(+), 4 deletions(-)fs/inode.c +1
-1@@ -601,12 +601,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);fs/inode.c +1
-1-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;fs/inode.c +2
-3@@ -651,11 +651,11 @@ void evict_inodes(struct super_block *sb)int invalidate_inodes (struct super_block *sb,bool kill_dirty) {int busy =0 ; -struct inode *inode, *next; +struct inode *inode;LIST_HEAD (dispose);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) {spin_lock (&inode->i_lock);if (inode->i_state & (I_NEW |I_FREEING |I_WILL_FREE )) {spin_unlock (&inode->i_lock); --2.10.2
Quoted 4 lines
--
To unsubscribe from this list: send the line "unsubscribe linux-fsdevel" in the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.htmlCheers, Andreas
Signature · 2 lines
Jan Kara <[email protected]> SUSE Labs, CR