[<prev] [next>] [thread-next>] [day] [month] [year] [list]
Message-ID: <20250616054722.142310-1-chizhiling@163.com>
Date: Mon, 16 Jun 2025 13:47:22 +0800
From: Chi Zhiling <chizhiling@....com>
To: brauner@...nel.org,
djwong@...nel.org
Cc: linux-xfs@...r.kernel.org,
linux-fsdevel@...r.kernel.org,
linux-kernel@...r.kernel.org,
Chi Zhiling <chizhiling@...inos.cn>
Subject: [PATCH] iomap: Reduce some calculations in iomap_adjust_read_range()
From: Chi Zhiling <chizhiling@...inos.cn>
It's unnecessary to update the poff and plen in every loop, delay the
calculations until return stage.
Signed-off-by: Chi Zhiling <chizhiling@...inos.cn>
---
fs/iomap/buffered-io.c | 11 +++++------
1 file changed, 5 insertions(+), 6 deletions(-)
diff --git a/fs/iomap/buffered-io.c b/fs/iomap/buffered-io.c
index 3729391a18f3..0a1be45f7b96 100644
--- a/fs/iomap/buffered-io.c
+++ b/fs/iomap/buffered-io.c
@@ -233,7 +233,6 @@ static void iomap_adjust_read_range(struct inode *inode, struct folio *folio,
loff_t orig_pos = *pos;
loff_t isize = i_size_read(inode);
unsigned block_bits = inode->i_blkbits;
- unsigned block_size = (1 << block_bits);
size_t poff = offset_in_folio(folio, *pos);
size_t plen = min_t(loff_t, folio_size(folio) - poff, length);
size_t orig_plen = plen;
@@ -252,16 +251,12 @@ static void iomap_adjust_read_range(struct inode *inode, struct folio *folio,
for (i = first; i <= last; i++) {
if (!ifs_block_is_uptodate(ifs, i))
break;
- *pos += block_size;
- poff += block_size;
- plen -= block_size;
first++;
}
/* truncate len if we find any trailing uptodate block(s) */
while (++i <= last) {
if (ifs_block_is_uptodate(ifs, i)) {
- plen -= (last - i + 1) * block_size;
last = i - 1;
break;
}
@@ -277,9 +272,13 @@ static void iomap_adjust_read_range(struct inode *inode, struct folio *folio,
unsigned end = offset_in_folio(folio, isize - 1) >> block_bits;
if (first <= end && last > end)
- plen -= (last - end) * block_size;
+ last = end;
}
+ poff = first << block_bits;
+ plen = (last - first + 1) << block_bits;
+ *pos = folio_pos(folio) + poff;
+
*offp = poff;
*lenp = plen;
}
--
2.43.0
Powered by blists - more mailing lists