Skip to content

Commit 279d5fc

Browse files
Matthew Wilcox (Oracle)akpm00
authored andcommitted
iomap: hold state_lock over call to ifs_set_range_uptodate()
Patch series "Add folio_end_read", v2. The core of this patchset is the new folio_end_read() call which filesystems can use when finishing a page cache read instead of separate calls to mark the folio uptodate and unlock it. As an illustration of its use, I converted ext4, iomap & mpage; more can be converted. I think that's useful by itself, but the interesting optimisation is that we can implement that with a single XOR instruction that sets the uptodate bit, clears the lock bit, tests the waiter bit and provides a write memory barrier. That removes one memory barrier and one atomic instruction from each page read, which seems worth doing. That's in patch 15. The last two patches could be a separate series, but basically we can do the same thing with the writeback flag that we do with the unlock flag; clear it and test the waiters bit at the same time. This patch (of 17): This is really preparation for the next patch, but it lets us call folio_mark_uptodate() in just one place instead of two. Link: https://lkml.kernel.org/r/[email protected] Link: https://lkml.kernel.org/r/[email protected] Signed-off-by: Matthew Wilcox (Oracle) <[email protected]> Cc: Matthew Wilcox (Oracle) <[email protected]> Cc: Nicholas Piggin <[email protected]> Cc: "Theodore Ts'o" <[email protected]> Cc: Andreas Dilger <[email protected]> Cc: Richard Henderson <[email protected]> Cc: Ivan Kokshaysky <[email protected]> Cc: Matt Turner <[email protected]> Cc: Thomas Bogendoerfer <[email protected]> Cc: Michael Ellerman <[email protected]> Cc: Christophe Leroy <[email protected]> Cc: Paul Walmsley <[email protected]> Cc: Palmer Dabbelt <[email protected]> Cc: Albert Ou <[email protected]> Cc: Heiko Carstens <[email protected]> Cc: Vasily Gorbik <[email protected]> Cc: Alexander Gordeev <[email protected]> Cc: Christian Borntraeger <[email protected]> Cc: Sven Schnelle <[email protected]> Cc: Geert Uytterhoeven <[email protected]> Signed-off-by: Andrew Morton <[email protected]>
1 parent 116d573 commit 279d5fc

File tree

1 file changed

+11
-9
lines changed

1 file changed

+11
-9
lines changed

fs/iomap/buffered-io.c

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -57,30 +57,32 @@ static inline bool ifs_block_is_uptodate(struct iomap_folio_state *ifs,
5757
return test_bit(block, ifs->state);
5858
}
5959

60-
static void ifs_set_range_uptodate(struct folio *folio,
60+
static bool ifs_set_range_uptodate(struct folio *folio,
6161
struct iomap_folio_state *ifs, size_t off, size_t len)
6262
{
6363
struct inode *inode = folio->mapping->host;
6464
unsigned int first_blk = off >> inode->i_blkbits;
6565
unsigned int last_blk = (off + len - 1) >> inode->i_blkbits;
6666
unsigned int nr_blks = last_blk - first_blk + 1;
67-
unsigned long flags;
6867

69-
spin_lock_irqsave(&ifs->state_lock, flags);
7068
bitmap_set(ifs->state, first_blk, nr_blks);
71-
if (ifs_is_fully_uptodate(folio, ifs))
72-
folio_mark_uptodate(folio);
73-
spin_unlock_irqrestore(&ifs->state_lock, flags);
69+
return ifs_is_fully_uptodate(folio, ifs);
7470
}
7571

7672
static void iomap_set_range_uptodate(struct folio *folio, size_t off,
7773
size_t len)
7874
{
7975
struct iomap_folio_state *ifs = folio->private;
76+
unsigned long flags;
77+
bool uptodate = true;
8078

81-
if (ifs)
82-
ifs_set_range_uptodate(folio, ifs, off, len);
83-
else
79+
if (ifs) {
80+
spin_lock_irqsave(&ifs->state_lock, flags);
81+
uptodate = ifs_set_range_uptodate(folio, ifs, off, len);
82+
spin_unlock_irqrestore(&ifs->state_lock, flags);
83+
}
84+
85+
if (uptodate)
8486
folio_mark_uptodate(folio);
8587
}
8688

0 commit comments

Comments
 (0)