From: Lance Yang <lance.yang@linux.dev>
To: akpm@linux-foundation.org
Cc: david@redhat.com, Liam.Howlett@oracle.com, baohua@kernel.org,
baolin.wang@linux.alibaba.com, dev.jain@arm.com,
linux-kernel@vger.kernel.org, linux-mm@kvack.org,
lorenzo.stoakes@oracle.com, npache@redhat.com,
ryan.roberts@arm.com, usamaarif642@gmail.com, ziy@nvidia.com,
Lance Yang <lance.yang@linux.dev>
Subject: [PATCH 1/1] mm: avoid processing mlocked THPs in deferred split shrinker
Date: Mon, 8 Sep 2025 12:07:13 +0800 [thread overview]
Message-ID: <20250908040713.42960-1-lance.yang@linux.dev> (raw)
From: Lance Yang <lance.yang@linux.dev>
When a new THP is faulted in or collapsed, it is unconditionally added to
the deferred split queue. If this THP is subsequently mlocked, it remains
on the queue but is removed from the LRU and marked unevictable.
During memory reclaim, deferred_split_scan() will still pick up this large
folio. Because it's not partially mapped, it will proceed to call
thp_underused() and then attempt to split_folio() to free all zero-filled
subpages.
This is a pointless waste of CPU cycles. The folio is mlocked and
unevictable, so any attempt to reclaim memory from it via splitting is
doomed to fail.
So, let's add an early folio_test_mlocked() check to skip this case.
Signed-off-by: Lance Yang <lance.yang@linux.dev>
---
mm/huge_memory.c | 3 +++
1 file changed, 3 insertions(+)
diff --git a/mm/huge_memory.c b/mm/huge_memory.c
index 77f0c3417973..d2e84015d6b4 100644
--- a/mm/huge_memory.c
+++ b/mm/huge_memory.c
@@ -4183,6 +4183,9 @@ static unsigned long deferred_split_scan(struct shrinker *shrink,
bool underused = false;
if (!folio_test_partially_mapped(folio)) {
+ /* An mlocked folio is not a candidate for the shrinker. */
+ if (folio_test_mlocked(folio))
+ goto next;
underused = thp_underused(folio);
if (!underused)
goto next;
--
2.49.0
next reply other threads:[~2025-09-08 4:07 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-09-08 4:07 Lance Yang [this message]
2025-09-08 7:38 ` David Hildenbrand
2025-09-08 8:13 ` Lance Yang
2025-09-08 8:33 ` 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=20250908040713.42960-1-lance.yang@linux.dev \
--to=lance.yang@linux.dev \
--cc=Liam.Howlett@oracle.com \
--cc=akpm@linux-foundation.org \
--cc=baohua@kernel.org \
--cc=baolin.wang@linux.alibaba.com \
--cc=david@redhat.com \
--cc=dev.jain@arm.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-mm@kvack.org \
--cc=lorenzo.stoakes@oracle.com \
--cc=npache@redhat.com \
--cc=ryan.roberts@arm.com \
--cc=usamaarif642@gmail.com \
--cc=ziy@nvidia.com \
/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