Skip to content

Commit dac2a4f

Browse files
Frank van der Lindenakpm00
authored andcommitted
mm/hugetlb: copy the CMA flag when demoting
Since commit d2d7867 ("mm/hugetlb: enable bootmem allocation from CMA areas"), a flag is used to mark hugetlb folios as allocated from CMA. This flag is also used to decide if it should be freed to CMA. However, the flag isn't copied to the smaller folios when a hugetlb folio is broken up for demotion, which would cause it to be freed incorrectly. Fix this by copying the flag to the smaller order hugetlb pages created from the original one. Link: https://lkml.kernel.org/r/20250501044325.20365-1-fvdl@google.com Fixes: d2d7867 ("mm/hugetlb: enable bootmem allocation from CMA areas") Signed-off-by: Frank van der Linden <fvdl@google.com> Reviewed-by: Anshuman Khandual <anshuman.khandual@arm.com> Reviewed-by: Oscar Salvador <osalvador@suse.de> Reviewed-by: Jane Chu <Jane.Chu@oracle.com> Cc: Muchun Song <muchun.song@linux.dev> Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
1 parent 9a9794a commit dac2a4f

File tree

1 file changed

+6
-0
lines changed

1 file changed

+6
-0
lines changed

mm/hugetlb.c

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4034,10 +4034,13 @@ static long demote_free_hugetlb_folios(struct hstate *src, struct hstate *dst,
40344034

40354035
list_for_each_entry_safe(folio, next, src_list, lru) {
40364036
int i;
4037+
bool cma;
40374038

40384039
if (folio_test_hugetlb_vmemmap_optimized(folio))
40394040
continue;
40404041

4042+
cma = folio_test_hugetlb_cma(folio);
4043+
40414044
list_del(&folio->lru);
40424045

40434046
split_page_owner(&folio->page, huge_page_order(src), huge_page_order(dst));
@@ -4053,6 +4056,9 @@ static long demote_free_hugetlb_folios(struct hstate *src, struct hstate *dst,
40534056

40544057
new_folio->mapping = NULL;
40554058
init_new_hugetlb_folio(dst, new_folio);
4059+
/* Copy the CMA flag so that it is freed correctly */
4060+
if (cma)
4061+
folio_set_hugetlb_cma(new_folio);
40564062
list_add(&new_folio->lru, &dst_list);
40574063
}
40584064
}

0 commit comments

Comments
 (0)