Skip to content

Commit a1d98e4

Browse files
axboebrauner
authored andcommitted
mm/filemap: unify dropbehind flag testing and clearing
The read and write side does this a bit differently, unify it such that the _{read,write} helpers check the bit before locking, and the generic handler is in charge of clearing the bit and invalidating, once under the folio lock. Signed-off-by: Jens Axboe <[email protected]> Link: https://lore.kernel.org/[email protected] Signed-off-by: Christian Brauner <[email protected]>
1 parent 1da7a06 commit a1d98e4

File tree

1 file changed

+11
-10
lines changed

1 file changed

+11
-10
lines changed

mm/filemap.c

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1595,7 +1595,11 @@ static void filemap_end_dropbehind(struct folio *folio)
15951595

15961596
VM_BUG_ON_FOLIO(!folio_test_locked(folio), folio);
15971597

1598-
if (mapping && !folio_test_writeback(folio) && !folio_test_dirty(folio))
1598+
if (folio_test_writeback(folio) || folio_test_dirty(folio))
1599+
return;
1600+
if (!folio_test_clear_dropbehind(folio))
1601+
return;
1602+
if (mapping)
15991603
folio_unmap_invalidate(mapping, folio, 0);
16001604
}
16011605

@@ -1606,6 +1610,9 @@ static void filemap_end_dropbehind(struct folio *folio)
16061610
*/
16071611
static void filemap_end_dropbehind_write(struct folio *folio)
16081612
{
1613+
if (!folio_test_dropbehind(folio))
1614+
return;
1615+
16091616
/*
16101617
* Hitting !in_task() should not happen off RWF_DONTCACHE writeback,
16111618
* but can happen if normal writeback just happens to find dirty folios
@@ -1629,8 +1636,6 @@ static void filemap_end_dropbehind_write(struct folio *folio)
16291636
*/
16301637
void folio_end_writeback(struct folio *folio)
16311638
{
1632-
bool folio_dropbehind = false;
1633-
16341639
VM_BUG_ON_FOLIO(!folio_test_writeback(folio), folio);
16351640

16361641
/*
@@ -1652,14 +1657,11 @@ void folio_end_writeback(struct folio *folio)
16521657
* reused before the folio_wake_bit().
16531658
*/
16541659
folio_get(folio);
1655-
if (!folio_test_dirty(folio))
1656-
folio_dropbehind = folio_test_clear_dropbehind(folio);
16571660
if (__folio_end_writeback(folio))
16581661
folio_wake_bit(folio, PG_writeback);
1659-
acct_reclaim_writeback(folio);
16601662

1661-
if (folio_dropbehind)
1662-
filemap_end_dropbehind_write(folio);
1663+
filemap_end_dropbehind_write(folio);
1664+
acct_reclaim_writeback(folio);
16631665
folio_put(folio);
16641666
}
16651667
EXPORT_SYMBOL(folio_end_writeback);
@@ -2651,8 +2653,7 @@ static void filemap_end_dropbehind_read(struct folio *folio)
26512653
if (folio_test_writeback(folio) || folio_test_dirty(folio))
26522654
return;
26532655
if (folio_trylock(folio)) {
2654-
if (folio_test_clear_dropbehind(folio))
2655-
filemap_end_dropbehind(folio);
2656+
filemap_end_dropbehind(folio);
26562657
folio_unlock(folio);
26572658
}
26582659
}

0 commit comments

Comments
 (0)