Skip to contentSkip to conversation

mm/huge_memory: Fix outdated comment about freeing subpages in __folio_split

PATCH Applied Barry Song (Xiaomi) 4 participants 10 messages Apr 23 – Apr 28

Subsystems (2)
lore
Share & tools
lore

Barry Song (Xiaomi)

author reviewer
#0 lore raw

PATCH 1/1 mm/huge_memory: Fix outdated comment about freeing subpages in __folio_split

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 <[email protected]>
Cc Lorenzo Stoakes <[email protected]>
Cc Zi Yan <[email protected]>
Cc Baolin Wang <[email protected]>
Cc "Liam R. Howlett" <[email protected]>
Cc Nico Pache <[email protected]>
Cc Ryan Roberts <[email protected]>
Cc Dev Jain <[email protected]>
Cc Lance Yang <[email protected]>
Cc Chris Li <[email protected]>
Cc Kairui Song <[email protected]>
Cc Kemeng Shi <[email protected]>
Cc Nhat Pham <[email protected]>
Cc Baoquan He <[email protected]>
Cc Youngjun Park <[email protected]>
---
 mm/huge_memory.c | 9 ++++-----
 1 file changed, 4 insertions(+), 5 deletions(-)
mm/huge_memory.c +4 -5
index 970e077019b7..4586f3ccb133 100644
@@ -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);
 	}
Signature · 1 line
2.39.3 (Apple Git-146)
maintainer Acked-by on v1 1/1
#1 lore raw
Quoted 6 lines · Barry Song (Xiaomi)

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).

Quoted 32 lines

Fix this by making the description more generic.

Cc David Hildenbrand <[email protected]>
Cc Lorenzo Stoakes <[email protected]>
Cc Zi Yan <[email protected]>
Cc Baolin Wang <[email protected]>
Cc "Liam R. Howlett" <[email protected]>
Cc Nico Pache <[email protected]>
Cc Ryan Roberts <[email protected]>
Cc Dev Jain <[email protected]>
Cc Lance Yang <[email protected]>
Cc Chris Li <[email protected]>
Cc Kairui Song <[email protected]>
Cc Kemeng Shi <[email protected]>
Cc Nhat Pham <[email protected]>
Cc Baoquan He <[email protected]>
Cc Youngjun Park <[email protected]>
---
 mm/huge_memory.c | 9 ++++-----
 1 file changed, 4 insertions(+), 5 deletions(-)
mm/huge_memory.c +0 -2
index 970e077019b7..4586f3ccb133 100644
@@ -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

mm/huge_memory.c static int __folio_split(struct folio *folio, unsigned int new_order, · line 4199

Quoted 10 lines
mm/huge_memory.c +4 -3
-		 * 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);
 	}
Signature · 3 lines
Cheers,

David
author reviewer
#2 lore raw
Quoted 11 lines · David Hildenbrand (Arm)
Quoted 6 lines · Barry Song (Xiaomi)

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. "

Quoted 29 lines
Quoted 29 lines

Fix this by making the description more generic.

Cc David Hildenbrand <[email protected]>
Cc Lorenzo Stoakes <[email protected]>
Cc Zi Yan <[email protected]>
Cc Baolin Wang <[email protected]>
Cc "Liam R. Howlett" <[email protected]>
Cc Nico Pache <[email protected]>
Cc Ryan Roberts <[email protected]>
Cc Dev Jain <[email protected]>
Cc Lance Yang <[email protected]>
Cc Chris Li <[email protected]>
Cc Kairui Song <[email protected]>
Cc Kemeng Shi <[email protected]>
Cc Nhat Pham <[email protected]>
Cc Baoquan He <[email protected]>
Cc Youngjun Park <[email protected]>
---
 mm/huge_memory.c | 9 ++++-----
 1 file changed, 4 insertions(+), 5 deletions(-)
mm/huge_memory.c +0 -0
index 970e077019b7..4586f3ccb133 100644
@@ -4190,11 +4190,10 @@ static int __folio_split(struct folio *folio, unsigned int new_order,
 
Quoted 16 lines
Quoted 4 lines
mm/huge_memory.c +0 -2
              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

mm/huge_memory.c static int __folio_split(struct folio *folio, unsigned int new_order, · line 4199

Quoted 10 lines
mm/huge_memory.c +4 -3
-              * 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);
      }

Thanks for reviewing!

Best Regards,
Barry

