Skip to content

Commit 14efb47

Browse files
x-y-zakpm00
authored andcommitted
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. Link: https://lkml.kernel.org/r/[email protected] Fixes: c010d47 ("mm: thp: split huge page to any lower order pages") Signed-off-by: Zi Yan <[email protected]> Reported-by: Hugh Dickins <[email protected]> Closes: https://lore.kernel.org/all/[email protected]/ 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]> Cc: <[email protected]> Signed-off-by: Andrew Morton <[email protected]>
1 parent 67a2f86 commit 14efb47

File tree

1 file changed

+1
-1
lines changed

1 file changed

+1
-1
lines changed

mm/huge_memory.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3304,7 +3304,7 @@ static void __split_huge_page(struct page *page, struct list_head *list,
33043304
folio_account_cleaned(tail,
33053305
inode_to_wb(folio->mapping->host));
33063306
__filemap_remove_folio(tail, NULL);
3307-
folio_put(tail);
3307+
folio_put_refs(tail, folio_nr_pages(tail));
33083308
} else if (!folio_test_anon(folio)) {
33093309
__xa_store(&folio->mapping->i_pages, tail->index,
33103310
tail, 0);

0 commit comments

Comments
 (0)