Skip to contentSkip to conversation

ext4: remove redundant check buffer_uptodate()

PATCH Superseded Joseph Qi 3 participants 3 messages Apr 26, 2021 ext4 file system

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore

Joseph Qi

author
#0 lore raw

PATCH 1/1 ext4: remove redundant check buffer_uptodate()

Now set_buffer_uptodate() will test first and then set, so we don't have to check buffer_uptodate() first, remove it to simplify code.

---
 fs/ext4/inode.c | 9 +++------
 1 file changed, 3 insertions(+), 6 deletions(-)
fs/ext4/inode.c +3 -6
index 0948a43..9e02538 100644
@@ -1065,10 +1065,8 @@ static int ext4_block_write_begin(struct page *page, loff_t pos, unsigned len,
 	    block++, block_start = block_end, bh = bh->b_this_page) {
 		block_end = block_start + blocksize;
 		if (block_end <= from || block_start >= to) {
-			if (PageUptodate(page)) {
-				if (!buffer_uptodate(bh))
-					set_buffer_uptodate(bh);
-			}
+			if (PageUptodate(page))
+				set_buffer_uptodate(bh);
 			continue;
 		}
 		if (buffer_new(bh))
@@ -1092,8 +1090,7 @@ static int ext4_block_write_begin(struct page *page, loff_t pos, unsigned len,
 			}
 		}
 		if (PageUptodate(page)) {
-			if (!buffer_uptodate(bh))
-				set_buffer_uptodate(bh);
+			set_buffer_uptodate(bh);
 			continue;
 		}
 		if (!buffer_uptodate(bh) && !buffer_delay(bh) &&
Signature · 1 line
1.8.3.1
Reviewed-by on v1 1/1
#1 lore raw
Quoted 2 lines · Joseph Qi

Now set_buffer_uptodate() will test first and then set, so we don't have to check buffer_uptodate() first, remove it to simplify code.

Maybe we can change below function as well then.
No need to check same thing twice since set_buffer_uptodate() is already doing the check.

fs/ext4/ext4.h +1 -1
index b258e8279266..856bd9981409 100644
@@ -3749,7 +3749,7 @@ static inline int ext4_buffer_uptodate(struct buffer_head *bh)
         * have to read the block because we may read the old data
         * successfully.
         */
-       if (!buffer_uptodate(bh) && buffer_write_io_error(bh))
+       if (buffer_write_io_error(bh))
                set_buffer_uptodate(bh);
        return buffer_uptodate(bh);
 }

With that pls feel free to add:

Quoted 36 lines
---
 fs/ext4/inode.c | 9 +++------
 1 file changed, 3 insertions(+), 6 deletions(-)
fs/ext4/inode.c +3 -7
index 0948a43..9e02538 100644
@@ -1065,10 +1065,8 @@ static int ext4_block_write_begin(struct page *page, loff_t pos, unsigned len,
 	    block++, block_start = block_end, bh = bh->b_this_page) {
 		block_end = block_start + blocksize;
 		if (block_end <= from || block_start >= to) {
-			if (PageUptodate(page)) {
-				if (!buffer_uptodate(bh))
-					set_buffer_uptodate(bh);
-			}
+			if (PageUptodate(page))
+				set_buffer_uptodate(bh);
 			continue;
 		}
 		if (buffer_new(bh))
@@ -1092,8 +1090,7 @@ static int ext4_block_write_begin(struct page *page, loff_t pos, unsigned len,
 			}
 		}
 		if (PageUptodate(page)) {
-			if (!buffer_uptodate(bh))
-				set_buffer_uptodate(bh);
+			set_buffer_uptodate(bh);
 			continue;
 		}
 		if (!buffer_uptodate(bh) && !buffer_delay(bh) &&
--

1.8.3.1

#2 lore raw
Quoted 21 lines · riteshh
Quoted 2 lines · Joseph Qi

Now set_buffer_uptodate() will test first and then set, so we don't have to check buffer_uptodate() first, remove it to simplify code.

Maybe we can change below function as well then.
No need to check same thing twice since set_buffer_uptodate() is already doing the check.

fs/ext4/ext4.h +1 -1
index b258e8279266..856bd9981409 100644
@@ -3749,7 +3749,7 @@ static inline int ext4_buffer_uptodate(struct buffer_head *bh)
         * have to read the block because we may read the old data
         * successfully.
         */
-       if (!buffer_uptodate(bh) && buffer_write_io_error(bh))
+       if (buffer_write_io_error(bh))
                set_buffer_uptodate(bh);
        return buffer_uptodate(bh);
 }
Quoted 3 lines

With that pls feel free to add:

Sure, will send v2 with above addressed.

Thanks,
Joseph