From: yangge1116@126.com
To: akpm@linux-foundation.org
Cc: linux-mm@kvack.org, linux-kernel@vger.kernel.org,
21cnbao@gmail.com, david@redhat.com,
baolin.wang@linux.alibaba.com, liuzixing@hygon.cn,
yangge <yangge1116@126.com>
Subject: [PATCH V2] mm/swap: take folio refcount after testing the LRU flag
Date: Mon, 12 Aug 2024 19:21:58 +0800 [thread overview]
Message-ID: <1723461718-5503-1-git-send-email-yangge1116@126.com> (raw)
From: yangge <yangge1116@126.com>
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/d41865b4-d6fa-49ba-890a-921eefad27dd@redhat.com/ [1]
Signed-off-by: yangge <yangge1116@126.com>
Acked-by: David Hildenbrand <david@redhat.com>
---
mm/swap.c | 9 ++++-----
1 file changed, 4 insertions(+), 5 deletions(-)
V2:
Add sanity check suggested by David
diff --git a/mm/swap.c b/mm/swap.c
index 67a2467..c048659 100644
--- a/mm/swap.c
+++ b/mm/swap.c
@@ -226,12 +226,11 @@ 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;
- }
+
+ VM_WARN_ON_ONCE(!folio_ref_count(folio));
+ folio_get(folio);
if (disable_irq)
local_lock_irqsave(&cpu_fbatches.lock_irq, flags);
--
2.7.4
next reply other threads:[~2024-08-12 11:22 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-08-12 11:21 yangge1116 [this message]
2024-08-12 19:06 ` Yu Zhao
2024-08-12 20:12 ` David Hildenbrand
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1723461718-5503-1-git-send-email-yangge1116@126.com \
--to=yangge1116@126.com \
--cc=21cnbao@gmail.com \
--cc=akpm@linux-foundation.org \
--cc=baolin.wang@linux.alibaba.com \
--cc=david@redhat.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-mm@kvack.org \
--cc=liuzixing@hygon.cn \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox