]> git.ipfire.org Git - thirdparty/linux.git/commitdiff
iomap: avoid unnecessary ifs_set_range_uptodate() with locks
authorJinliang Zheng <alexjlzheng@tencent.com>
Fri, 11 Jul 2025 08:12:07 +0000 (16:12 +0800)
committerChristian Brauner <brauner@kernel.org>
Fri, 11 Jul 2025 09:42:44 +0000 (11:42 +0200)
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>
Link: https://lore.kernel.org/20250711081207.1782667-1-alexjlzheng@tencent.com
Reviewed-by: Darrick J. Wong <djwong@kernel.org>
Reviewed-by: Christoph Hellwig <hch@infradead.org>
Reviewed-by: Christoph Hellwig <hch@lst.de>
Signed-off-by: Christian Brauner <brauner@kernel.org>
fs/iomap/buffered-io.c

index 3729391a18f32bc9830baa7273e84028bb42b099..fb4519158f3a79031639892e8aaf3dc47c83b13e 100644 (file)
@@ -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);