From: Baolin Wang <baolin.wang@linux.alibaba.com>
To: Nico Pache <npache@redhat.com>, Ye Liu <ye.liu@linux.dev>
Cc: Andrew Morton <akpm@linux-foundation.org>,
David Hildenbrand <david@kernel.org>,
Lorenzo Stoakes <ljs@kernel.org>, Ye Liu <liuye@kylinos.cn>,
Zi Yan <ziy@nvidia.com>, "Liam R. Howlett" <liam@infradead.org>,
Ryan Roberts <ryan.roberts@arm.com>, Dev Jain <dev.jain@arm.com>,
Barry Song <baohua@kernel.org>, Lance Yang <lance.yang@linux.dev>,
Usama Arif <usama.arif@linux.dev>,
linux-mm@kvack.org, linux-kernel@vger.kernel.org,
joannelkoong@gmail.com
Subject: Re: [PATCH] mm/thp: support mTHP in thp_underused()
Date: Wed, 15 Jul 2026 15:35:30 +0800 [thread overview]
Message-ID: <414075de-e039-4bc5-8316-bef297e72b42@linux.alibaba.com> (raw)
In-Reply-To: <CAA1CXcD0rTPkHHnswHuioyX=HbBetaaZVx1mfFi=a7jdhAgZsA@mail.gmail.com>
CC Joanne.
On 7/15/26 2:42 PM, Nico Pache wrote:
> On Wed, Jul 15, 2026 at 12:28 AM Ye Liu <ye.liu@linux.dev> wrote:
>>
>> From: Ye Liu <liuye@kylinos.cn>
>>
>> When khugepaged_max_ptes_none is configured to a non-default value,
>> scale it for non-PMD-mappable folios to match the logic in
>> collapse_max_ptes_none(), so mTHP can be classified as underused
>> instead of being silently skipped due to unscaled PMD-sized thresholds.
>
> IIUC we don't actually add non-PMD folios to the deferred split list
> and only operate on fully mapped folios, so consequently, we never try
> to shrink them with the underused shrinker.
Right. Joanne sent a similar patch set[1] to split underused mTHP
folios, but David said "needs more proper thought".
[1]
https://lore.kernel.org/all/20260707201735.4113107-1-joannelkoong@gmail.com/
>> Signed-off-by: Ye Liu <liuye@kylinos.cn>
>> ---
>> mm/huge_memory.c | 21 +++++++++++++--------
>> 1 file changed, 13 insertions(+), 8 deletions(-)
>>
>> diff --git a/mm/huge_memory.c b/mm/huge_memory.c
>> index 25612af72dca..c642bec967fa 100644
>> --- a/mm/huge_memory.c
>> +++ b/mm/huge_memory.c
>> @@ -4489,24 +4489,29 @@ static unsigned long deferred_split_count(struct shrinker *shrink,
>> static bool thp_underused(struct folio *folio)
>> {
>> int num_zero_pages = 0, num_filled_pages = 0;
>> + unsigned int max_ptes_none = khugepaged_max_ptes_none;
>> + unsigned int folio_nr = folio_nr_pages(folio);
>> int i;
>>
>> - if (khugepaged_max_ptes_none == HPAGE_PMD_NR - 1)
>> + if (!folio_test_pmd_mappable(folio)) {
>> + if (max_ptes_none == HPAGE_PMD_NR - 1)
>> + max_ptes_none = folio_nr - 1;
>> + else if (max_ptes_none)
>> + return false;
>> + }
>> +
>> + if (max_ptes_none == folio_nr - 1)
>> return false;
>>
>> if (folio_contain_hwpoisoned_page(folio))
>> return false;
>>
>> - for (i = 0; i < folio_nr_pages(folio); i++) {
>> + for (i = 0; i < folio_nr; i++) {
>> if (pages_identical(folio_page(folio, i), ZERO_PAGE(0))) {
>> - if (++num_zero_pages > khugepaged_max_ptes_none)
>> + if (++num_zero_pages > max_ptes_none)
>> return true;
>> } else {
>> - /*
>> - * Another path for early exit once the number
>> - * of non-zero filled pages exceeds threshold.
>> - */
>> - if (++num_filled_pages >= HPAGE_PMD_NR - khugepaged_max_ptes_none)
>> + if (++num_filled_pages >= folio_nr - max_ptes_none)
>> return false;
>> }
>> }
>> --
>> 2.43.0
>>
next prev parent reply other threads:[~2026-07-15 7:35 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-07-15 6:21 [PATCH] mm/thp: support mTHP in thp_underused() Ye Liu
2026-07-15 6:42 ` Nico Pache
2026-07-15 7:35 ` Baolin Wang [this message]
2026-07-15 8:22 ` Ye Liu
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=414075de-e039-4bc5-8316-bef297e72b42@linux.alibaba.com \
--to=baolin.wang@linux.alibaba.com \
--cc=akpm@linux-foundation.org \
--cc=baohua@kernel.org \
--cc=david@kernel.org \
--cc=dev.jain@arm.com \
--cc=joannelkoong@gmail.com \
--cc=lance.yang@linux.dev \
--cc=liam@infradead.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-mm@kvack.org \
--cc=liuye@kylinos.cn \
--cc=ljs@kernel.org \
--cc=npache@redhat.com \
--cc=ryan.roberts@arm.com \
--cc=usama.arif@linux.dev \
--cc=ye.liu@linux.dev \
--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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.