* [PATCH] hugetlb: Don't restore vmemmap of non-HVOed folios on bulk restore error
@ 2026-11-16 22:15 James Houghton
0 siblings, 0 replies; only message in thread
From: James Houghton @ 2026-11-16 22:15 UTC (permalink / raw)
To: Muchun Song, Oscar Salvador, David Hildenbrand, Andrew Morton
Cc: Mike Rapoport, linux-mm, linux-kernel, James Houghton
When hugetlb_vmemmap_restore_folios() fails, it stops processing the
list, so folio_list may still contain folios that were never vmemmap
optimized, e.g. because HVO failed when they were allocated. Their
hugetlb flag has already been cleared by remove_hugetlb_folio().
If no folios could be restored, bulk_vmemmap_restore_error() then calls
hugetlb_vmemmap_restore_folio() on every folio left on folio_list,
including those, which trips the !folio_test_hugetlb() check in
__hugetlb_vmemmap_restore_folio():
page dumped because: VM_WARN_ON_ONCE_FOLIO(!folio_test_hugetlb(folio))
WARNING: mm/hugetlb_vmemmap.c:503 at __hugetlb_vmemmap_restore_folio+0x270/0x300
...
__hugetlb_vmemmap_restore_folio+0x270/0x300 (P)
hugetlb_vmemmap_restore_folio+0x1c/0x30
update_and_free_pages_bulk+0x2c0/0x368
__nr_hugepages_store_common+0x2e8/0x3f0
Otherwise this is benign: the restore is a no-op returning success for
non-optimized folios, which are then freed as intended.
Skip the restore for folios that are not vmemmap optimized; they can be
freed right away.
This is very unlikely to happen without fault injection, as it requires
both HVO and a subsequent vmemmap restore to fail.
Fixes: cfb8c75099db ("hugetlb: perform vmemmap restoration on a list of pages")
Signed-off-by: James Houghton <jthoughton@google.com>
---
This patch was originally part of the series that enables the HugeTLB
vmemmap optimization (HVO) on arm64, here[1]. It has been modified given
the feedback received at [1]. Based on top of mm-unstable.
[1] https://lore.kernel.org/linux-mm/20261003002123.505555-2-jthoughton@google.com/
---
mm/hugetlb.c | 29 ++++++++++++++++++-----------
1 file changed, 18 insertions(+), 11 deletions(-)
diff --git a/mm/hugetlb.c b/mm/hugetlb.c
index cb2de24affdc..6e9f3fb04a3c 100644
--- a/mm/hugetlb.c
+++ b/mm/hugetlb.c
@@ -1628,21 +1628,28 @@ static void bulk_vmemmap_restore_error(struct hstate *h,
* If are able to restore vmemmap and free one hugetlb page, we
* quit processing the list to retry the bulk operation.
*/
- list_for_each_entry_safe(folio, t_folio, folio_list, lru)
- if (hugetlb_vmemmap_restore_folio(h, folio)) {
- list_del(&folio->lru);
- spin_lock_irq(&hugetlb_lock);
- add_hugetlb_folio(h, folio, true);
- spin_unlock_irq(&hugetlb_lock);
- } else {
- list_del(&folio->lru);
+ list_for_each_entry_safe(folio, t_folio, folio_list, lru) {
+ list_del(&folio->lru);
+ /*
+ * remove_hugetlb_folio() already cleared the hugetlb flag
+ * for folios whose vmemmap was not optimized, so they can
+ * be freed without restoring vmemmap.
+ */
+ if (folio_test_hugetlb(folio)) {
+ if (hugetlb_vmemmap_restore_folio(h, folio)) {
+ spin_lock_irq(&hugetlb_lock);
+ add_hugetlb_folio(h, folio, true);
+ spin_unlock_irq(&hugetlb_lock);
+ continue;
+ }
spin_lock_irq(&hugetlb_lock);
__folio_clear_hugetlb(folio);
spin_unlock_irq(&hugetlb_lock);
- update_and_free_hugetlb_folio(h, folio, false);
- cond_resched();
- break;
}
+ update_and_free_hugetlb_folio(h, folio, false);
+ cond_resched();
+ break;
+ }
}
}
base-commit: e1f34fb16e0236c4e60b5f392f1cf5aee76f7d0f
--
2.56.0.679.gc527c65306-goog
^ permalink raw reply related [flat|nested] only message in thread
only message in thread, other threads:[~2026-11-16 22:16 UTC | newest]
Thread overview: (only message) (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-11-16 22:15 [PATCH] hugetlb: Don't restore vmemmap of non-HVOed folios on bulk restore error James Houghton
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox