linux-mm.kvack.org archive mirror
 help / color / mirror / Atom feed
From: "David Hildenbrand (Arm)" <david@kernel.org>
To: Dev Jain <dev.jain@arm.com>, Andrew Morton <akpm@linux-foundation.org>
Cc: 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,
	linux-kernel@vger.kernel.org
Subject: Re: [PATCH] khugepaged: convert redundant check to WARN_ON
Date: Tue, 24 Feb 2026 11:51:23 +0100	[thread overview]
Message-ID: <24b7829b-aaf0-42ac-b91c-916754f95046@kernel.org> (raw)
In-Reply-To: <a0b4febb-d803-4c18-9211-7286d682d705@arm.com>

On 2/23/26 05:40, Dev Jain wrote:
> 
> On 20/02/26 4:03 am, Andrew Morton wrote:
>> On Thu, 19 Feb 2026 11:18:27 +0530 Dev Jain <dev.jain@arm.com> wrote:
>>
>>> Claim: folio_order(folio) == HPAGE_PMD_ORDER => folio->index == start.
>>>
>>> Proof: Both loops in hpage_collapse_scan_file and collapse_file, which
>>> iterate on the xarray, have the invariant that
>>> start <= folio->index < start + HPAGE_PMD_NR ... (i)
>>> A folio is always naturally aligned in the pagecache, therefore
>>> folio_order == HPAGE_PMD_ORDER => IS_ALIGNED(folio->index, HPAGE_PMD_NR) == true ... (ii)
>>> thp_vma_allowable_order -> thp_vma_suitable_order requires that the virtual
>>> offsets in the VMA are aligned to the order,
>>> => IS_ALIGNED(start, HPAGE_PMD_NR) == true ... (iii)
>>>
>>> Combining (i), (ii) and (iii), the claim is proven.
>>>
>>> Therefore, convert this to a VM_WARN_ON.
>>>
>>> ...
>>>
>>> --- a/mm/khugepaged.c
>>> +++ b/mm/khugepaged.c
>>> @@ -2000,8 +2000,9 @@ static enum scan_result collapse_file(struct mm_struct *mm, unsigned long addr,
>>>  		 * we locked the first folio, then a THP might be there already.
>>>  		 * This will be discovered on the first iteration.
>>>  		 */
>>> -		if (folio_order(folio) == HPAGE_PMD_ORDER &&
>>> -		    folio->index == start) {
>>> +		if (folio_order(folio) == HPAGE_PMD_ORDER) {
>>> +			VM_WARN_ON(folio->index != start);
>> It's a bad sad to remove unneeded code by retaining that code and
>> adding even more code.
>>
>> Perhaps add a comment reminding us to remove this altogether at a later
>> date?
> 
> But then shouldn't I remove it just now :) 

I'd say, remove it directly. Even if "folio->index != start", both
functions should do the right thing.

While at it, we could heavily simplify the comments to "If there is
already a PMD-sized THP, we can only try collapsing the PTE table".

Or sth, like that.

-- 
Cheers,

David


  reply	other threads:[~2026-02-24 10:51 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-02-19  5:48 Dev Jain
2026-02-19 22:33 ` Andrew Morton
2026-02-23  4:40   ` Dev Jain
2026-02-24 10:51     ` David Hildenbrand (Arm) [this message]
2026-02-24  8:21 ` Baolin Wang
2026-02-24  8:45   ` Lance 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=24b7829b-aaf0-42ac-b91c-916754f95046@kernel.org \
    --to=david@kernel.org \
    --cc=Liam.Howlett@oracle.com \
    --cc=akpm@linux-foundation.org \
    --cc=baohua@kernel.org \
    --cc=baolin.wang@linux.alibaba.com \
    --cc=dev.jain@arm.com \
    --cc=lance.yang@linux.dev \
    --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=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