[PATCH v2 26/35] mm/rmap: don't fail unmapping hugetlb folios from private VMAs
From: David Hildenbrand (Arm)
Date: Thu Dec 03 2026 - 06:44:28 EST
Before unmapping a hugetlb page cache folio, try_to_migrate_one() and
try_to_unmap_poisoned_hugetlb_one() try to unshare the PMD table, which
requires the hugetlb VMA lock in write mode.
As we already hold the i_mmap_rwsem, we can only trylock it, and give up
if that fails.
Since private hugetlb VMAs have a VMA lock as well, the trylock can also
fail on private VMAs, for example while another thread is faulting in
that VMA. PMD table sharing does not apply in private VMAs, so there is
nothing to unshare and we fail for no reason: migration fails more
often, and memory failure might leave a poisoned folio mapped.
Let's fix it by only taking the VMA lock and trying to unshare if PMD
tables can be shared.
Fortunately, we can drop the anon folio checks now.
This has low urgency, as it requires racing with, for example, a page
fault in the private VMA, and migration is usually retried.
Fixes: bf4916922c60 ("hugetlbfs: extend hugetlb_vma_lock to private VMAs")
Cc: stable@xxxxxxxxxxxxxxx
Signed-off-by: David Hildenbrand (Arm) <david@xxxxxxxxxx>
---
mm/rmap.c | 6 ++----
1 file changed, 2 insertions(+), 4 deletions(-)
diff --git a/mm/rmap.c b/mm/rmap.c
index 4193793158bc1..b85ab855a438a 100644
--- a/mm/rmap.c
+++ b/mm/rmap.c
@@ -2049,7 +2049,7 @@ static bool try_to_unmap_poisoned_hugetlb_one(struct folio *folio,
* acquiring vma_lock BEFORE i_mmap_rwsem. We can only try lock here and
* fail if unsuccessful.
*/
- if (!folio_test_anon(folio)) {
+ if (__vma_shareable_lock(vma)) {
struct mmu_gather tlb;
VM_WARN_ON_ONCE(!(flags & TTU_RMAP_LOCKED));
@@ -2580,8 +2580,6 @@ static bool try_to_migrate_one(struct folio *folio, struct vm_area_struct *vma,
PageAnonExclusive(subpage);
if (folio_test_hugetlb(folio)) {
- bool anon = folio_test_anon(folio);
-
/*
* huge_pmd_unshare may unmap an entire PMD page.
* There is no way of knowing exactly which PMDs may
@@ -2601,7 +2599,7 @@ static bool try_to_migrate_one(struct folio *folio, struct vm_area_struct *vma,
* i_mmap_rwsem. We can only try lock here and
* fail if unsuccessful.
*/
- if (!anon) {
+ if (__vma_shareable_lock(vma)) {
struct mmu_gather tlb;
VM_BUG_ON(!(flags & TTU_RMAP_LOCKED));
--
2.56.1