linux-fsdevel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] iomap: skip unnecessary ifs_block_is_uptodate check
@ 2025-04-08 17:29 Gou Hao
  2025-04-09 15:30 ` Darrick J. Wong
                   ` (2 more replies)
  0 siblings, 3 replies; 9+ messages in thread
From: Gou Hao @ 2025-04-08 17:29 UTC (permalink / raw)
  To: brauner, djwong
  Cc: linux-xfs, linux-fsdevel, linux-kernel, wangyuli, gouhaojake

After the first 'for' loop, the first call to
ifs_block_is_uptodate always evaluates to 0.

Signed-off-by: Gou Hao <gouhao@uniontech.com>
---
 fs/iomap/buffered-io.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

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;
-- 
2.20.1


^ permalink raw reply related	[flat|nested] 9+ messages in thread

* Re: [PATCH] iomap: skip unnecessary ifs_block_is_uptodate check
  2025-04-08 17:29 [PATCH] iomap: skip unnecessary ifs_block_is_uptodate check Gou Hao
@ 2025-04-09 15:30 ` Darrick J. Wong
  2025-04-10  5:37   ` Gou Hao
  2025-04-10  5:42 ` [PATCH V2] " Gou Hao
  2025-04-10  7:12 ` [PATCH V3] " Gou Hao
  2 siblings, 1 reply; 9+ messages in thread
From: Darrick J. Wong @ 2025-04-09 15:30 UTC (permalink / raw)
  To: Gou Hao
  Cc: brauner, linux-xfs, linux-fsdevel, linux-kernel, wangyuli,
	gouhaojake

On Wed, Apr 09, 2025 at 01:29:24AM +0800, Gou Hao wrote:
> After the first 'for' loop, the first call to
> ifs_block_is_uptodate always evaluates to 0.
> 
> Signed-off-by: Gou Hao <gouhao@uniontech.com>
> ---
>  fs/iomap/buffered-io.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
> 
> 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++) {

Hmmm... 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 that I can think of) 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.

Reviewed-by: "Darrick J. Wong" <djwong@kernel.org>

--D


>  			if (ifs_block_is_uptodate(ifs, i)) {
>  				plen -= (last - i + 1) * block_size;
>  				last = i - 1;
> -- 
> 2.20.1
> 
> 

^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: [PATCH] iomap: skip unnecessary ifs_block_is_uptodate check
  2025-04-09 15:30 ` Darrick J. Wong
@ 2025-04-10  5:37   ` Gou Hao
  0 siblings, 0 replies; 9+ messages in thread
From: Gou Hao @ 2025-04-10  5:37 UTC (permalink / raw)
  To: Darrick J. Wong
  Cc: brauner, linux-xfs, linux-fsdevel, linux-kernel, wangyuli,
	gouhaojake


On 2025/4/9 23:30, Darrick J. Wong wrote:
> On Wed, Apr 09, 2025 at 01:29:24AM +0800, Gou Hao wrote:
>> After the first 'for' loop, the first call to
>> ifs_block_is_uptodate always evaluates to 0.
>>
>> Signed-off-by: Gou Hao <gouhao@uniontech.com>
>> ---
>>   fs/iomap/buffered-io.c | 2 +-
>>   1 file changed, 1 insertion(+), 1 deletion(-)
>>
>> 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++) {
> Hmmm... 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 that I can think of) 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.
>
> Reviewed-by: "Darrick J. Wong" <djwong@kernel.org>
>
> --D

Thank you for your review. The explanation is very clear. I will revise the

commit message and send the V2 patch.

--

thanks,

Gou Hao

