linux-mm.kvack.org archive mirror
 help / color / mirror / Atom feed
From: liuye <liuye@kylinos.cn>
To: "David Hildenbrand (Arm)" <david@kernel.org>,
	Ye Liu <ye.liu@linux.dev>,
	Andrew Morton <akpm@linux-foundation.org>,
	Lorenzo Stoakes <ljs@kernel.org>
Cc: Zi Yan <ziy@nvidia.com>,
	Baolin Wang <baolin.wang@linux.alibaba.com>,
	"Liam R. Howlett" <Liam.Howlett@oracle.com>,
	Nico Pache <npache@redhat.com>,
	Ryan Roberts <ryan.roberts@arm.com>, Dev Jain <dev.jain@arm.com>,
	Barry Song <baohua@kernel.org>, Lance Yang <lance.yang@linux.dev>,
	linux-mm@kvack.org, linux-kernel@vger.kernel.org
Subject: Re: [PATCH] mm/khugepaged: use round_{up,down}() for PMD alignment in madvise_collapse()
Date: Thu, 9 Apr 2026 09:28:37 +0800	[thread overview]
Message-ID: <ba16238e-abb3-4867-b7eb-82271345efe9@kylinos.cn> (raw)
In-Reply-To: <f92c31e8-0a1e-43e5-8d41-18a1b17f4e27@kernel.org>


在 2026/4/8 18:34, David Hildenbrand (Arm) 写道:
> On 4/8/26 11:35, Ye Liu wrote:
>> From: Ye Liu <liuye@kylinos.cn>
>>
>> The PMD alignment in madvise_collapse() is currently implemented
>> using open-coded bitmask operations:
>>
>>     (start + ~HPAGE_PMD_MASK) & HPAGE_PMD_MASK
>>     end & HPAGE_PMD_MASK
>>
>> Replace them with round_up() and round_down(), which express the
>> same alignment semantics more directly and match other PMD-alignment
>> code paths in khugepaged.
>>
>> No functional change intended.
>>
>> Signed-off-by: Ye Liu <liuye@kylinos.cn>
>> ---
>>  mm/khugepaged.c | 4 ++--
>>  1 file changed, 2 insertions(+), 2 deletions(-)
>>
>> diff --git a/mm/khugepaged.c b/mm/khugepaged.c
>> index 1e2bff40d014..80d0b7136b58 100644
>> --- a/mm/khugepaged.c
>> +++ b/mm/khugepaged.c
>> @@ -2835,8 +2835,8 @@ int madvise_collapse(struct vm_area_struct *vma, unsigned long start,
>>  	mmgrab(mm);
>>  	lru_add_drain_all();
>>  
>> -	hstart = (start + ~HPAGE_PMD_MASK) & HPAGE_PMD_MASK;
>> -	hend = end & HPAGE_PMD_MASK;
>> +	hstart = round_up(start, HPAGE_PMD_SIZE);
>> +	hend = round_down(end, HPAGE_PMD_SIZE);
>>  
>>  	for (addr = hstart; addr < hend; addr += HPAGE_PMD_SIZE) {
>>  		enum scan_result result = SCAN_FAIL;
> I tend to prefer ALIGN / ALIGN_DOWN when dealing with sizes + addresses.
>
Thanks, that makes sense.                                          
                                                                   
I'll switch this to ALIGN()/ALIGN_DOWN() in v2 for the address/size
alignment style preference.                                        

-- 
Thanks,
Ye Liu



      reply	other threads:[~2026-04-09  1:28 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-04-08  9:35 Ye Liu
2026-04-08 10:34 ` David Hildenbrand (Arm)
2026-04-09  1:28   ` liuye [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=ba16238e-abb3-4867-b7eb-82271345efe9@kylinos.cn \
    --to=liuye@kylinos.cn \
    --cc=Liam.Howlett@oracle.com \
    --cc=akpm@linux-foundation.org \
    --cc=baohua@kernel.org \
    --cc=baolin.wang@linux.alibaba.com \
    --cc=david@kernel.org \
    --cc=dev.jain@arm.com \
    --cc=lance.yang@linux.dev \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-mm@kvack.org \
    --cc=ljs@kernel.org \
    --cc=npache@redhat.com \
    --cc=ryan.roberts@arm.com \
    --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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox