Skip to content

Commit b426260

Browse files
Matthew Wilcox (Oracle)opsiff
authored andcommitted
mm: use folio_xor_flags_has_waiters() in folio_end_writeback()
mainline inclusion from mainline-v6.7-rc1 category: performance Match how folio_unlock() works by combining the test for PG_waiters with the clearing of PG_writeback. This should have a small performance win, and removes the last user of folio_wake(). Link: https://lkml.kernel.org/r/[email protected] Signed-off-by: Matthew Wilcox (Oracle) <[email protected]> Cc: Albert Ou <[email protected]> Cc: Alexander Gordeev <[email protected]> Cc: Andreas Dilger <[email protected]> Cc: Christian Borntraeger <[email protected]> Cc: Christophe Leroy <[email protected]> Cc: Geert Uytterhoeven <[email protected]> Cc: Heiko Carstens <[email protected]> Cc: Ivan Kokshaysky <[email protected]> Cc: Matt Turner <[email protected]> Cc: Michael Ellerman <[email protected]> Cc: Nicholas Piggin <[email protected]> Cc: Palmer Dabbelt <[email protected]> Cc: Paul Walmsley <[email protected]> Cc: Richard Henderson <[email protected]> Cc: Sven Schnelle <[email protected]> Cc: "Theodore Ts'o" <[email protected]> Cc: Thomas Bogendoerfer <[email protected]> Cc: Vasily Gorbik <[email protected]> Signed-off-by: Andrew Morton <[email protected]> (cherry picked from commit 2580d55) Signed-off-by: Wentao Guan <[email protected]>
1 parent b30a671 commit b426260

File tree

3 files changed

+10
-16
lines changed

3 files changed

+10
-16
lines changed

mm/filemap.c

Lines changed: 3 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1186,13 +1186,6 @@ static void folio_wake_bit(struct folio *folio, int bit_nr)
11861186
spin_unlock_irqrestore(&q->lock, flags);
11871187
}
11881188

1189-
static void folio_wake(struct folio *folio, int bit)
1190-
{
1191-
if (!folio_test_waiters(folio))
1192-
return;
1193-
folio_wake_bit(folio, bit);
1194-
}
1195-
11961189
/*
11971190
* A choice of three behaviors for folio_wait_bit_common():
11981191
*/
@@ -1629,13 +1622,11 @@ void folio_end_writeback(struct folio *folio)
16291622
* Writeback does not hold a folio reference of its own, relying
16301623
* on truncation to wait for the clearing of PG_writeback.
16311624
* But here we must make sure that the folio is not freed and
1632-
* reused before the folio_wake().
1625+
* reused before the folio_wake_bit().
16331626
*/
16341627
folio_get(folio);
1635-
__folio_end_writeback(folio);
1636-
1637-
smp_mb__after_atomic();
1638-
folio_wake(folio, PG_writeback);
1628+
if (__folio_end_writeback(folio))
1629+
folio_wake_bit(folio, PG_writeback);
16391630
acct_reclaim_writeback(folio);
16401631
folio_put(folio);
16411632
}

mm/internal.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -150,7 +150,7 @@ static inline void wake_throttle_isolated(pg_data_t *pgdat)
150150

151151
vm_fault_t do_swap_page(struct vm_fault *vmf);
152152
void folio_rotate_reclaimable(struct folio *folio);
153-
void __folio_end_writeback(struct folio *folio);
153+
bool __folio_end_writeback(struct folio *folio);
154154
void deactivate_file_folio(struct folio *folio);
155155
void folio_activate(struct folio *folio);
156156

mm/page-writeback.c

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2995,10 +2995,11 @@ static void wb_inode_writeback_end(struct bdi_writeback *wb)
29952995
spin_unlock_irqrestore(&wb->work_lock, flags);
29962996
}
29972997

2998-
void __folio_end_writeback(struct folio *folio)
2998+
bool __folio_end_writeback(struct folio *folio)
29992999
{
30003000
long nr = folio_nr_pages(folio);
30013001
struct address_space *mapping = folio_mapping(folio);
3002+
bool ret;
30023003

30033004
folio_memcg_lock(folio);
30043005
if (mapping && mapping_use_writeback_tags(mapping)) {
@@ -3007,7 +3008,7 @@ void __folio_end_writeback(struct folio *folio)
30073008
unsigned long flags;
30083009

30093010
xa_lock_irqsave(&mapping->i_pages, flags);
3010-
folio_test_clear_writeback(folio);
3011+
ret = folio_xor_flags_has_waiters(folio, 1 << PG_writeback);
30113012
__xa_clear_mark(&mapping->i_pages, folio_index(folio),
30123013
PAGECACHE_TAG_WRITEBACK);
30133014
if (bdi->capabilities & BDI_CAP_WRITEBACK_ACCT) {
@@ -3025,13 +3026,15 @@ void __folio_end_writeback(struct folio *folio)
30253026

30263027
xa_unlock_irqrestore(&mapping->i_pages, flags);
30273028
} else {
3028-
folio_test_clear_writeback(folio);
3029+
ret = folio_xor_flags_has_waiters(folio, 1 << PG_writeback);
30293030
}
30303031

30313032
lruvec_stat_mod_folio(folio, NR_WRITEBACK, -nr);
30323033
zone_stat_mod_folio(folio, NR_ZONE_WRITE_PENDING, -nr);
30333034
node_stat_mod_folio(folio, NR_WRITTEN, nr);
30343035
folio_memcg_unlock(folio);
3036+
3037+
return ret;
30353038
}
30363039

30373040
bool __folio_start_writeback(struct folio *folio, bool keep_write)

0 commit comments

Comments
 (0)