>
>>   			if (ifs_block_is_uptodate(ifs, i)) {
>>   				plen -= (last - i + 1) * block_size;
>>   				last = i - 1;
>> -- 
>> 2.20.1
>>
>>

^ permalink raw reply	[flat|nested] 9+ messages in thread

* [PATCH V2] iomap: skip unnecessary ifs_block_is_uptodate check
  2025-04-08 17:29 [PATCH] iomap: skip unnecessary ifs_block_is_uptodate check Gou Hao
  2025-04-09 15:30 ` Darrick J. Wong
@ 2025-04-10  5:42 ` Gou Hao
  2025-04-10  5:54   ` Christoph Hellwig
  2025-04-10  7:12 ` [PATCH V3] " Gou Hao
  2 siblings, 1 reply; 9+ messages in thread
From: Gou Hao @ 2025-04-10  5:42 UTC (permalink / raw)
  To: gouhao
  Cc: brauner, djwong, gouhaojake, linux-fsdevel, linux-kernel,
	linux-xfs, wangyuli

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(-)

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;
-- 
2.20.1


^ permalink raw reply related	[flat|nested] 9+ messages in thread

* Re: [PATCH V2] iomap: skip unnecessary ifs_block_is_uptodate check
  2025-04-10  5:42 ` [PATCH V2] " Gou Hao
@ 2025-04-10  5:54   ` Christoph Hellwig
  2025-04-10  6:25     ` Gou Hao
  0 siblings, 1 reply; 9+ messages in thread
From: Christoph Hellwig @ 2025-04-10  5:54 UTC (permalink / raw)
  To: Gou Hao
  Cc: brauner, djwong, gouhaojake, linux-fsdevel, linux-kernel,
	linux-xfs, wangyuli

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) {

?


^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: [PATCH V2] iomap: skip unnecessary ifs_block_is_uptodate check
  2025-04-10  5:54   ` Christoph Hellwig
@ 2025-04-10  6:25     ` Gou Hao
  0 siblings, 0 replies; 9+ messages in thread
From: Gou Hao @ 2025-04-10  6:25 UTC (permalink / raw)
  To: Christoph Hellwig
  Cc: brauner, djwong, gouhaojake, linux-fsdevel, linux-kernel,
	linux-xfs, wangyuli


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.
>


^ permalink raw reply	[flat|nested] 9+ messages in thread

* [PATCH V3] iomap: skip unnecessary ifs_block_is_uptodate check
  2025-04-08 17:29 [PATCH] iomap: skip unnecessary ifs_block_is_uptodate check Gou Hao
  2025-04-09 15:30 ` Darrick J. Wong
  2025-04-10  5:42 ` [PATCH V2] " Gou Hao
@ 2025-04-10  7:12 ` Gou Hao
  2025-04-10  7:17   ` Christoph Hellwig
  2025-04-11 14:02   ` Christian Brauner
  2 siblings, 2 replies; 9+ messages in thread
From: Gou Hao @ 2025-04-10  7:12 UTC (permalink / raw)
  To: gouhao, brauner, djwong, hch
  Cc: gouhaojake, linux-fsdevel, linux-kernel, linux-xfs, wangyuli

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.

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

Changes:
V3:
- optimize commit log
- change 'for' to 'while'

V2:
- optimize commit log

diff --git a/fs/iomap/buffered-io.c b/fs/iomap/buffered-io.c
index 31553372b33a..5b08bd417b28 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++) {
+		while (++i <= last) {
 			if (ifs_block_is_uptodate(ifs, i)) {
 				plen -= (last - i + 1) * block_size;
 				last = i - 1;
-- 
2.20.1


^ permalink raw reply related	[flat|nested] 9+ messages in thread

* Re: [PATCH V3] iomap: skip unnecessary ifs_block_is_uptodate check
  2025-04-10  7:12 ` [PATCH V3] " Gou Hao
@ 2025-04-10  7:17   ` Christoph Hellwig
  2025-04-11 14:02   ` Christian Brauner
  1 sibling, 0 replies; 9+ messages in thread
From: Christoph Hellwig @ 2025-04-10  7:17 UTC (permalink / raw)
  To: Gou Hao
  Cc: brauner, djwong, hch, gouhaojake, linux-fsdevel, linux-kernel,
	linux-xfs, wangyuli

Looks good:

Reviewed-by: Christoph Hellwig <hch@lst.de>


^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: [PATCH V3] iomap: skip unnecessary ifs_block_is_uptodate check
  2025-04-10  7:12 ` [PATCH V3] " Gou Hao
  2025-04-10  7:17   ` Christoph Hellwig
@ 2025-04-11 14:02   ` Christian Brauner
  1 sibling, 0 replies; 9+ messages in thread
From: Christian Brauner @ 2025-04-11 14:02 UTC (permalink / raw)
  To: djwong, hch, Gou Hao
  Cc: Christian Brauner, gouhaojake, linux-fsdevel, linux-kernel,
	linux-xfs, wangyuli

On Thu, 10 Apr 2025 15:12:36 +0800, Gou Hao wrote:
> 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.
> 
> [...]

Applied to the vfs.fixes branch of the vfs/vfs.git tree.
Patches in the vfs.fixes branch should appear in linux-next soon.

Please report any outstanding bugs that were missed during review in a
new review to the original patch series allowing us to drop it.

It's encouraged to provide Acked-bys and Reviewed-bys even though the
patch has now been applied. If possible patch trailers will be updated.

Note that commit hashes shown below are subject to change due to rebase,
trailer updates or similar. If in doubt, please check the listed branch.

tree:   https://git.kernel.org/pub/scm/linux/kernel/git/vfs/vfs.git
branch: vfs.fixes

[1/1] iomap: skip unnecessary ifs_block_is_uptodate check
      https://git.kernel.org/vfs/vfs/c/8e3c15ee0d29

^ permalink raw reply	[flat|nested] 9+ messages in thread

end of thread, other threads:[~2025-04-11 14:02 UTC | newest]

Thread overview: 9+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-04-08 17:29 [PATCH] iomap: skip unnecessary ifs_block_is_uptodate check Gou Hao
2025-04-09 15:30 ` Darrick J. Wong
2025-04-10  5:37   ` Gou Hao
2025-04-10  5:42 ` [PATCH V2] " Gou Hao
2025-04-10  5:54   ` Christoph Hellwig
2025-04-10  6:25     ` Gou Hao
2025-04-10  7:12 ` [PATCH V3] " Gou Hao
2025-04-10  7:17   ` Christoph Hellwig
2025-04-11 14:02   ` Christian Brauner

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).