Skip to contentSkip to conversation

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

PATCH Applied Zi Yan 1 participant 1 message Mar 10, 2025

Subsystems (5)
lore
Share & tools
lore

Zi Yan

author reviewer
#0 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

Quoted 1 line

0 order ones, causing truncated folios not being freed.

Fixes c010d47f107f ("mm: thp: split huge page to any lower order pages")
---
 mm/huge_memory.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
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);
Signature · 1 line
2.47.2