From: "Zach O'Keefe" <zokeefe@google.com>
To: Zi Yan <ziy@nvidia.com>
Cc: Kiryl Shutsemau <kirill@shutemov.name>,
Andrew Morton <akpm@linux-foundation.org>,
David Hildenbrand <david@redhat.com>,
Lorenzo Stoakes <lorenzo.stoakes@oracle.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>,
linux-mm@kvack.org, linux-kernel@vger.kernel.org
Subject: Re: [PATCHv2] mm/khugepaged: Do not fail collapse_pte_mapped_thp() on SCAN_PMD_NULL
Date: Mon, 15 Sep 2025 09:51:16 -0700 [thread overview]
Message-ID: <CAAa6QmT-x4MmpMRigx_T3kwn2MTApotz1sr_RKze-k94kXwiOA@mail.gmail.com> (raw)
In-Reply-To: <63CFCF33-B334-446F-B6AE-EADB24A9F8CD@nvidia.com>
[-- Attachment #1: Type: text/plain, Size: 2146 bytes --]
On Mon, Sep 15, 2025 at 8:35 AM Zi Yan <ziy@nvidia.com> wrote:
> On 15 Sep 2025, at 9:52, Kiryl Shutsemau wrote:
>
> > From: Kiryl Shutsemau <kas@kernel.org>
> >
> > MADV_COLLAPSE on a file mapping behaves inconsistently depending on if
> > PMD page table is installed or not.
> >
> > Consider following example:
> >
> > p = mmap(NULL, 2UL << 20, PROT_READ | PROT_WRITE,
> > MAP_SHARED, fd, 0);
> > err = madvise(p, 2UL << 20, MADV_COLLAPSE);
> >
> > fd is a populated tmpfs file.
> >
> > The result depends on the address that the kernel returns on mmap().
> > If it is located in an existing PMD table, the madvise() will succeed.
> > However, if the table does not exist, it will fail with -EINVAL.
> >
> > This occurs because find_pmd_or_thp_or_none() returns SCAN_PMD_NULL when
> > a page table is missing, which causes collapse_pte_mapped_thp() to fail.
> >
> > SCAN_PMD_NULL and SCAN_PMD_NONE should be treated the same in
> > collapse_pte_mapped_thp(): install the PMD leaf entry and allocate page
> > tables as needed.
>
> Why does collapse code want to know the difference between SCAN_PMD_NULL
> and
> SCAN_PMD_NONE? Both seems to be treated as “nothing here, install a PMD
> leaf”. One difference is that madvise_collapse() will continue
> on SCAN_PMD_NULL but bail out on SCAN_PMD_NONE.
>
> I wonder if we could have SCAN_PMD_NULL_OR_NONE instead.
>
> Zach, since you added both, can you share some insight? Thanks.
>
> >
> > Signed-off-by: Kiryl Shutsemau <kas@kernel.org>
> > ---
> >
> > v2:
> > - Modify set_huge_pmd() instead of introducing install_huge_pmd();
> >
> > ---
> > mm/khugepaged.c | 20 +++++++++++++++++++-
> > 1 file changed, 19 insertions(+), 1 deletion(-)
> >
>
> The changes look good to me. Reviewed-by: Zi Yan <ziy@nvidia.com>
>
> Best Regards,
> Yan, Zi
Thanks Zi. Hugh had also looped me into this. Travelling today but will
respond tomorrow. Generally though, this is a behavioural cleanup I’d had
been meaning to do for a while, but didn’t realize it’d be so
straightforward. Thank you,
Kiryl
>
>
[-- Attachment #2: Type: text/html, Size: 3463 bytes --]
next prev parent reply other threads:[~2025-09-15 16:51 UTC|newest]
Thread overview: 13+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-09-15 13:52 Kiryl Shutsemau
2025-09-15 13:58 ` David Hildenbrand
2025-09-15 15:08 ` Dev Jain
2025-09-15 15:35 ` Zi Yan
2025-09-15 16:51 ` Zach O'Keefe [this message]
2025-09-16 9:54 ` Lorenzo Stoakes
2025-09-16 18:06 ` Zach O'Keefe
2025-09-17 10:52 ` Kiryl Shutsemau
2025-09-17 13:56 ` Zach O'Keefe
2025-09-18 12:27 ` Lorenzo Stoakes
2025-09-17 10:43 ` Kiryl Shutsemau
2025-09-18 12:16 ` Lorenzo Stoakes
2025-09-19 3:14 ` Baolin Wang
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=CAAa6QmT-x4MmpMRigx_T3kwn2MTApotz1sr_RKze-k94kXwiOA@mail.gmail.com \
--to=zokeefe@google.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=dev.jain@arm.com \
--cc=kirill@shutemov.name \
--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