|  | 
| 48 | 48 | #include <linux/page_owner.h> | 
| 49 | 49 | #include "internal.h" | 
| 50 | 50 | #include "hugetlb_vmemmap.h" | 
|  | 51 | +#include <linux/page-isolation.h> | 
| 51 | 52 | 
 | 
| 52 | 53 | int hugetlb_max_hstate __read_mostly; | 
| 53 | 54 | unsigned int default_hstate_idx; | 
| @@ -1336,6 +1337,9 @@ static struct folio *dequeue_hugetlb_folio_node_exact(struct hstate *h, | 
| 1336 | 1337 | 		if (folio_test_hwpoison(folio)) | 
| 1337 | 1338 | 			continue; | 
| 1338 | 1339 | 
 | 
|  | 1340 | +		if (is_migrate_isolate_page(&folio->page)) | 
|  | 1341 | +			continue; | 
|  | 1342 | + | 
| 1339 | 1343 | 		list_move(&folio->lru, &h->hugepage_activelist); | 
| 1340 | 1344 | 		folio_ref_unfreeze(folio, 1); | 
| 1341 | 1345 | 		folio_clear_hugetlb_freed(folio); | 
| @@ -2975,6 +2979,44 @@ int isolate_or_dissolve_huge_page(struct page *page, struct list_head *list) | 
| 2975 | 2979 | 	return ret; | 
| 2976 | 2980 | } | 
| 2977 | 2981 | 
 | 
|  | 2982 | +/* | 
|  | 2983 | + *  replace_free_hugepage_folios - Replace free hugepage folios in a given pfn | 
|  | 2984 | + *  range with new folios. | 
|  | 2985 | + *  @start_pfn: start pfn of the given pfn range | 
|  | 2986 | + *  @end_pfn: end pfn of the given pfn range | 
|  | 2987 | + *  Returns 0 on success, otherwise negated error. | 
|  | 2988 | + */ | 
|  | 2989 | +int replace_free_hugepage_folios(unsigned long start_pfn, unsigned long end_pfn) | 
|  | 2990 | +{ | 
|  | 2991 | +	struct hstate *h; | 
|  | 2992 | +	struct folio *folio; | 
|  | 2993 | +	int ret = 0; | 
|  | 2994 | + | 
|  | 2995 | +	LIST_HEAD(isolate_list); | 
|  | 2996 | + | 
|  | 2997 | +	while (start_pfn < end_pfn) { | 
|  | 2998 | +		folio = pfn_folio(start_pfn); | 
|  | 2999 | +		if (folio_test_hugetlb(folio)) { | 
|  | 3000 | +			h = folio_hstate(folio); | 
|  | 3001 | +		} else { | 
|  | 3002 | +			start_pfn++; | 
|  | 3003 | +			continue; | 
|  | 3004 | +		} | 
|  | 3005 | + | 
|  | 3006 | +		if (!folio_ref_count(folio)) { | 
|  | 3007 | +			ret = alloc_and_dissolve_hugetlb_folio(h, folio, | 
|  | 3008 | +							       &isolate_list); | 
|  | 3009 | +			if (ret) | 
|  | 3010 | +				break; | 
|  | 3011 | + | 
|  | 3012 | +			putback_movable_pages(&isolate_list); | 
|  | 3013 | +		} | 
|  | 3014 | +		start_pfn++; | 
|  | 3015 | +	} | 
|  | 3016 | + | 
|  | 3017 | +	return ret; | 
|  | 3018 | +} | 
|  | 3019 | + | 
| 2978 | 3020 | struct folio *alloc_hugetlb_folio(struct vm_area_struct *vma, | 
| 2979 | 3021 | 				    unsigned long addr, int avoid_reserve) | 
| 2980 | 3022 | { | 
|  | 
0 commit comments