diff mbox series

[V2] iomap: skip unnecessary ifs_block_is_uptodate check

Message ID 20250410054223.3325-1-gouhao@uniontech.com (mailing list archive)
State New
Headers show
Series [V2] iomap: skip unnecessary ifs_block_is_uptodate check | expand

Commit Message

Gou Hao April 10, 2025, 5:42 a.m. UTC
prior to the loop, $i is either the first !uptodate block, or
it's past $last.  Assuming there's no overflow (there's no combination
of huge folios and tiny blksize) then yeah, there's no point in
retesting that the same block $i is uptodate since we hold the folio
lock so nobody else could have set uptodate.

Signed-off-by: Gou Hao <gouhao@uniontech.com>
Reviewed-by: "Darrick J. Wong" <djwong@kernel.org>
---
 fs/iomap/buffered-io.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

Comments

Christoph Hellwig April 10, 2025, 5:54 a.m. UTC | #1
On Thu, Apr 10, 2025 at 01:42:23PM +0800, Gou Hao wrote:
> prior to the loop, $i is either the first !uptodate block, or
> it's past $last.  Assuming there's no overflow (there's no combination
> of huge folios and tiny blksize) then yeah, there's no point in
> retesting that the same block $i is uptodate since we hold the folio
> lock so nobody else could have set uptodate.

Capitalize the first word in the sentence and use up the 73 characters
available for the commit log:

In iomap_adjust_read_range, i is either the first !uptodate block, or it
is past last for the second loop looking for trailing uptodate blocks.
Assuming there's no overflow (there's no combination of huge folios and
tiny blksize) then yeah, there is no point in retesting that the same
block pointed to by i is uptodate since we hold the folio lock so nobody
else could have set it uptodate.

>  		/* truncate len if we find any trailing uptodate block(s) */
> -		for ( ; i <= last; i++) {
> +		for (i++; i <= last; i++) {

A bit nitpicky, but I find a i++ in the initialization condition of a
for loop a bit odd.

What about turning this into a:

		while (++i <= last) {

?
Gou Hao April 10, 2025, 6:25 a.m. UTC | #2
On 2025/4/10 13:54, Christoph Hellwig wrote:
> On Thu, Apr 10, 2025 at 01:42:23PM +0800, Gou Hao wrote:
>> prior to the loop, $i is either the first !uptodate block, or
>> it's past $last.  Assuming there's no overflow (there's no combination
>> of huge folios and tiny blksize) then yeah, there's no point in
>> retesting that the same block $i is uptodate since we hold the folio
>> lock so nobody else could have set uptodate.
> Capitalize the first word in the sentence and use up the 73 characters
> available for the commit log:
>
> In iomap_adjust_read_range, i is either the first !uptodate block, or it
> is past last for the second loop looking for trailing uptodate blocks.
> Assuming there's no overflow (there's no combination of huge folios and
> tiny blksize) then yeah, there is no point in retesting that the same
> block pointed to by i is uptodate since we hold the folio lock so nobody
> else could have set it uptodate.
Thank you, i will change the log in next patch.
>>   		/* truncate len if we find any trailing uptodate block(s) */
>> -		for ( ; i <= last; i++) {
>> +		for (i++; i <= last; i++) {
> A bit nitpicky, but I find a i++ in the initialization condition of a
> for loop a bit odd.
>
> What about turning this into a:
>
> 		while (++i <= last) {
>
> ?
Yes,  it is better.  I will test this.
>
diff mbox series

Patch

diff --git a/fs/iomap/buffered-io.c b/fs/iomap/buffered-io.c
index 31553372b33a..2f52e8e61240 100644
--- a/fs/iomap/buffered-io.c
+++ b/fs/iomap/buffered-io.c
@@ -259,7 +259,7 @@  static void iomap_adjust_read_range(struct inode *inode, struct folio *folio,
 		}
 
 		/* truncate len if we find any trailing uptodate block(s) */
-		for ( ; i <= last; i++) {
+		for (i++; i <= last; i++) {
 			if (ifs_block_is_uptodate(ifs, i)) {
 				plen -= (last - i + 1) * block_size;
 				last = i - 1;