Skip to content

Commit 2580d55

Browse files
Matthew Wilcox (Oracle)akpm00
authored andcommitted
mm: use folio_xor_flags_has_waiters() in folio_end_writeback()
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]>
1 parent 7d0795d commit 2580d55

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
@@ -1175,13 +1175,6 @@ static void folio_wake_bit(struct folio *folio, int bit_nr)
11751175
spin_unlock_irqrestore(&q->lock, flags);
11761176
}
11771177

1178-
static void folio_wake(struct folio *folio, int bit)
1179-
{
1180-
if (!folio_test_waiters(folio))
1181-
return;
1182-
folio_wake_bit(folio, bit);
1183-
}
1184-
11851178
/*
11861179
* A choice of three behaviors for folio_wait_bit_common():
11871180
*/
@@ -1618,13 +1611,11 @@ void folio_end_writeback(struct folio *folio)
16181611
* Writeback does not hold a folio reference of its own, relying
16191612
* on truncation to wait for the clearing of PG_writeback.
16201613
* But here we must make sure that the folio is not freed and
1621-
* reused before the folio_wake().
1614+
* reused before the folio_wake_bit().
16221615
*/
16231616
folio_get(folio);
1624-
__folio_end_writeback(folio);
1625-
1626-
smp_mb__after_atomic();
1627-
folio_wake(folio, PG_writeback);
1617+
if (__folio_end_writeback(folio))
1618+
folio_wake_bit(folio, PG_writeback);
16281619
acct_reclaim_writeback(folio);
16291620
folio_put(folio);
16301621
}

mm/internal.h

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

106106
vm_fault_t do_swap_page(struct vm_fault *vmf);
107107
void folio_rotate_reclaimable(struct folio *folio);
108-
void __folio_end_writeback(struct folio *folio);
108+
bool __folio_end_writeback(struct folio *folio);
109109
void deactivate_file_folio(struct folio *folio);
110110
void folio_activate(struct folio *folio);
111111

mm/page-writeback.c

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

2943-
void __folio_end_writeback(struct folio *folio)
2943+
bool __folio_end_writeback(struct folio *folio)
29442944
{
29452945
long nr = folio_nr_pages(folio);
29462946
struct address_space *mapping = folio_mapping(folio);
2947+
bool ret;
29472948

29482949
folio_memcg_lock(folio);
29492950
if (mapping && mapping_use_writeback_tags(mapping)) {
@@ -2952,7 +2953,7 @@ void __folio_end_writeback(struct folio *folio)
29522953
unsigned long flags;
29532954

29542955
xa_lock_irqsave(&mapping->i_pages, flags);
2955-
folio_test_clear_writeback(folio);
2956+
ret = folio_xor_flags_has_waiters(folio, 1 << PG_writeback);
29562957
__xa_clear_mark(&mapping->i_pages, folio_index(folio),
29572958
PAGECACHE_TAG_WRITEBACK);
29582959
if (bdi->capabilities & BDI_CAP_WRITEBACK_ACCT) {
@@ -2970,13 +2971,15 @@ void __folio_end_writeback(struct folio *folio)
29702971

29712972
xa_unlock_irqrestore(&mapping->i_pages, flags);
29722973
} else {
2973-
folio_test_clear_writeback(folio);
2974+
ret = folio_xor_flags_has_waiters(folio, 1 << PG_writeback);
29742975
}
29752976

29762977
lruvec_stat_mod_folio(folio, NR_WRITEBACK, -nr);
29772978
zone_stat_mod_folio(folio, NR_ZONE_WRITE_PENDING, -nr);
29782979
node_stat_mod_folio(folio, NR_WRITTEN, nr);
29792980
folio_memcg_unlock(folio);
2981+
2982+
return ret;
29802983
}
29812984

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

0 commit comments

Comments
 (0)