Thread (119 messages) 119 messages, 9 authors, 13d ago
COOLING13d

[RFC PATCH 49/57] mm/khugepaged: drop the mmap_lock barrier from __khugepaged_exit()

From: Kiryl Shutsemau <hidden>
Date: 2026-08-16 22:47:49
Also in: bpf, linux-kselftest, linux-mm, lkml
Subsystem: memory management, memory management - thp (transparent huge page), the rest · Maintainers: Andrew Morton, David Hildenbrand, Linus Torvalds

From: "Kiryl Shutsemau (Meta)" <kas@kernel.org>

__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@kernel.org>
---
 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
Keyboard shortcuts
hback out one level
jnext message in thread
kprevious message in thread
ldrill in
Escclose help / fold thread tree
?toggle this help