* [PATCH] mm/khugepaged: don't map folios that are not uptodate in MADV_COLLAPSE
@ 2026-11-05 18:16 David Hildenbrand (Arm)
2026-11-05 19:34 ` Lorenzo Stoakes (ARM)
` (5 more replies)
0 siblings, 6 replies; 8+ messages in thread
From: David Hildenbrand (Arm) @ 2026-11-05 18:16 UTC (permalink / raw)
To: Andrew Morton, Zi Yan, Baolin Wang, Hugh Dickins,
Liam R. Howlett, Nico Pache, Ryan Roberts, Dev Jain, Barry Song,
Lance Yang, Usama Arif, Kiryl Shutsemau, Zach O'Keefe
Cc: linux-mm, linux-kernel, Chris Mason, stable, David Hildenbrand (Arm)
madvise(MADV_COLLAPSE) can map PMD-sized pagecache folios that are not
uptodate. For example, shmem fallocate() can put such folios into the
page cache.
collapse_file() already refuses to proceed with folios that are not
uptodate. Let's just do the same in try_collapse_pte_mapped_thp() and skip
such folios, leaving handling to the page faults.
Note that collapse_file() effectively clears shmem folios through
shmem_get_folio(); let's keep this fix simple and simply let the page
fault path deal with that.
Fixes: 34488399fa08 ("mm/madvise: add file and shmem support to MADV_COLLAPSE")
Reported-by: Chris Mason <mason@kernel.org>
Cc: stable@vger.kernel.org
Signed-off-by: David Hildenbrand (Arm) <david@kernel.org>
---
Once reviewed, I will pick this up in a timely manner.
---
mm/khugepaged.c | 6 ++++++
1 file changed, 6 insertions(+)
diff --git a/mm/khugepaged.c b/mm/khugepaged.c
index 8d9f05a39afb3..db135b3c44ef1 100644
--- a/mm/khugepaged.c
+++ b/mm/khugepaged.c
@@ -1900,6 +1900,12 @@ static enum scan_result try_collapse_pte_mapped_thp(struct mm_struct *mm, unsign
goto drop_folio;
}
+ /* Leave any uninitialized folios to the page fault path. */
+ if (!folio_test_uptodate(folio)) {
+ result = SCAN_FAIL;
+ goto drop_folio;
+ }
+
result = find_pmd_or_thp_or_none(mm, haddr, &pmd);
switch (result) {
case SCAN_SUCCEED:
---
base-commit: f44fd601f72e09e44c667b9234c9cd469856679c
change-id: 20261105-set_huge_pmd_uptodate-9b9820307f30
--
Cheers,
David
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: [PATCH] mm/khugepaged: don't map folios that are not uptodate in MADV_COLLAPSE
2026-11-05 18:16 [PATCH] mm/khugepaged: don't map folios that are not uptodate in MADV_COLLAPSE David Hildenbrand (Arm)
@ 2026-11-05 19:34 ` Lorenzo Stoakes (ARM)
2026-11-05 19:58 ` Hugh Dickins
` (4 subsequent siblings)
5 siblings, 0 replies; 8+ messages in thread
From: Lorenzo Stoakes (ARM) @ 2026-11-05 19:34 UTC (permalink / raw)
To: David Hildenbrand (Arm)
Cc: Andrew Morton, Zi Yan, Baolin Wang, Hugh Dickins,
Liam R. Howlett, Nico Pache, Ryan Roberts, Dev Jain, Barry Song,
Lance Yang, Usama Arif, Kiryl Shutsemau, Zach O'Keefe,
linux-mm, linux-kernel, Chris Mason, stable
On Thu, Nov 05, 2026 at 07:16:44PM +0100, David Hildenbrand (Arm) wrote:
> madvise(MADV_COLLAPSE) can map PMD-sized pagecache folios that are not
> uptodate. For example, shmem fallocate() can put such folios into the
> page cache.
>
> collapse_file() already refuses to proceed with folios that are not
> uptodate. Let's just do the same in try_collapse_pte_mapped_thp() and skip
> such folios, leaving handling to the page faults.
>
> Note that collapse_file() effectively clears shmem folios through
> shmem_get_folio(); let's keep this fix simple and simply let the page
> fault path deal with that.
>
> Fixes: 34488399fa08 ("mm/madvise: add file and shmem support to MADV_COLLAPSE")
> Reported-by: Chris Mason <mason@kernel.org>
> Cc: stable@vger.kernel.org
> Signed-off-by: David Hildenbrand (Arm) <david@kernel.org>
Looks reasonable to me, there's no reason we should be dealing with non-uptodate
folios there.
Reviewed-by: Lorenzo Stoakes (ARM) <ljs@kernel.org>
> ---
> Once reviewed, I will pick this up in a timely manner.
> ---
> mm/khugepaged.c | 6 ++++++
> 1 file changed, 6 insertions(+)
>
> diff --git a/mm/khugepaged.c b/mm/khugepaged.c
> index 8d9f05a39afb3..db135b3c44ef1 100644
> --- a/mm/khugepaged.c
> +++ b/mm/khugepaged.c
> @@ -1900,6 +1900,12 @@ static enum scan_result try_collapse_pte_mapped_thp(struct mm_struct *mm, unsign
> goto drop_folio;
> }
>
> + /* Leave any uninitialized folios to the page fault path. */
> + if (!folio_test_uptodate(folio)) {
> + result = SCAN_FAIL;
> + goto drop_folio;
> + }
> +
> result = find_pmd_or_thp_or_none(mm, haddr, &pmd);
> switch (result) {
> case SCAN_SUCCEED:
>
> ---
>
> base-commit: f44fd601f72e09e44c667b9234c9cd469856679c
>
> change-id: 20261105-set_huge_pmd_uptodate-9b9820307f30
>
> --
>
> Cheers,
>
> David
>
--
Cheers, Lorenzo
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: [PATCH] mm/khugepaged: don't map folios that are not uptodate in MADV_COLLAPSE
2026-11-05 18:16 [PATCH] mm/khugepaged: don't map folios that are not uptodate in MADV_COLLAPSE David Hildenbrand (Arm)
2026-11-05 19:34 ` Lorenzo Stoakes (ARM)
@ 2026-11-05 19:58 ` Hugh Dickins
2026-11-05 20:09 ` Zi Yan
` (3 subsequent siblings)
5 siblings, 0 replies; 8+ messages in thread
From: Hugh Dickins @ 2026-11-05 19:58 UTC (permalink / raw)
To: David Hildenbrand (Arm)
Cc: Andrew Morton, Zi Yan, Baolin Wang, Hugh Dickins,
Liam R. Howlett, Nico Pache, Ryan Roberts, Dev Jain, Barry Song,
Lance Yang, Usama Arif, Kiryl Shutsemau, Zach O'Keefe,
linux-mm, linux-kernel, Chris Mason, stable
On Thu, 5 Nov 2026, David Hildenbrand (Arm) wrote:
> madvise(MADV_COLLAPSE) can map PMD-sized pagecache folios that are not
> uptodate. For example, shmem fallocate() can put such folios into the
> page cache.
>
> collapse_file() already refuses to proceed with folios that are not
> uptodate. Let's just do the same in try_collapse_pte_mapped_thp() and skip
> such folios, leaving handling to the page faults.
>
> Note that collapse_file() effectively clears shmem folios through
> shmem_get_folio(); let's keep this fix simple and simply let the page
> fault path deal with that.
>
> Fixes: 34488399fa08 ("mm/madvise: add file and shmem support to MADV_COLLAPSE")
> Reported-by: Chris Mason <mason@kernel.org>
> Cc: stable@vger.kernel.org
> Signed-off-by: David Hildenbrand (Arm) <david@kernel.org>
Acked-by: Hugh Dickins <hughd@google.com>
Valuable catch, thanks. I was worried that "try_collapse_pte_mapped_thp"
implies there's already a PTE mapping the non-uptodate folio, which
would already be wrong. But we've been a little too free with the
SCAN_PTE_MAPPED_HUGEPAGE result code, so there's no such implication
(and even if there had been a good PTE, I doubt there's enough locking
to stop racing fallocates putting a non-uptodate folio there meanwhile).
I was going to quibble with the Fixes, thinking the problem was there
earlier: but no, I agree with you, that's when install_pmd came in.
> ---
> Once reviewed, I will pick this up in a timely manner.
> ---
> mm/khugepaged.c | 6 ++++++
> 1 file changed, 6 insertions(+)
>
> diff --git a/mm/khugepaged.c b/mm/khugepaged.c
> index 8d9f05a39afb3..db135b3c44ef1 100644
> --- a/mm/khugepaged.c
> +++ b/mm/khugepaged.c
> @@ -1900,6 +1900,12 @@ static enum scan_result try_collapse_pte_mapped_thp(struct mm_struct *mm, unsign
> goto drop_folio;
> }
>
> + /* Leave any uninitialized folios to the page fault path. */
> + if (!folio_test_uptodate(folio)) {
> + result = SCAN_FAIL;
> + goto drop_folio;
> + }
> +
> result = find_pmd_or_thp_or_none(mm, haddr, &pmd);
> switch (result) {
> case SCAN_SUCCEED:
>
> ---
>
> base-commit: f44fd601f72e09e44c667b9234c9cd469856679c
>
> change-id: 20261105-set_huge_pmd_uptodate-9b9820307f30
>
> --
>
> Cheers,
>
> David
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: [PATCH] mm/khugepaged: don't map folios that are not uptodate in MADV_COLLAPSE
2026-11-05 18:16 [PATCH] mm/khugepaged: don't map folios that are not uptodate in MADV_COLLAPSE David Hildenbrand (Arm)
2026-11-05 19:34 ` Lorenzo Stoakes (ARM)
2026-11-05 19:58 ` Hugh Dickins
@ 2026-11-05 20:09 ` Zi Yan
2026-11-05 21:24 ` Zach O'Keefe
2026-11-06 1:08 ` SJ Park
` (2 subsequent siblings)
5 siblings, 1 reply; 8+ messages in thread
From: Zi Yan @ 2026-11-05 20:09 UTC (permalink / raw)
To: David Hildenbrand (Arm),
Andrew Morton, Baolin Wang, Hugh Dickins, Liam R. Howlett,
Nico Pache, Ryan Roberts, Dev Jain, Barry Song, Lance Yang,
Usama Arif, Kiryl Shutsemau, Zach O'Keefe
Cc: linux-mm, linux-kernel, Chris Mason, stable
On Thu Nov 5, 2026 at 1:16 PM EST, David Hildenbrand (Arm) wrote:
> madvise(MADV_COLLAPSE) can map PMD-sized pagecache folios that are not
> uptodate. For example, shmem fallocate() can put such folios into the
> page cache.
>
> collapse_file() already refuses to proceed with folios that are not
> uptodate. Let's just do the same in try_collapse_pte_mapped_thp() and skip
> such folios, leaving handling to the page faults.
>
> Note that collapse_file() effectively clears shmem folios through
> shmem_get_folio(); let's keep this fix simple and simply let the page
> fault path deal with that.
>
> Fixes: 34488399fa08 ("mm/madvise: add file and shmem support to MADV_COLLAPSE")
> Reported-by: Chris Mason <mason@kernel.org>
> Cc: stable@vger.kernel.org
> Signed-off-by: David Hildenbrand (Arm) <david@kernel.org>
> ---
> Once reviewed, I will pick this up in a timely manner.
> ---
> mm/khugepaged.c | 6 ++++++
> 1 file changed, 6 insertions(+)
>
Makes sense.
Acked-by: Zi Yan <ziy@nvidia.com>
--
Best Regards,
Yan, Zi
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: [PATCH] mm/khugepaged: don't map folios that are not uptodate in MADV_COLLAPSE
2026-11-05 20:09 ` Zi Yan
@ 2026-11-05 21:24 ` Zach O'Keefe
0 siblings, 0 replies; 8+ messages in thread
From: Zach O'Keefe @ 2026-11-05 21:24 UTC (permalink / raw)
To: Zi Yan
Cc: David Hildenbrand (Arm),
Andrew Morton, Baolin Wang, Hugh Dickins, Liam R. Howlett,
Nico Pache, Ryan Roberts, Dev Jain, Barry Song, Lance Yang,
Usama Arif, Kiryl Shutsemau, linux-mm, linux-kernel, Chris Mason,
stable
On Thu, Nov 5, 2026 at 12:09 PM Zi Yan <ziy@nvidia.com> wrote:
>
> On Thu Nov 5, 2026 at 1:16 PM EST, David Hildenbrand (Arm) wrote:
> > madvise(MADV_COLLAPSE) can map PMD-sized pagecache folios that are not
> > uptodate. For example, shmem fallocate() can put such folios into the
> > page cache.
> >
> > collapse_file() already refuses to proceed with folios that are not
> > uptodate. Let's just do the same in try_collapse_pte_mapped_thp() and skip
> > such folios, leaving handling to the page faults.
> >
> > Note that collapse_file() effectively clears shmem folios through
> > shmem_get_folio(); let's keep this fix simple and simply let the page
> > fault path deal with that.
> >
> > Fixes: 34488399fa08 ("mm/madvise: add file and shmem support to MADV_COLLAPSE")
> > Reported-by: Chris Mason <mason@kernel.org>
> > Cc: stable@vger.kernel.org
> > Signed-off-by: David Hildenbrand (Arm) <david@kernel.org>
> > ---
> > Once reviewed, I will pick this up in a timely manner.
> > ---
> > mm/khugepaged.c | 6 ++++++
> > 1 file changed, 6 insertions(+)
> >
> Makes sense.
>
> Acked-by: Zi Yan <ziy@nvidia.com>
Ah, good catch..
Agree with Hugh that the "pte_mapped" naming is a bit of a misnomer,
though it was how I was thinking of things at the time.
Thanks David / Chris.
Reviewed-by: Zach O'Keefe <zokeefe@google.com>
> --
> Best Regards,
> Yan, Zi
>
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: [PATCH] mm/khugepaged: don't map folios that are not uptodate in MADV_COLLAPSE
2026-11-05 18:16 [PATCH] mm/khugepaged: don't map folios that are not uptodate in MADV_COLLAPSE David Hildenbrand (Arm)
` (2 preceding siblings ...)
2026-11-05 20:09 ` Zi Yan
@ 2026-11-06 1:08 ` SJ Park
2026-11-06 2:49 ` Baolin Wang
2026-11-06 2:53 ` Lance Yang
5 siblings, 0 replies; 8+ messages in thread
From: SJ Park @ 2026-11-06 1:08 UTC (permalink / raw)
To: David Hildenbrand (Arm)
Cc: SJ Park, Andrew Morton, Zi Yan, Baolin Wang, Hugh Dickins,
Liam R. Howlett, Nico Pache, Ryan Roberts, Dev Jain, Barry Song,
Lance Yang, Usama Arif, Kiryl Shutsemau, Zach O'Keefe,
linux-mm, linux-kernel, Chris Mason, stable
On Thu, 05 Nov 2026 19:16:44 +0100 "David Hildenbrand (Arm)" <david@kernel.org> wrote:
> madvise(MADV_COLLAPSE) can map PMD-sized pagecache folios that are not
> uptodate. For example, shmem fallocate() can put such folios into the
> page cache.
>
> collapse_file() already refuses to proceed with folios that are not
> uptodate. Let's just do the same in try_collapse_pte_mapped_thp() and skip
> such folios, leaving handling to the page faults.
>
> Note that collapse_file() effectively clears shmem folios through
> shmem_get_folio(); let's keep this fix simple and simply let the page
> fault path deal with that.
Makes sense to me.
>
> Fixes: 34488399fa08 ("mm/madvise: add file and shmem support to MADV_COLLAPSE")
> Reported-by: Chris Mason <mason@kernel.org>
> Cc: stable@vger.kernel.org
> Signed-off-by: David Hildenbrand (Arm) <david@kernel.org>
Reviewed-by: SJ Park <sj@kernel.org>
Thanks,
SJ
[...]
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: [PATCH] mm/khugepaged: don't map folios that are not uptodate in MADV_COLLAPSE
2026-11-05 18:16 [PATCH] mm/khugepaged: don't map folios that are not uptodate in MADV_COLLAPSE David Hildenbrand (Arm)
` (3 preceding siblings ...)
2026-11-06 1:08 ` SJ Park
@ 2026-11-06 2:49 ` Baolin Wang
2026-11-06 2:53 ` Lance Yang
5 siblings, 0 replies; 8+ messages in thread
From: Baolin Wang @ 2026-11-06 2:49 UTC (permalink / raw)
To: David Hildenbrand (Arm),
Andrew Morton, Zi Yan, Hugh Dickins, Liam R. Howlett, Nico Pache,
Ryan Roberts, Dev Jain, Barry Song, Lance Yang, Usama Arif,
Kiryl Shutsemau, Zach O'Keefe
Cc: linux-mm, linux-kernel, Chris Mason, stable
On 11/6/26 2:16 AM, David Hildenbrand (Arm) wrote:
> madvise(MADV_COLLAPSE) can map PMD-sized pagecache folios that are not
> uptodate. For example, shmem fallocate() can put such folios into the
> page cache.
>
> collapse_file() already refuses to proceed with folios that are not
> uptodate. Let's just do the same in try_collapse_pte_mapped_thp() and skip
> such folios, leaving handling to the page faults.
>
> Note that collapse_file() effectively clears shmem folios through
> shmem_get_folio(); let's keep this fix simple and simply let the page
> fault path deal with that.
>
> Fixes: 34488399fa08 ("mm/madvise: add file and shmem support to MADV_COLLAPSE")
> Reported-by: Chris Mason <mason@kernel.org>
> Cc: stable@vger.kernel.org
> Signed-off-by: David Hildenbrand (Arm) <david@kernel.org>
> ---
Make sense to me.
Reviewed-by: Baolin Wang <baolin.wang@linux.alibaba.com>
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: [PATCH] mm/khugepaged: don't map folios that are not uptodate in MADV_COLLAPSE
2026-11-05 18:16 [PATCH] mm/khugepaged: don't map folios that are not uptodate in MADV_COLLAPSE David Hildenbrand (Arm)
` (4 preceding siblings ...)
2026-11-06 2:49 ` Baolin Wang
@ 2026-11-06 2:53 ` Lance Yang
5 siblings, 0 replies; 8+ messages in thread
From: Lance Yang @ 2026-11-06 2:53 UTC (permalink / raw)
To: david
Cc: akpm, ziy, baolin.wang, hughd, liam, nico.pache, ryan.roberts,
dev.jain, baohua, lance.yang, usama.arif, kas, zokeefe, linux-mm,
linux-kernel, mason, stable
On Thu, Nov 05, 2026 at 07:16:44PM +0100, David Hildenbrand (Arm) wrote:
>madvise(MADV_COLLAPSE) can map PMD-sized pagecache folios that are not
>uptodate. For example, shmem fallocate() can put such folios into the
>page cache.
>
>collapse_file() already refuses to proceed with folios that are not
>uptodate. Let's just do the same in try_collapse_pte_mapped_thp() and skip
>such folios, leaving handling to the page faults.
>
>Note that collapse_file() effectively clears shmem folios through
>shmem_get_folio(); let's keep this fix simple and simply let the page
>fault path deal with that.
>
>Fixes: 34488399fa08 ("mm/madvise: add file and shmem support to MADV_COLLAPSE")
>Reported-by: Chris Mason <mason@kernel.org>
>Cc: stable@vger.kernel.org
>Signed-off-by: David Hildenbrand (Arm) <david@kernel.org>
>---
Nice work1
Reviewed-by: Lance Yang <lance.yang@linux.dev>
^ permalink raw reply [flat|nested] 8+ messages in thread
end of thread, other threads:[~2026-11-06 2:53 UTC | newest]
Thread overview: 8+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-11-05 18:16 [PATCH] mm/khugepaged: don't map folios that are not uptodate in MADV_COLLAPSE David Hildenbrand (Arm)
2026-11-05 19:34 ` Lorenzo Stoakes (ARM)
2026-11-05 19:58 ` Hugh Dickins
2026-11-05 20:09 ` Zi Yan
2026-11-05 21:24 ` Zach O'Keefe
2026-11-06 1:08 ` SJ Park
2026-11-06 2:49 ` Baolin Wang
2026-11-06 2:53 ` Lance Yang
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®