linux-mm.kvack.org archive mirror
 help / color / mirror / Atom feed
From: Lance Yang <lance.yang@linux.dev>
To: Zi Yan <ziy@nvidia.com>
Cc: akpm@linux-foundation.org, david@redhat.com,
	lorenzo.stoakes@oracle.com, baolin.wang@linux.alibaba.com,
	Liam.Howlett@oracle.com, npache@redhat.com, ryan.roberts@arm.com,
	dev.jain@arm.com, baohua@kernel.org, ioworker0@gmail.com,
	richard.weiyang@gmail.com, linux-kernel@vger.kernel.org,
	linux-mm@kvack.org
Subject: Re: [PATCH mm-new 2/2] mm/khugepaged: merge PTE scanning logic into a new helper
Date: Sat, 4 Oct 2025 11:06:02 +0800	[thread overview]
Message-ID: <b2d2f634-c587-4639-8191-8d74357fe8fe@linux.dev> (raw)
In-Reply-To: <9DF437D8-E98B-4061-A8C7-521D89070C97@nvidia.com>



On 2025/10/4 01:11, Zi Yan wrote:
> On 2 Oct 2025, at 3:32, Lance Yang wrote:
> 
>> From: Lance Yang <lance.yang@linux.dev>
>>
>> As David suggested, the PTE scanning logic in hpage_collapse_scan_pmd()
>> and __collapse_huge_page_isolate() was almost duplicated.
>>
>> This patch cleans things up by moving all the common PTE checking logic
>> into a new shared helper, thp_collapse_check_pte().
>>
>> Suggested-by: David Hildenbrand <david@redhat.com>
>> Signed-off-by: Lance Yang <lance.yang@linux.dev>
>> ---
>>   mm/khugepaged.c | 167 ++++++++++++++++++++++++++++++------------------
>>   1 file changed, 104 insertions(+), 63 deletions(-)
>>
>> diff --git a/mm/khugepaged.c b/mm/khugepaged.c
>> index 808523f92c7b..2a897cfb1d03 100644
>> --- a/mm/khugepaged.c
>> +++ b/mm/khugepaged.c
>> @@ -61,6 +61,12 @@ enum scan_result {
>>   	SCAN_PAGE_FILLED,
>>   };
>>
>> +enum pte_check_result {
>> +	PTE_CHECK_SUCCEED,
>> +	PTE_CHECK_CONTINUE,
>> +	PTE_CHECK_FAIL,
>> +};
>> +
>>   #define CREATE_TRACE_POINTS
>>   #include <trace/events/huge_memory.h>
>>
>> @@ -533,6 +539,87 @@ static void release_pte_pages(pte_t *pte, pte_t *_pte,
>>   	}
>>   }
>>
>> +/*
>> + * thp_collapse_check_pte - Check if a PTE is suitable for THP collapse
>> + * @pte:           PTE to check
>> + * @vma:           VMA the PTE belongs to
>> + * @cc:            Collapse control settings
>> + * @scan_swap_pte: Allow scanning of swap PTEs if true
>> + * @none_or_zero:  Counter for none/zero PTEs (must be non-NULL)
>> + * @unmapped:      Counter for swap PTEs (must be non-NULL if scan_swap_pte
>> + *                 is true)
>> + * @scan_result:   Used to return the failure reason (SCAN_*) on a
>> + *                 PTE_CHECK_FAIL return. Must be non-NULL
>> + *
>> + * Returns:
>> + *   PTE_CHECK_SUCCEED  - Valid PTE, proceed with collapse
>> + *   PTE_CHECK_CONTINUE - Skip this none/zero PTE but continue scanning
>> + *   PTE_CHECK_FAIL     - Abort collapse scan
>> + */
>> +static inline int thp_collapse_check_pte(pte_t pte, struct vm_area_struct *vma,
>> +		struct collapse_control *cc, bool scan_swap_pte,
>> +		int *none_or_zero, int *unmapped, int *scan_result)
>> +{
>> +	VM_BUG_ON(!none_or_zero || !scan_result);
>> +	VM_BUG_ON(scan_swap_pte && !unmapped);
> 
> Please use VM_WARN_ONCE_ON and just return. Or put all stats in a struct,
> pass and check the struct pointer instead.

Yes, will use VM_WARN_ONCE_ON instead of VM_BUG_ON, and just return 
PTE_CHECK_FAIL.

Thanks,
Lance

> 
> 
> Best Regards,
> Yan, Zi



      reply	other threads:[~2025-10-04  3:06 UTC|newest]

Thread overview: 18+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-10-02  7:32 [PATCH mm-new 0/2] mm/khugepaged: refactor and merge PTE scanning logic Lance Yang
2025-10-02  7:32 ` [PATCH mm-new 1/2] mm/khugepaged: optimize PTE scanning with if-else-if-else-if chain Lance Yang
2025-10-03 13:21   ` Wei Yang
2025-10-03 16:33   ` Dev Jain
2025-10-04  3:08     ` Lance Yang
2025-10-03 17:04   ` Zi Yan
2025-10-02  7:32 ` [PATCH mm-new 2/2] mm/khugepaged: merge PTE scanning logic into a new helper Lance Yang
2025-10-03 17:05   ` Dev Jain
2025-10-04  3:03     ` Lance Yang
2025-10-04  4:42       ` Dev Jain
2025-10-04  5:24         ` Lance Yang
2025-10-04  9:42     ` Wei Yang
2025-10-04 13:11       ` Dev Jain
2025-10-05  2:35         ` Lance Yang
2025-10-05  2:38           ` Zi Yan
2025-10-05  2:44             ` Lance Yang
2025-10-03 17:11   ` Zi Yan
2025-10-04  3:06     ` Lance Yang [this message]

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=b2d2f634-c587-4639-8191-8d74357fe8fe@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=ioworker0@gmail.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-mm@kvack.org \
    --cc=lorenzo.stoakes@oracle.com \
    --cc=npache@redhat.com \
    --cc=richard.weiyang@gmail.com \
    --cc=ryan.roberts@arm.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