Skip to contentSkip to conversation

FAILED: patch "[PATCH] mm/huge_memory: drop beyond-EOF folios with the right number" failed to apply to 6.12-stable tree

PATCH In review [email protected] 3 participants 3 messages Mar 24, 2025 – Mar 25, 2025

Subsystems (3)
lore
Share & tools
lore

[email protected]

author maintainer
#0 lore raw

The patch below does not apply to the 6.12-stable tree.
If someone wants it applied there, or to any other stable or longterm tree, then please email the backport, including the original git commit id to <[email protected]>.

To reproduce the conflict and resubmit, you may use the following commands:

git fetch https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git/ linux-6.12.y
git checkout FETCH_HEAD
git cherry-pick -x 14efb4793519d73fb2902bb0ece319b886e4b4b9
# <resolve conflicts, build, test, etc.>
git commit -s
git send-email --to '<[email protected]>' --in-reply-to '2025032430-granny-hunter-c6a5@gregkh' --subject-prefix 'PATCH 6.12.y' HEAD^..

Possible dependencies:

thanks,

greg k-h

------------------ original commit in Linus's tree ------------------

From 14efb4793519d73fb2902bb0ece319b886e4b4b9 Mon Sep 17 00:00:00 2001
From: Zi Yan <[email protected]>
Date: Mon, 10 Mar 2025 11:57:27 -0400
Subject: [PATCH] mm/huge_memory: drop beyond-EOF folios with the right number
of refs

When an after-split folio is large and needs to be dropped due to EOF, folio_put_refs(folio, folio_nr_pages(folio)) should be used to drop all page cache refs. Otherwise, the folio will not be freed, causing memory leak.

This leak would happen on a filesystem with blocksize > page_size and a truncate is performed, where the blocksize makes folios split to >0 order ones, causing truncated folios not being freed.

Fixes c010d47f107f ("mm: thp: split huge page to any lower order pages")
Cc Baolin Wang <[email protected]>
Cc David Hildenbrand <[email protected]>
Cc John Hubbard <[email protected]>
Cc Kefeng Wang <[email protected]>
Cc Kirill A. Shuemov <[email protected]>
Cc Luis Chamberalin <[email protected]>
Cc Matthew Wilcow (Oracle) <[email protected]>
Cc Miaohe Lin <[email protected]>
Cc Pankaj Raghav <[email protected]>
Cc Ryan Roberts <[email protected]>
Cc Yang Shi <[email protected]>
Cc Yu Zhao <[email protected]>
mm/huge_memory.c +1 -1
index 3d3ebdc002d5..373781b21e5c 100644
@@ -3304,7 +3304,7 @@ static void __split_huge_page(struct page *page, struct list_head *list,
 				folio_account_cleaned(tail,
 					inode_to_wb(folio->mapping->host));
 			__filemap_remove_folio(tail, NULL);
-			folio_put(tail);
+			folio_put_refs(tail, folio_nr_pages(tail));
 		} else if (!folio_test_anon(folio)) {
 			__xa_store(&folio->mapping->i_pages, tail->index,
 					tail, 0);
reviewer
#1 lore raw

PATCH 1/1 mm/huge_memory: drop beyond-EOF folios with the right number of refs

When an after-split folio is large and needs to be dropped due to EOF, folio_put_refs(folio, folio_nr_pages(folio)) should be used to drop all page cache refs. Otherwise, the folio will not be freed, causing memory leak.

This leak would happen on a filesystem with blocksize > page_size and a truncate is performed, where the blocksize makes folios split to >0 order ones, causing truncated folios not being freed.

Fixes c010d47f107f ("mm: thp: split huge page to any lower order pages")
Cc Baolin Wang <[email protected]>
Cc David Hildenbrand <[email protected]>
Cc John Hubbard <[email protected]>
Cc Kefeng Wang <[email protected]>
Cc Kirill A. Shuemov <[email protected]>
Cc Luis Chamberalin <[email protected]>
Cc Matthew Wilcow (Oracle) <[email protected]>
Cc Miaohe Lin <[email protected]>
Cc Pankaj Raghav <[email protected]>
Cc Ryan Roberts <[email protected]>
Cc Yang Shi <[email protected]>
Cc Yu Zhao <[email protected]>
(cherry picked from commit 14efb4793519d73fb2902bb0ece319b886e4b4b9)
---
 mm/huge_memory.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
mm/huge_memory.c +1 -1
index f127b61f04a8..40ac11e29423 100644
@@ -3224,7 +3224,7 @@ static void __split_huge_page(struct page *page, struct list_head *list,
 				folio_account_cleaned(tail,
 					inode_to_wb(folio->mapping->host));
 			__filemap_remove_folio(tail, NULL);
-			folio_put(tail);
+			folio_put_refs(tail, folio_nr_pages(tail));
 		} else if (!PageAnon(page)) {
 			__xa_store(&folio->mapping->i_pages, head[i].index,
 					head + i, 0);
Signature · 1 line
2.47.2
maintainer
#2 lore raw

Re: [PATCH 6.12.y] mm/huge_memory: drop beyond-EOF folios with the right number of refs

[ Sasha's backport helper bot ]

Hi,

Summary of potential issues:
⚠️ Found matching upstream commit but patch is missing proper reference to it

Found matching upstream commit: 14efb4793519d73fb2902bb0ece319b886e4b4b9

Status in newer kernel trees:
6.13.y | Not found

Note: The patch differs from the upstream commit:
---
1: 14efb4793519d ! 1: 8e2adc6066c3d mm/huge_memory: drop beyond-EOF folios with the right number of refs
@@ Commit message

+ (cherry picked from commit 14efb4793519d73fb2902bb0ece319b886e4b4b9)

## mm/huge_memory.c ##
@@ mm/huge_memory.c: static void __split_huge_page(struct page *page, struct list_head *list,
@@ mm/huge_memory.c: static void __split_huge_page(struct page *page, struct list_h
__filemap_remove_folio(tail, NULL);
- folio_put(tail);
+ folio_put_refs(tail, folio_nr_pages(tail));
- } else if (!folio_test_anon(folio)) {
- __xa_store(&folio->mapping->i_pages, tail->index,
- tail, 0);
+ } else if (!PageAnon(page)) {
+ __xa_store(&folio->mapping->i_pages, head[i].index,
+ head + i, 0);
---

Results of testing on various branches:

| Branch                    | Patch Apply | Build Test |
|---------------------------|-------------|------------|
| stable/linux-6.12.y       |  Success    |  Success   |