Skip to contentSkip to conversation

page_alloc: allow migration of smaller hugepages during contig_alloc.

PATCH Superseded Gregory Price 4 participants 5 messages Oct 24, 2025 – Nov 6, 2025

Subsystems (2)

v3 of 7 Superseded Latest is v7 →

lore
Share & tools
lore
#0 lore raw

PATCH v3 1/1 page_alloc: allow migration of smaller hugepages during contig_alloc.

We presently skip regions with hugepages entirely when trying to do contiguous page allocation. Instead, if hugepage migration is enabled, consider regions with hugepages smaller than the target contiguous allocation request as valid targets for allocation.

isolate_migrate_pages_block() already expects requests with hugepages to originate from alloc_contig, and hugetlb code also does a migratable check when isolating in folio_isolate_hugetlb().

---
 mm/page_alloc.c | 15 +++++++++++++--
 1 file changed, 13 insertions(+), 2 deletions(-)
mm/page_alloc.c +13 -2
index 600d9e981c23..23866d4c26ff 100644
@@ -7048,8 +7048,19 @@ static bool pfn_range_valid_contig(struct zone *z, unsigned long start_pfn,
 		if (PageReserved(page))
 			return false;
 
-		if (PageHuge(page))
-			return false;
+		if (PageHuge(page)) {
+			unsigned int order;
+
+			if (!IS_ENABLED(CONFIG_ARCH_ENABLE_HUGEPAGE_MIGRATION))
+				return false;
+
+			/* Don't consider moving same size/larger pages */
+			page = compound_head(page);
+			order = compound_order(page);
+			if ((order >= MAX_FOLIO_ORDER) ||
+			    (nr_pages <= (1 << order)))
+				return false;
+		}
 	}
 	return true;
 }
Signature · 1 line
2.51.0
Acked-by on v3 1/1
#1 lore raw
Quoted 5 lines · Gregory Price

We presently skip regions with hugepages entirely when trying to do contiguous page allocation. Instead, if hugepage migration is enabled, consider regions with hugepages smaller than the target contiguous allocation request as valid targets for allocation.

Quoted 8 lines

isolate_migrate_pages_block() already expects requests with hugepages to originate from alloc_contig, and hugetlb code also does a migratable check when isolating in folio_isolate_hugetlb().

Reviewed-by on v3 1/1
#2 lore raw
In reply to Gregory Price
Quoted 5 lines · Gregory Price

We presently skip regions with hugepages entirely when trying to do contiguous page allocation. Instead, if hugepage migration is enabled, consider regions with hugepages smaller than the target contiguous allocation request as valid targets for allocation.

Quoted 8 lines

isolate_migrate_pages_block() already expects requests with hugepages to originate from alloc_contig, and hugetlb code also does a migratable check when isolating in folio_isolate_hugetlb().

Signature · 2 lines
Oscar Salvador
SUSE Labs
Acked-by on v3 1/1
#3 lore raw
In reply to Gregory Price
Quoted 9 lines · Gregory Price

We presently skip regions with hugepages entirely when trying to do contiguous page allocation. Instead, if hugepage migration is enabled, consider regions with hugepages smaller than the target contiguous allocation request as valid targets for allocation.

isolate_migrate_pages_block() already expects requests with hugepages to originate from alloc_contig, and hugetlb code also does a migratable check when isolating in folio_isolate_hugetlb().

Quoted 5 lines

---

Nit: trailing "." in subject

Signature · 3 lines
Cheers

David / dhildenb
#4 lore raw
Quoted 16 lines · David Hildenbrand
Quoted 9 lines · Gregory Price

We presently skip regions with hugepages entirely when trying to do contiguous page allocation. Instead, if hugepage migration is enabled, consider regions with hugepages smaller than the target contiguous allocation request as valid targets for allocation.

isolate_migrate_pages_block() already expects requests with hugepages to originate from alloc_contig, and hugetlb code also does a migratable check when isolating in folio_isolate_hugetlb().

Quoted 5 lines

---

Quoted 4 lines

Nit: trailing "." in subject

Hi David,

Do you think i should just staple these commits together at this point?

https://lore.kernel.org/linux-mm/[email protected]/

If not i'll drop the '.' and just resubmit this with tags and just update the commit message on movable_gigantic_pages to reference this commit and your notes from there.

~Gregory