aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authoryangge <[email protected]>2024-08-13 17:52:23 +0800
committerAndrew Morton <[email protected]>2024-09-01 20:26:10 -0700
commit67b9a353e171c3969223e53308feb15b722bb64a (patch)
treed923293b7295602f02a91d9d478454173f85ca7c
parentb6273b55d88539c6a7127a697c61d3f89c5831fe (diff)
mm/swap: take folio refcount after testing the LRU flag
Whoever passes a folio to __folio_batch_add_and_move() must hold a reference, otherwise something else would already be messed up. If the folio is referenced, it will not be freed elsewhere, so we can safely clear the folio's lru flag. As discussed with David in [1], we should take the reference after testing the LRU flag, not before. Link: https://lore.kernel.org/lkml/[email protected]/ [1] Link: https://lkml.kernel.org/r/[email protected] Signed-off-by: yangge <[email protected]> Acked-by: David Hildenbrand <[email protected]> Cc: Baolin Wang <[email protected]> Cc: Yu Zhao <[email protected]> Signed-off-by: Andrew Morton <[email protected]>
-rw-r--r--mm/swap.c8
1 files changed, 3 insertions, 5 deletions
diff --git a/mm/swap.c b/mm/swap.c
index 67a246772811..6b838986d294 100644
--- a/mm/swap.c
+++ b/mm/swap.c
@@ -226,12 +226,10 @@ static void __folio_batch_add_and_move(struct folio_batch __percpu *fbatch,
{
unsigned long flags;
- folio_get(folio);
-
- if (on_lru && !folio_test_clear_lru(folio)) {
- folio_put(folio);
+ if (on_lru && !folio_test_clear_lru(folio))
return;
- }
+
+ folio_get(folio);
if (disable_irq)
local_lock_irqsave(&cpu_fbatches.lock_irq, flags);