iomap: skip unnecessary ifs_block_is_uptodate check
Subsystems (2)
PATCH 1/1 iomap: skip unnecessary ifs_block_is_uptodate check
After the first 'for' loop, the first call toifs_block_is_uptodate always evaluates to 0.
--- fs/iomap/buffered-io.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
fs/iomap/buffered-io.c +1 -1
@@ -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 ;
Signature · 1 line
2.20.1
Quoted 13 lines · Gou Hao
After the first 'for' loop, the first call to
ifs_block_is_uptodatealways evaluates to 0.Signed-off-by Gou Hao <[email protected]>--- fs/iomap/buffered-io.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)fs/iomap/buffered-io.c +0
-0
fs/iomap/buffered-io.c static void iomap_adjust_read_range(struct inode *inode, struct folio *folio, · line 262
Quoted 5 lines
fs/iomap/buffered-io.c +1
-1@@ -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.
--D
Quoted 7 lines
fs/iomap/buffered-io.c +0
-0if (ifs_block_is_uptodate (ifs, i)) { plen -= (last - i +1 ) * block_size; last = i -1 ;Signature · 1 line
2.20.1
Quoted 25 lines · Darrick J. Wong
Quoted 13 lines · Gou Hao
After the first 'for' loop, the first call to
ifs_block_is_uptodatealways evaluates to 0.Signed-off-by Gou Hao <[email protected]>--- fs/iomap/buffered-io.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)fs/iomap/buffered-io.c +0
-0fs/iomap/buffered-io.c static void iomap_adjust_read_range(struct inode *inode, struct folio *folio, · line 262
Quoted 5 lines
fs/iomap/buffered-io.c +1
-1@@ -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.
Quoted 3 lines
Reviewed-by "Darrick J. Wong" <[email protected]>--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
Quoted 8 lines
Quoted 8 lines
fs/iomap/buffered-io.c +0
-0if (ifs_block_is_uptodate (ifs, i)) { plen -= (last - i +1 ) * block_size; last = i -1 ;Signature · 1 line
2.20.1
PATCH v2 1/1 iomap: skip unnecessary ifs_block_is_uptodate check
In reply to Gou Haoprior 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.
--- fs/iomap/buffered-io.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
fs/iomap/buffered-io.c +1 -1
@@ -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 ;
Signature · 1 line
2.20.1
Quoted 5 lines · Gou Hao
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.
fs/iomap/buffered-io.c static void iomap_adjust_read_range(struct inode *inode, struct folio *folio, · line 262
Quoted 3 lines
fs/iomap/buffered-io.c +1
-1/* 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) {?
Quoted 9 lines · Christoph Hellwig
Quoted 5 lines · Gou Hao
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:
Quoted 6 lines
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.
Quoted 11 lines
fs/iomap/buffered-io.c static void iomap_adjust_read_range(struct inode *inode, struct folio *folio, · line 262
Quoted 3 lines
/* truncate len if we find any trailing uptodate block(s) */
fs/iomap/buffered-io.c +1
-1-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.
Quoted 1 line
PATCH v3 1/1 iomap: skip unnecessary ifs_block_is_uptodate check
In reply to Gou HaoIn 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.
--- 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
fs/iomap/buffered-io.c +1 -1
@@ -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 ;
Signature · 1 line
2.20.1
Looks good:
Quoted 8 lines · Gou Hao
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