mm/huge_memory.c | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-)
The comment appears to be outdated. First, add_to_swap() no longer
exists after Kairui’s commit b487a2da3575 ("mm, swap: simplify folio
swap allocation"). Second, partially zapped folios are now always
split before folio_alloc_swap() to avoid extra I/O, following Ryan’s
commit 5ed890ce5147 ("mm: vmscan: avoid split during
shrink_folio_list()").
Fix this by making the description more generic.
Cc: David Hildenbrand <david@kernel.org>
Cc: Lorenzo Stoakes <ljs@kernel.org>
Cc: Zi Yan <ziy@nvidia.com>
Cc: Baolin Wang <baolin.wang@linux.alibaba.com>
Cc: "Liam R. Howlett" <Liam.Howlett@oracle.com>
Cc: Nico Pache <npache@redhat.com>
Cc: Ryan Roberts <ryan.roberts@arm.com>
Cc: Dev Jain <dev.jain@arm.com>
Cc: Lance Yang <lance.yang@linux.dev>
Cc: Chris Li <chrisl@kernel.org>
Cc: Kairui Song <kasong@tencent.com>
Cc: Kemeng Shi <shikemeng@huaweicloud.com>
Cc: Nhat Pham <nphamcs@gmail.com>
Cc: Baoquan He <bhe@redhat.com>
Cc: Youngjun Park <youngjun.park@lge.com>
Signed-off-by: Barry Song (Xiaomi) <baohua@kernel.org>
---
mm/huge_memory.c | 9 ++++-----
1 file changed, 4 insertions(+), 5 deletions(-)
diff --git a/mm/huge_memory.c b/mm/huge_memory.c
index 970e077019b7..4586f3ccb133 100644
--- a/mm/huge_memory.c
+++ b/mm/huge_memory.c
@@ -4190,11 +4190,10 @@ static int __folio_split(struct folio *folio, unsigned int new_order,
folio_unlock(new_folio);
/*
- * Subpages may be freed if there wasn't any mapping
- * like if add_to_swap() is running on a lru page that
- * had its mapping zapped. And freeing these pages
- * requires taking the lru_lock so we do the put_page
- * of the tail pages after the split is complete.
+ * Subpages whose mapping has been zapped may be freed
+ * earlier, but freeing them requires taking the
+ * lru_lock, so we defer put_page() on tail pages until
+ * after the split completes.
*/
free_folio_and_swap_cache(new_folio);
}
--
2.39.3 (Apple Git-146)
On 22 Apr 2026, at 23:49, Barry Song (Xiaomi) wrote:
> The comment appears to be outdated. First, add_to_swap() no longer
> exists after Kairui’s commit b487a2da3575 ("mm, swap: simplify folio
> swap allocation"). Second, partially zapped folios are now always
> split before folio_alloc_swap() to avoid extra I/O, following Ryan’s
> commit 5ed890ce5147 ("mm: vmscan: avoid split during
> shrink_folio_list()").
> Fix this by making the description more generic.
>
> Cc: David Hildenbrand <david@kernel.org>
> Cc: Lorenzo Stoakes <ljs@kernel.org>
> Cc: Zi Yan <ziy@nvidia.com>
> Cc: Baolin Wang <baolin.wang@linux.alibaba.com>
> Cc: "Liam R. Howlett" <Liam.Howlett@oracle.com>
> Cc: Nico Pache <npache@redhat.com>
> Cc: Ryan Roberts <ryan.roberts@arm.com>
> Cc: Dev Jain <dev.jain@arm.com>
> Cc: Lance Yang <lance.yang@linux.dev>
> Cc: Chris Li <chrisl@kernel.org>
> Cc: Kairui Song <kasong@tencent.com>
> Cc: Kemeng Shi <shikemeng@huaweicloud.com>
> Cc: Nhat Pham <nphamcs@gmail.com>
> Cc: Baoquan He <bhe@redhat.com>
> Cc: Youngjun Park <youngjun.park@lge.com>
> Signed-off-by: Barry Song (Xiaomi) <baohua@kernel.org>
> ---
> mm/huge_memory.c | 9 ++++-----
> 1 file changed, 4 insertions(+), 5 deletions(-)
>
> diff --git a/mm/huge_memory.c b/mm/huge_memory.c
> index 970e077019b7..4586f3ccb133 100644
> --- a/mm/huge_memory.c
> +++ b/mm/huge_memory.c
> @@ -4190,11 +4190,10 @@ static int __folio_split(struct folio *folio, unsigned int new_order,
>
> folio_unlock(new_folio);
> /*
> - * Subpages may be freed if there wasn't any mapping
> - * like if add_to_swap() is running on a lru page that
> - * had its mapping zapped. And freeing these pages
> - * requires taking the lru_lock so we do the put_page
> - * of the tail pages after the split is complete.
> + * Subpages whose mapping has been zapped may be freed
> + * earlier, but freeing them requires taking the
> + * lru_lock, so we defer put_page() on tail pages until
> + * after the split completes.
> */
> free_folio_and_swap_cache(new_folio);
> }
> --
> 2.39.3 (Apple Git-146)
Acked-by: Zi Yan <ziy@nvidia.com>
--
Best Regards,
Yan, Zi
On 4/23/26 05:49, Barry Song (Xiaomi) wrote:
> The comment appears to be outdated. First, add_to_swap() no longer
> exists after Kairui’s commit b487a2da3575 ("mm, swap: simplify folio
> swap allocation"). Second, partially zapped folios are now always
> split before folio_alloc_swap() to avoid extra I/O, following Ryan’s
> commit 5ed890ce5147 ("mm: vmscan: avoid split during
> shrink_folio_list()").
Not necessarily. We have some scenarios where we have partially-mapped folios
not detected as such as of today (with CONFIG_NO_PAGE_MAPCOUNT).
> Fix this by making the description more generic.
>
> Cc: David Hildenbrand <david@kernel.org>
> Cc: Lorenzo Stoakes <ljs@kernel.org>
> Cc: Zi Yan <ziy@nvidia.com>
> Cc: Baolin Wang <baolin.wang@linux.alibaba.com>
> Cc: "Liam R. Howlett" <Liam.Howlett@oracle.com>
> Cc: Nico Pache <npache@redhat.com>
> Cc: Ryan Roberts <ryan.roberts@arm.com>
> Cc: Dev Jain <dev.jain@arm.com>
> Cc: Lance Yang <lance.yang@linux.dev>
> Cc: Chris Li <chrisl@kernel.org>
> Cc: Kairui Song <kasong@tencent.com>
> Cc: Kemeng Shi <shikemeng@huaweicloud.com>
> Cc: Nhat Pham <nphamcs@gmail.com>
> Cc: Baoquan He <bhe@redhat.com>
> Cc: Youngjun Park <youngjun.park@lge.com>
> Signed-off-by: Barry Song (Xiaomi) <baohua@kernel.org>
> ---
> mm/huge_memory.c | 9 ++++-----
> 1 file changed, 4 insertions(+), 5 deletions(-)
>
> diff --git a/mm/huge_memory.c b/mm/huge_memory.c
> index 970e077019b7..4586f3ccb133 100644
> --- a/mm/huge_memory.c
> +++ b/mm/huge_memory.c
> @@ -4190,11 +4190,10 @@ static int __folio_split(struct folio *folio, unsigned int new_order,
>
> folio_unlock(new_folio);
> /*
> - * Subpages may be freed if there wasn't any mapping
> - * like if add_to_swap() is running on a lru page that
> - * had its mapping zapped. And freeing these pages
> - * requires taking the lru_lock so we do the put_page
> - * of the tail pages after the split is complete.
> + * Subpages whose mapping has been zapped may be freed
> + * earlier, but freeing them requires taking the
> + * lru_lock, so we defer put_page() on tail pages until
> + * after the split completes.
> */
> free_folio_and_swap_cache(new_folio);
> }
Acked-by: David Hildenbrand (Arm) <david@kernel.org>
--
Cheers,
David
On Thu, Apr 23, 2026 at 8:36 PM David Hildenbrand (Arm)
<david@kernel.org> wrote:
>
> On 4/23/26 05:49, Barry Song (Xiaomi) wrote:
> > The comment appears to be outdated. First, add_to_swap() no longer
> > exists after Kairui’s commit b487a2da3575 ("mm, swap: simplify folio
> > swap allocation"). Second, partially zapped folios are now always
> > split before folio_alloc_swap() to avoid extra I/O, following Ryan’s
> > commit 5ed890ce5147 ("mm: vmscan: avoid split during
> > shrink_folio_list()").
>
> Not necessarily. We have some scenarios where we have partially-mapped folios
> not detected as such as of today (with CONFIG_NO_PAGE_MAPCOUNT).
Thanks, david! would it make more sense to add “when
CONFIG_PAGE_MAPCOUNT is enabled” at the end of the
sentence? I mean:
"
following Ryan’s
commit 5ed890ce5147 ("mm: vmscan: avoid split during
shrink_folio_list()") when CONFIG_PAGE_MAPCOUNT is enabled.
"
>
> > Fix this by making the description more generic.
> >
> > Cc: David Hildenbrand <david@kernel.org>
> > Cc: Lorenzo Stoakes <ljs@kernel.org>
> > Cc: Zi Yan <ziy@nvidia.com>
> > Cc: Baolin Wang <baolin.wang@linux.alibaba.com>
> > Cc: "Liam R. Howlett" <Liam.Howlett@oracle.com>
> > Cc: Nico Pache <npache@redhat.com>
> > Cc: Ryan Roberts <ryan.roberts@arm.com>
> > Cc: Dev Jain <dev.jain@arm.com>
> > Cc: Lance Yang <lance.yang@linux.dev>
> > Cc: Chris Li <chrisl@kernel.org>
> > Cc: Kairui Song <kasong@tencent.com>
> > Cc: Kemeng Shi <shikemeng@huaweicloud.com>
> > Cc: Nhat Pham <nphamcs@gmail.com>
> > Cc: Baoquan He <bhe@redhat.com>
> > Cc: Youngjun Park <youngjun.park@lge.com>
> > Signed-off-by: Barry Song (Xiaomi) <baohua@kernel.org>
> > ---
> > mm/huge_memory.c | 9 ++++-----
> > 1 file changed, 4 insertions(+), 5 deletions(-)
> >
> > diff --git a/mm/huge_memory.c b/mm/huge_memory.c
> > index 970e077019b7..4586f3ccb133 100644
> > --- a/mm/huge_memory.c
> > +++ b/mm/huge_memory.c
> > @@ -4190,11 +4190,10 @@ static int __folio_split(struct folio *folio, unsigned int new_order,
> >
> > folio_unlock(new_folio);
> > /*
> > - * Subpages may be freed if there wasn't any mapping
> > - * like if add_to_swap() is running on a lru page that
> > - * had its mapping zapped. And freeing these pages
> > - * requires taking the lru_lock so we do the put_page
> > - * of the tail pages after the split is complete.
> > + * Subpages whose mapping has been zapped may be freed
> > + * earlier, but freeing them requires taking the
> > + * lru_lock, so we defer put_page() on tail pages until
> > + * after the split completes.
> > */
> > free_folio_and_swap_cache(new_folio);
> > }
>
> Acked-by: David Hildenbrand (Arm) <david@kernel.org>
Thanks for reviewing!
Best Regards,
Barry
On 4/26/26 22:42, Barry Song wrote:
> On Thu, Apr 23, 2026 at 8:36 PM David Hildenbrand (Arm)
> <david@kernel.org> wrote:
>>
>> On 4/23/26 05:49, Barry Song (Xiaomi) wrote:
>>> The comment appears to be outdated. First, add_to_swap() no longer
>>> exists after Kairui’s commit b487a2da3575 ("mm, swap: simplify folio
>>> swap allocation"). Second, partially zapped folios are now always
>>> split before folio_alloc_swap() to avoid extra I/O, following Ryan’s
>>> commit 5ed890ce5147 ("mm: vmscan: avoid split during
>>> shrink_folio_list()").
>>
>> Not necessarily. We have some scenarios where we have partially-mapped folios
>> not detected as such as of today (with CONFIG_NO_PAGE_MAPCOUNT).
>
> Thanks, david! would it make more sense to add “when
> CONFIG_PAGE_MAPCOUNT is enabled” at the end of the
> sentence?
Better to phrase it in a way that doesn't even require these details :)
Do we even need this detail in the patch description?
--
Cheers,
David
On Mon, Apr 27, 2026 at 3:42 PM David Hildenbrand (Arm)
<david@kernel.org> wrote:
>
> On 4/26/26 22:42, Barry Song wrote:
> > On Thu, Apr 23, 2026 at 8:36 PM David Hildenbrand (Arm)
> > <david@kernel.org> wrote:
> >>
> >> On 4/23/26 05:49, Barry Song (Xiaomi) wrote:
> >>> The comment appears to be outdated. First, add_to_swap() no longer
> >>> exists after Kairui’s commit b487a2da3575 ("mm, swap: simplify folio
> >>> swap allocation"). Second, partially zapped folios are now always
> >>> split before folio_alloc_swap() to avoid extra I/O, following Ryan’s
> >>> commit 5ed890ce5147 ("mm: vmscan: avoid split during
> >>> shrink_folio_list()").
> >>
> >> Not necessarily. We have some scenarios where we have partially-mapped folios
> >> not detected as such as of today (with CONFIG_NO_PAGE_MAPCOUNT).
> >
> > Thanks, david! would it make more sense to add “when
> > CONFIG_PAGE_MAPCOUNT is enabled” at the end of the
> > sentence?
>
> Better to phrase it in a way that doesn't even require these details :)
>
> Do we even need this detail in the patch description?
What about:
The comment appears to be outdated. add_to_swap() no longer exists,
and the explanation of why we need to call put_page() after
splitting could be made more general.
Best Regards
Barry
On 4/28/26 12:05, Barry Song wrote: > On Mon, Apr 27, 2026 at 3:42 PM David Hildenbrand (Arm) > <david@kernel.org> wrote: >> >> On 4/26/26 22:42, Barry Song wrote: >>> On Thu, Apr 23, 2026 at 8:36 PM David Hildenbrand (Arm) >>> <david@kernel.org> wrote: >>> >>> Thanks, david! would it make more sense to add “when >>> CONFIG_PAGE_MAPCOUNT is enabled” at the end of the >>> sentence? >> >> Better to phrase it in a way that doesn't even require these details :) >> >> Do we even need this detail in the patch description? > > What about: > > The comment appears to be outdated. add_to_swap() no longer exists, > and the explanation of why we need to call put_page() after > splitting could be made more general. Jup :) -- Cheers, David
On Tue, Apr 28, 2026 at 6:08 PM David Hildenbrand (Arm) <david@kernel.org> wrote: > > On 4/28/26 12:05, Barry Song wrote: > > On Mon, Apr 27, 2026 at 3:42 PM David Hildenbrand (Arm) > > <david@kernel.org> wrote: > >> > >> On 4/26/26 22:42, Barry Song wrote: > >>> On Thu, Apr 23, 2026 at 8:36 PM David Hildenbrand (Arm) > >>> <david@kernel.org> wrote: > >>> > >>> Thanks, david! would it make more sense to add “when > >>> CONFIG_PAGE_MAPCOUNT is enabled” at the end of the > >>> sentence? > >> > >> Better to phrase it in a way that doesn't even require these details :) > >> > >> Do we even need this detail in the patch description? > > > > What about: > > > > The comment appears to be outdated. add_to_swap() no longer exists, > > and the explanation of why we need to call put_page() after > > splitting could be made more general. > > Jup :) Thanks! Hi Andrew, would you like to make the change in the changelog, or would you prefer that I send a new version? Thanks Barry
On Tue, 28 Apr 2026 18:32:40 +0800 Barry Song <baohua@kernel.org> wrote: > On Tue, Apr 28, 2026 at 6:08 PM David Hildenbrand (Arm) > <david@kernel.org> wrote: > > > > On 4/28/26 12:05, Barry Song wrote: > > > On Mon, Apr 27, 2026 at 3:42 PM David Hildenbrand (Arm) > > > <david@kernel.org> wrote: > > >> > > >> On 4/26/26 22:42, Barry Song wrote: > > >>> On Thu, Apr 23, 2026 at 8:36 PM David Hildenbrand (Arm) > > >>> <david@kernel.org> wrote: > > >>> > > >>> Thanks, david! would it make more sense to add “when > > >>> CONFIG_PAGE_MAPCOUNT is enabled” at the end of the > > >>> sentence? > > >> > > >> Better to phrase it in a way that doesn't even require these details :) > > >> > > >> Do we even need this detail in the patch description? > > > > > > What about: > > > > > > The comment appears to be outdated. add_to_swap() no longer exists, > > > and the explanation of why we need to call put_page() after > > > splitting could be made more general. > > > > Jup :) > > Thanks! > Hi Andrew, would you like to make the change in the > changelog, or would you prefer that I send a new version? This? From: "Barry Song (Xiaomi)" <baohua@kernel.org> Subject: mm/huge_memory: fix outdated comment about freeing subpages in __folio_split Date: Thu, 23 Apr 2026 11:49:17 +0800 The comment appears to be outdated. add_to_swap() no longer exists, and the explanation of why we need to call put_page() after splitting could be made more general. Link: https://lore.kernel.org/20260423034917.8234-1-baohua@kernel.org Signed-off-by: Barry Song (Xiaomi) <baohua@kernel.org> Acked-by: David Hildenbrand (Arm) <david@kernel.org> Acked-by: Zi Yan <ziy@nvidia.com> Cc: Lorenzo Stoakes <ljs@kernel.org> Cc: Baolin Wang <baolin.wang@linux.alibaba.com> Cc: Liam R. Howlett <liam@infradead.org> Cc: Nico Pache <npache@redhat.com> Cc: Ryan Roberts <ryan.roberts@arm.com> Cc: Dev Jain <dev.jain@arm.com> Cc: Lance Yang <lance.yang@linux.dev> Cc: Chris Li <chrisl@kernel.org> Cc: Kairui Song <kasong@tencent.com> Cc: Kemeng Shi <shikemeng@huaweicloud.com> Cc: Nhat Pham <nphamcs@gmail.com> Cc: Baoquan He <bhe@redhat.com> Cc: Youngjun Park <youngjun.park@lge.com> Signed-off-by: Andrew Morton <akpm@linux-foundation.org> --- mm/huge_memory.c | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) --- a/mm/huge_memory.c~mm-huge_memory-fix-outdated-comment-about-freeing-subpages-in-__folio_split +++ a/mm/huge_memory.c @@ -4190,11 +4190,10 @@ fail: folio_unlock(new_folio); /* - * Subpages may be freed if there wasn't any mapping - * like if add_to_swap() is running on a lru page that - * had its mapping zapped. And freeing these pages - * requires taking the lru_lock so we do the put_page - * of the tail pages after the split is complete. + * Subpages whose mapping has been zapped may be freed + * earlier, but freeing them requires taking the + * lru_lock, so we defer put_page() on tail pages until + * after the split completes. */ free_folio_and_swap_cache(new_folio); } _
On Tue, Apr 28, 2026 at 9:01 PM Andrew Morton <akpm@linux-foundation.org> wrote: > > On Tue, 28 Apr 2026 18:32:40 +0800 Barry Song <baohua@kernel.org> wrote: > > > On Tue, Apr 28, 2026 at 6:08 PM David Hildenbrand (Arm) > > <david@kernel.org> wrote: > > > > > > On 4/28/26 12:05, Barry Song wrote: > > > > On Mon, Apr 27, 2026 at 3:42 PM David Hildenbrand (Arm) > > > > <david@kernel.org> wrote: > > > >> > > > >> On 4/26/26 22:42, Barry Song wrote: > > > >>> On Thu, Apr 23, 2026 at 8:36 PM David Hildenbrand (Arm) > > > >>> <david@kernel.org> wrote: > > > >>> > > > >>> Thanks, david! would it make more sense to add “when > > > >>> CONFIG_PAGE_MAPCOUNT is enabled” at the end of the > > > >>> sentence? > > > >> > > > >> Better to phrase it in a way that doesn't even require these details :) > > > >> > > > >> Do we even need this detail in the patch description? > > > > > > > > What about: > > > > > > > > The comment appears to be outdated. add_to_swap() no longer exists, > > > > and the explanation of why we need to call put_page() after > > > > splitting could be made more general. > > > > > > Jup :) > > > > Thanks! > > Hi Andrew, would you like to make the change in the > > changelog, or would you prefer that I send a new version? > > This? Yes, exactly. Thanks very much! > > From: "Barry Song (Xiaomi)" <baohua@kernel.org> > Subject: mm/huge_memory: fix outdated comment about freeing subpages in __folio_split > Date: Thu, 23 Apr 2026 11:49:17 +0800 > > The comment appears to be outdated. add_to_swap() no longer exists, > and the explanation of why we need to call put_page() after splitting > could be made more general.
© 2016 - 2026 Red Hat, Inc.