[RFC PATCH 49/57] mm/khugepaged: drop the mmap_lock barrier from __khugepaged_exit()
From: Kiryl Shutsemau
Date: Sun Aug 16 2026 - 18:59:01 EST
From: "Kiryl Shutsemau (Meta)" <kas@xxxxxxxxxx>
__khugepaged_exit() took mmap_lock for writing and dropped it again, to
wait for a scan holding it for reading before exit_mmap() destroyed the
page tables underneath it.
A scan now holds a reference on mm_users for as long as it runs, so it
cannot be in flight here at all: __mmput() runs only once that count has
reached zero, and asserts so on entry. The barrier is redundant.
Assisted-by: Claude-Code:claude-opus-5
Signed-off-by: Kiryl Shutsemau (Meta) <kas@xxxxxxxxxx>
---
mm/khugepaged.c | 10 ----------
1 file changed, 10 deletions(-)
diff --git a/mm/khugepaged.c b/mm/khugepaged.c
index 1d77d9a8046d..2b3364bdb100 100644
--- a/mm/khugepaged.c
+++ b/mm/khugepaged.c
@@ -434,16 +434,6 @@ void __khugepaged_exit(struct mm_struct *mm)
mm_flags_clear(MMF_VM_HUGEPAGE, mm);
mm_slot_free(mm_slot_cache, slot);
mmdrop(mm);
- } else if (slot) {
- /*
- * This is required to serialize against
- * collapse_test_exit() (which is guaranteed to run
- * under mmap_lock read mode). Stop here (after we return all
- * pagetables will be destroyed) until khugepaged has finished
- * working on the pagetables under the mmap_lock.
- */
- mmap_write_lock(mm);
- mmap_write_unlock(mm);
}
}
--
2.54.0