From: Dev Jain <dev.jain@arm.com>
To: David Hildenbrand <david@redhat.com>,
Wei Yang <richard.weiyang@gmail.com>
Cc: akpm@linux-foundation.org, lorenzo.stoakes@oracle.com,
ziy@nvidia.com, baolin.wang@linux.alibaba.com,
Liam.Howlett@oracle.com, npache@redhat.com, ryan.roberts@arm.com,
baohua@kernel.org, lance.yang@linux.dev, linux-mm@kvack.org
Subject: Re: [PATCH] mm/khugepaged: use [pmd|pte]_addr for better reading
Date: Mon, 22 Sep 2025 13:56:54 +0530 [thread overview]
Message-ID: <433cba08-e33f-43ba-bccc-a2b1f2b1cd50@arm.com> (raw)
In-Reply-To: <89afa6d6-0a02-4825-8923-3752397b38dc@redhat.com>
On 22/09/25 1:46 pm, David Hildenbrand wrote:
> On 22.09.25 10:12, Wei Yang wrote:
>> On Sat, Sep 20, 2025 at 06:01:59PM +0530, Dev Jain wrote:
>>>
>>> On 20/09/25 2:32 pm, Wei Yang wrote:
>>>> On Sat, Sep 20, 2025 at 10:21:56AM +0530, Dev Jain wrote:
>>>>> On 20/09/25 6:24 am, Wei Yang wrote:
>>>>>> When collapse a pmd, there are two address in use:
>>>>>>
>>>>>> * address points to the start of pmd
>>>>>> * address points to each individual page
>>>>>>
>>>>>> Current naming is not easy to distinguish these two and error prone.
>>>>>>
>>>>>> Name the first one to pmd_addr and second one to pte_addr.
>>>>>>
>>>>>> Signed-off-by: Wei Yang <richard.weiyang@gmail.com>
>>>>>> Suggested-by: David Hildenbrand <david@redhat.com>
>>>>>> ---
>>>>>> mm/khugepaged.c | 43 ++++++++++++++++++++++---------------------
>>>>>> 1 file changed, 22 insertions(+), 21 deletions(-)
>>>>>>
>>>>>> diff --git a/mm/khugepaged.c b/mm/khugepaged.c
>>>>>> index 4c957ce788d1..6d03072c1a92 100644
>>>>>> --- a/mm/khugepaged.c
>>>>>> +++ b/mm/khugepaged.c
>>>>>> @@ -537,18 +537,19 @@ static void release_pte_pages(pte_t *pte,
>>>>>> pte_t *_pte,
>>>>>> }
>>>>>> static int __collapse_huge_page_isolate(struct vm_area_struct
>>>>>> *vma,
>>>>>> - unsigned long address,
>>>>>> + unsigned long pmd_addr,
>>>>>> pte_t *pte,
>>>>>> struct collapse_control *cc,
>>>>>> struct list_head *compound_pagelist)
>>>>>> {
>>>>>> struct page *page = NULL;
>>>>>> struct folio *folio = NULL;
>>>>>> + unsigned long pte_addr = pmd_addr;
>>>>>> pte_t *_pte;
>>>>>> int none_or_zero = 0, shared = 0, result = SCAN_FAIL,
>>>>>> referenced = 0;
>>>>>> for (_pte = pte; _pte < pte + HPAGE_PMD_NR;
>>>>>> - _pte++, address += PAGE_SIZE) {
>>>>>> + _pte++, pte_addr += PAGE_SIZE) {
>>>>>> pte_t pteval = ptep_get(_pte);
>>>>>> if (pte_none(pteval) || is_zero_pfn(pte_pfn(pteval))) {
>>>>>> ++none_or_zero;
>>>>>> @@ -570,7 +571,7 @@ static int
>>>>>> __collapse_huge_page_isolate(struct vm_area_struct *vma,
>>>>>> result = SCAN_PTE_UFFD_WP;
>>>>>> goto out;
>>>>>> }
>>>>>> - page = vm_normal_page(vma, address, pteval);
>>>>>> + page = vm_normal_page(vma, pte_addr, pteval);
>>>>>> if (unlikely(!page) ||
>>>>>> unlikely(is_zone_device_page(page))) {
>>>>>> result = SCAN_PAGE_NULL;
>>>>>> goto out;
>>>>>> @@ -655,8 +656,8 @@ static int
>>>>>> __collapse_huge_page_isolate(struct vm_area_struct *vma,
>>>>>> */
>>>>>> if (cc->is_khugepaged &&
>>>>>> (pte_young(pteval) || folio_test_young(folio) ||
>>>>>> - folio_test_referenced(folio) ||
>>>>>> mmu_notifier_test_young(vma->vm_mm,
>>>>>> - address)))
>>>>>> + folio_test_referenced(folio) ||
>>>>>> + mmu_notifier_test_young(vma->vm_mm, pte_addr)))
>>>>>> referenced++;
>>>>>> }
>>>>>> @@ -985,21 +986,21 @@ static int check_pmd_still_valid(struct
>>>>>> mm_struct *mm,
>>>>>> */
>>>>>> static int __collapse_huge_page_swapin(struct mm_struct *mm,
>>>>>> struct vm_area_struct *vma,
>>>>>> - unsigned long haddr, pmd_t *pmd,
>>>>>> + unsigned long pmd_addr, pmd_t *pmd,
>>>>>> int referenced)
>>>>> Will this be a problem when mTHP collapse is in? You may have the
>>>>> starting
>>>>> address lying in the PTE table.
>>>>>
>>>>> Personally "haddr" is pretty clear to me - I read it as
>>>>> "huge-aligned addr".
>>>>> I will vote for naming the starting addresses everywhere as
>>>>> "haddr", and use
>>>>> addr as the loop iterator. This is a short name and haddr will
>>>>> imply that it
>>>>> is aligned to the huge order we are collapsing for.
>>>>>
>>>> So your suggestion is
>>>>
>>>> pmd_addr -> haddr
>>>> pte_addr -> address
>>>
>>> pmd_addr -> haddr
>>> pte_addr -> addr
>>>
>>
>> Take another look into the code.
>>
>> The change touch three functions:
>>
>> __collapse_huge_page_isolate()
>> __collapse_huge_page_swapin()
>> hpage_collapse_scan_pmd()
>>
>> Use pmd_addr/pte_addr look reasonable for hpage_collapse_scan_pmd().
>> And haddr/addr would be suitable for the other two.
>
> haddr vs. addr is just nasty.
>
> Can we call the aligned one "aligned_addr" or something like that?
This works. Let us use aligned_addr/addr everywhere then.
next prev parent reply other threads:[~2025-09-22 8:27 UTC|newest]
Thread overview: 13+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-09-20 0:54 Wei Yang
2025-09-20 4:30 ` Lance Yang
2025-09-20 9:00 ` Wei Yang
2025-09-20 12:42 ` Lance Yang
2025-09-20 4:51 ` Dev Jain
2025-09-20 9:02 ` Wei Yang
2025-09-20 12:31 ` Dev Jain
2025-09-22 8:12 ` Wei Yang
2025-09-22 8:16 ` David Hildenbrand
2025-09-22 8:26 ` Dev Jain [this message]
2025-09-22 13:02 ` Wei Yang
2025-09-22 13:28 ` David Hildenbrand
2025-09-22 13:32 ` Wei Yang
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=433cba08-e33f-43ba-bccc-a2b1f2b1cd50@arm.com \
--to=dev.jain@arm.com \
--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=lance.yang@linux.dev \
--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