Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

mm/compaction: fix bug in hugetlb handling pathway

The compaction code doesn't take references on pages until we're certain
we should attempt to handle it.

In the hugetlb case, isolate_or_dissolve_huge_page() may return -EBUSY
without taking a reference to the folio associated with our pfn. If our
folio's refcount drops to 0, compound_nr() becomes unpredictable, making
low_pfn and nr_scanned unreliable. The user-visible effect is minimal -
this should rarely happen (if ever).

Fix this by storing the folio statistics earlier on the stack (just like
the THP and Buddy cases).

Also revert commit 66fe1cf7f581 ("mm: compaction: use helper compound_nr
in isolate_migratepages_block") to make backporting easier.

Link: https://lkml.kernel.org/r/20250401021025.637333-1-vishal.moola@gmail.com
Fixes: 369fa227c219 ("mm: make alloc_contig_range handle free hugetlb pages")
Signed-off-by: Vishal Moola (Oracle) <vishal.moola@gmail.com>
Acked-by: Oscar Salvador <osalvador@suse.de>
Reviewed-by: Zi Yan <ziy@nvidia.com>
Cc: Miaohe Lin <linmiaohe@huawei.com>
Cc: Oscar Salvador <osalvador@suse.de>
Cc: <stable@vger.kernel.org>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>

authored by

Vishal Moola (Oracle) and committed by
Andrew Morton
a84edd52 770c8d55

+3 -3
+3 -3
mm/compaction.c
··· 981 981 } 982 982 983 983 if (PageHuge(page)) { 984 + const unsigned int order = compound_order(page); 984 985 /* 985 986 * skip hugetlbfs if we are not compacting for pages 986 987 * bigger than its order. THPs and other compound pages 987 988 * are handled below. 988 989 */ 989 990 if (!cc->alloc_contig) { 990 - const unsigned int order = compound_order(page); 991 991 992 992 if (order <= MAX_PAGE_ORDER) { 993 993 low_pfn += (1UL << order) - 1; ··· 1011 1011 /* Do not report -EBUSY down the chain */ 1012 1012 if (ret == -EBUSY) 1013 1013 ret = 0; 1014 - low_pfn += compound_nr(page) - 1; 1015 - nr_scanned += compound_nr(page) - 1; 1014 + low_pfn += (1UL << order) - 1; 1015 + nr_scanned += (1UL << order) - 1; 1016 1016 goto isolate_fail; 1017 1017 } 1018 1018