#3 lore raw
Quoted 11 lines · Barry Song
Quoted 9 lines · David Hildenbrand (Arm)
Quoted 6 lines · Barry Song (Xiaomi)

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()").

Quoted 6 lines
Quoted 2 lines

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?

Signature · 3 lines
Cheers,

David
author reviewer
#4 lore raw
Quoted 16 lines · David Hildenbrand (Arm)
Quoted 14 lines · Barry Song
Quoted 11 lines · David Hildenbrand (Arm)
Quoted 6 lines · Barry Song (Xiaomi)

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).

Quoted 7 lines
Quoted 3 lines

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

#5 lore raw
Quoted 13 lines · Barry Song
Quoted 11 lines · David Hildenbrand (Arm)
Quoted 6 lines · Barry Song

On Thu, Apr 23, 2026 at 8:36 PM David Hildenbrand (Arm) <[email protected]> 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 :)

Quoted 7 lines
Quoted 1 line

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 :)

Signature · 3 lines
Cheers,

David
author reviewer
#6 lore raw
Quoted 17 lines · David Hildenbrand (Arm)
Quoted 15 lines · Barry Song
Quoted 12 lines · David Hildenbrand (Arm)
Quoted 6 lines · Barry Song

On Thu, Apr 23, 2026 at 8:36 PM David Hildenbrand (Arm) <[email protected]> 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?

Quoted 7 lines
Quoted 5 lines

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

maintainer Acked-by David Hildenbrand (Arm) Acked-by Zi Yan
#7 lore raw
Quoted 25 lines · On Tue, 28 Apr 2026 18:32:40 +0800 Barry Song <[email protected]> wrote:
Quoted 23 lines · David Hildenbrand (Arm)
Quoted 20 lines · Barry Song
Quoted 5 lines · David Hildenbrand (Arm)
Quoted 3 lines · Barry Song

On Thu, Apr 23, 2026 at 8:36 PM David Hildenbrand (Arm) <[email protected]> wrote:

Quoted 7 lines
Quoted 3 lines

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.

Quoted 5 lines
Quoted 1 line

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)" <[email protected]>
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.

---

 mm/huge_memory.c |    9 ++++-----
 1 file changed, 4 insertions(+), 5 deletions(-)
mm/huge_memory.c renamed from mm/huge_memory.c~mm-huge_memory-fix-outdated-comment-about-freeing-subpages-in-__folio_split +4 -5
@@ -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);
 	}

_

author reviewer
#8 lore raw
Quoted 28 lines · Andrew Morton
Quoted 25 lines · On Tue, 28 Apr 2026 18:32:40 +0800 Barry Song <[email protected]> wrote:
Quoted 23 lines · David Hildenbrand (Arm)
Quoted 20 lines · Barry Song
Quoted 5 lines · David Hildenbrand (Arm)
Quoted 3 lines · Barry Song

On Thu, Apr 23, 2026 at 8:36 PM David Hildenbrand (Arm) <[email protected]> wrote:

Quoted 7 lines
Quoted 3 lines

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.

Quoted 7 lines
Quoted 5 lines
Quoted 1 line

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!

Quoted 8 lines

From: "Barry Song (Xiaomi)" <[email protected]>
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.

reviewer Acked-by on v1 1/1
#9 lore raw
In reply to Barry Song (Xiaomi)
Quoted 50 lines · Barry Song (Xiaomi)

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 <[email protected]>
Cc Lorenzo Stoakes <[email protected]>
Cc Zi Yan <[email protected]>
Cc Baolin Wang <[email protected]>
Cc "Liam R. Howlett" <[email protected]>
Cc Nico Pache <[email protected]>
Cc Ryan Roberts <[email protected]>
Cc Dev Jain <[email protected]>
Cc Lance Yang <[email protected]>
Cc Chris Li <[email protected]>
Cc Kairui Song <[email protected]>
Cc Kemeng Shi <[email protected]>
Cc Nhat Pham <[email protected]>
Cc Baoquan He <[email protected]>
Cc Youngjun Park <[email protected]>
---
 mm/huge_memory.c | 9 ++++-----
 1 file changed, 4 insertions(+), 5 deletions(-)
mm/huge_memory.c +4 -5
index 970e077019b7..4586f3ccb133 100644
@@ -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);
 	}
Signature · 1 line
2.39.3 (Apple Git-146)

--
Best Regards,
Yan, Zi