diff mbox series

[3/3] ext4: Skip unwritten buffers in __ext4_block_zero_page_range()

Message ID 143d41362a57e453f5a2cb00dc71e38e020c1c20.1695987265.git.ojaswin@linux.ibm.com
State New
Headers show
Series Optimize __ext4_block_zero_page_range() for unwritten buffers | expand

Commit Message

Ojaswin Mujoo Sept. 29, 2023, 2:10 p.m. UTC
If the buffer is unwritten then the underlying block should already return zero
for reads. Further, if it is not dirty then we can be sure that there is no data
on the folio that might get written back later. Hence we skip zeroing out the
folio and underlying block in this case.

Suggested-by: Jan Kara <jack@suse.cz>
Signed-off-by: Ojaswin Mujoo <ojaswin@linux.ibm.com>
---
 fs/ext4/inode.c | 4 ++++
 1 file changed, 4 insertions(+)
diff mbox series

Patch

diff --git a/fs/ext4/inode.c b/fs/ext4/inode.c
index de8ea8430d30..75a951ffa3cb 100644
--- a/fs/ext4/inode.c
+++ b/fs/ext4/inode.c
@@ -3659,6 +3659,10 @@  static int __ext4_block_zero_page_range(handle_t *handle,
 		BUFFER_TRACE(bh, "freed: skip");
 		goto unlock;
 	}
+	if (buffer_unwritten(bh) && !buffer_dirty(bh)) {
+		BUFFER_TRACE(bh, "unwritten and non-dirty: skip");
+		goto unlock;
+	}
 	if (!buffer_mapped(bh)) {
 		BUFFER_TRACE(bh, "unmapped");
 		ext4_get_block(inode, iblock, bh, 0);