mm: replace free hugepage folios after migration
Subsystems (2)
PATCH 1/1 mm: replace free hugepage folios after migration
From: yangge <[email protected]>
[ Upstream commit 04f13d241b8b146b23038bffd907cb8278391d07 ]
My machine has 4 NUMA nodes, each equipped with 32GB of memory. I have configured each NUMA node with 16GB of CMA and 16GB of in-use hugetlb pages. The allocation of contiguous memory via cma_alloc() can fail probabilistically.
When there are free hugetlb folios in the hugetlb pool, during the migration of in-use hugetlb folios, new folios are allocated from the free hugetlb pool. After the migration is completed, the old folios are released back to the free hugetlb pool instead of being returned to the buddy system. This can cause test_pages_isolated() check to fail, ultimately leading to the failure of cma_alloc().
Call trace:
cma_alloc()
__alloc_contig_migrate_range() // migrate in-use hugepage test_pages_isolated()
__test_page_isolated_in_pageblock()
PageBuddy(page) // check if the page is in buddy
To address this issue, we introduce a function named replace_free_hugepage_folios(). This function will replace the hugepage in the free hugepage pool with a new one and release the old one to the buddy system. After the migration of in-use hugetlb pages is completed, we will invoke replace_free_hugepage_folios() to ensure that these hugepages are properly released to the buddy system. Following this step, when test_pages_isolated() is executed for inspection, it will successfully pass.
Additionally, when alloc_contig_range() is used to migrate multiple in-use hugetlb pages, it can result in some in-use hugetlb pages being released back to the free hugetlb pool and subsequently being reallocated and used again. For example:
[huge 0] [huge 1]
To migrate huge 0, we obtain huge x from the pool. After the migration is completed, we return the now-freed huge 0 back to the pool. When it's time to migrate huge 1, we can simply reuse the now-freed huge 0 from the pool. As a result, when replace_free_hugepage_folios() is executed, it cannot release huge 0 back to the buddy system. To address this issue, we should prevent the reuse of isolated free hugepages during the migration process.
[ 5.10: Take only the dequeue_huge_page_node_exact() hunk, so memory
offline stops migrating huge pages back into the isolated range. ]
---
Without this, offlining a memory block holding mapped huge pages keeps migrating them back into the block until the offline is interrupted. Reproduced on arm64 on 5.10 and 6.12 (stock AL2023 6.12.113): the offline was still migrating after 60 s. With this patch on 5.10 it completes in 0.15 s with the data intact. Also sent for 5.10, 5.15, 6.1, 6.6 and 6.12.
mm/hugetlb.c | 4 ++++ 1 file changed, 4 insertions(+)
mm/hugetlb.c +4 -0
@@ -41,6 +41,7 @@#include <linux/node.h> #include <linux/userfaultfd_k.h> #include <linux/page_owner.h> +#include <linux/page-isolation.h> #include "internal.h" int hugetlb_max_hstate__read_mostly ;
@@ -1088,6 +1089,9 @@ static struct page *dequeue_huge_page_node_exact(struct hstate *h, int nid)if (PageHWPoison (page))continue ; +if (is_migrate_isolate_page (page)) +continue ; +list_move (&page->lru, &h->hugepage_activelist);set_page_refcounted (page);ClearPageHugeFreed (page);
Signature · 1 line
2.50.1
Sasha Levin
maintainerQuoted 1 line
[ Upstream commit
04f13d241b8b146b23038bffd907cb8278391d07]
These carry only the is_migrate_isolate_page() hunk of 04f13d241b8b ("mm:
replace free hugepage folios after migration"), which has no Cc: stable or
Fixes: tag upstream.
I need an ack from an mm maintainer (David or Andrew) on the reduced backport before queueing it for 5.10, 5.15, 6.1, 6.6 and 6.12.
Signature · 2 lines
Thanks, Sasha
David Hildenbrand (Arm)
Acked-byQuoted 9 lines · Sasha Levin
Quoted 1 line
[ Upstream commit
04f13d241b8b146b23038bffd907cb8278391d07]These carry only the
is_migrate_isolate_page()hunk of04f13d241b8b("mm:
replace free hugepage folios after migration"), which has no Cc: stable or
Fixes: tag upstream.I need an ack from an mm maintainer (David or Andrew) on the reduced backport before queueing it for 5.10, 5.15, 6.1, 6.6 and 6.12.
Looks alright, the other hunks are only relevant for migration support of hugetlb folios in alloc_contig_range(), which we didn't have in 5.10 IIUC.
Signature · 3 lines
Cheers, David
Sasha Levin
maintainerQuoted 1 line
[ Upstream commit
04f13d241b8b146b23038bffd907cb8278391d07]
David points out in the 5.15 thread that this reduced backport is only right for 5.10: 5.15, 6.1, 6.6 and 6.12 all have hugetlb migration in alloc_contig_range(), so they need the whole of 04f13d241b8b ("mm: replace free hugepage folios after migration"), including replace_free_hugepage_folios().
Could you respin 6.12, 6.6, 6.1 and 5.15 with the full backport? The acked 5.10 patch stays on hold until those newer trees are covered.
Signature · 2 lines
Thanks, Sasha
Quoted 2 lines · Sasha Levin
Could you respin 6.12, 6.6, 6.1 and 5.15 with the full backport? The acked 5.10 patch stays on hold until those newer trees are covered.
Will do. Thanks for the reviews all!