* [PATCH v2] iomap: avoid unnecessary ifs_set_range_uptodate() with locks
@ 2025-07-11 8:12 alexjlzheng
2025-07-11 8:13 ` Christoph Hellwig
0 siblings, 1 reply; 2+ messages in thread
From: alexjlzheng @ 2025-07-11 8:12 UTC (permalink / raw)
To: brauner, djwong, hch, willy
Cc: linux-xfs, linux-fsdevel, linux-kernel, Jinliang Zheng
From: Jinliang Zheng <alexjlzheng@tencent.com>
In the buffer write path, iomap_set_range_uptodate() is called every
time iomap_end_write() is called. But if folio_test_uptodate() holds, we
know that all blocks in this folio are already in the uptodate state, so
there is no need to go deep into the critical section of state_lock to
execute bitmap_set().
This is because the folios always creep towards ifs_is_fully_uptodate()
state and once they've gotten there folio_mark_uptodate() is called, which
means the folio is uptodate.
Then once a folio is uptodate, there is no route back to !uptodate without
going through the removal of the folio from the page cache. Therefore, it's
fine to use folio_test_uptodate() to short-circuit unnecessary code paths.
Although state_lock may not have significant lock contention due to
folio lock, this patch at least reduces the number of instructions,
especially the expensive lock-prefixed instructions.
Signed-off-by: Jinliang Zheng <alexjlzheng@tencent.com>
Reviewed-by: "Darrick J. Wong" <djwong@kernel.org>
Reviewed-by: Christoph Hellwig <hch@infradead.org>
---
Changelog:
V2: Update commit message
V1: https://lore.kernel.org/linux-xfs/20250701144847.12752-1-alexjlzheng@tencent.com/
---
fs/iomap/buffered-io.c | 3 +++
1 file changed, 3 insertions(+)
diff --git a/fs/iomap/buffered-io.c b/fs/iomap/buffered-io.c
index 3729391a18f3..fb4519158f3a 100644
--- a/fs/iomap/buffered-io.c
+++ b/fs/iomap/buffered-io.c
@@ -71,6 +71,9 @@ static void iomap_set_range_uptodate(struct folio *folio, size_t off,
unsigned long flags;
bool uptodate = true;
+ if (folio_test_uptodate(folio))
+ return;
+
if (ifs) {
spin_lock_irqsave(&ifs->state_lock, flags);
uptodate = ifs_set_range_uptodate(folio, ifs, off, len);
--
2.49.0
^ permalink raw reply related [flat|nested] 2+ messages in thread
* Re: [PATCH v2] iomap: avoid unnecessary ifs_set_range_uptodate() with locks
2025-07-11 8:12 [PATCH v2] iomap: avoid unnecessary ifs_set_range_uptodate() with locks alexjlzheng
@ 2025-07-11 8:13 ` Christoph Hellwig
0 siblings, 0 replies; 2+ messages in thread
From: Christoph Hellwig @ 2025-07-11 8:13 UTC (permalink / raw)
To: alexjlzheng
Cc: brauner, djwong, hch, willy, linux-xfs, linux-fsdevel,
linux-kernel, Jinliang Zheng
Looks good:
Reviewed-by: Christoph Hellwig <hch@lst.de>
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2025-07-11 8:13 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-07-11 8:12 [PATCH v2] iomap: avoid unnecessary ifs_set_range_uptodate() with locks alexjlzheng
2025-07-11 8:13 ` Christoph Hellwig
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).