Skip to contentSkip to conversation

mm-mmap-reorganize-munmap-to-use-maple-states.patch removed from -mm tree

merged mm-stable Andrew Morton 1 participant 1 message Sep 27, 2022

lore
Share & tools
lore

Andrew Morton

author tree notice Applied
#0 lore raw

The quilt patch titled
Subject: mm/mmap: reorganize munmap to use maple states
has been removed from the -mm tree. Its filename was
mm-mmap-reorganize-munmap-to-use-maple-states.patch

This patch was dropped because it was merged into the mm-stable branch of git://git.kernel.org/pub/scm/linux/kernel/git/akpm/mm

------------------------------------------------------
From: "Liam R. Howlett" <[email protected]>
Subject: mm/mmap: reorganize munmap to use maple states
Date: Tue, 6 Sep 2022 19:48:52 +0000

Remove __do_munmap() in favour of do_munmap(), do_mas_munmap(), and do_mas_align_munmap().

do_munmap() is a wrapper to create a maple state for any callers that have not been converted to the maple tree.

do_mas_munmap() takes a maple state to mumap a range. This is just a small function which checks for error conditions and aligns the end of the range.

do_mas_align_munmap() uses the aligned range to mumap a range. do_mas_align_munmap() starts with the first VMA in the range, then finds the last VMA in the range. Both start and end are split if necessary. Then the VMAs are removed from the linked list and the mm mlock count is updated at the same time. Followed by a single tree operation of overwriting the area in with a NULL. Finally, the detached list is unmapped and freed.

By reorganizing the munmap calls as outlined, it is now possible to avoid extra work of aligning pre-aligned callers which are known to be safe, avoid extra VMA lookups or tree walks for modifications.

detach_vmas_to_be_unmapped() is no longer used, so drop this code.

vm_brk_flags() can just call the do_mas_munmap() as it checks for intersecting VMAs directly.

Cc Catalin Marinas <[email protected]>
Cc David Hildenbrand <[email protected]>
Cc David Howells <[email protected]>
Cc Davidlohr Bueso <[email protected]>
Cc "Matthew Wilcox (Oracle)" <[email protected]>
Cc SeongJae Park <[email protected]>
Cc Sven Schnelle <[email protected]>
Cc Vlastimil Babka <[email protected]>
Cc Will Deacon <[email protected]>

---

 include/linux/mm.h |    5 
 mm/mmap.c          |  228 +++++++++++++++++++++++++++----------------
 mm/mremap.c        |   17 +--
 3 files changed, 158 insertions(+), 92 deletions(-)
include/linux/mm.h renamed from include/linux/mm.h~mm-mmap-reorganize-munmap-to-use-maple-states +3 -2
@@ -2710,8 +2710,9 @@ extern unsigned long mmap_region(struct
 extern unsigned long do_mmap(struct file *file, unsigned long addr,
 	unsigned long len, unsigned long prot, unsigned long flags,
 	unsigned long pgoff, unsigned long *populate, struct list_head *uf);
-extern int __do_munmap(struct mm_struct *, unsigned long, size_t,
-		       struct list_head *uf, bool downgrade);
+extern int do_mas_munmap(struct ma_state *mas, struct mm_struct *mm,
+			 unsigned long start, size_t len, struct list_head *uf,
+			 bool downgrade);
 extern int do_munmap(struct mm_struct *, unsigned long, size_t,
 		     struct list_head *uf);
 extern int do_madvise(struct mm_struct *mm, unsigned long start, size_t len_in, int behavior);
mm/mmap.c renamed from mm/mmap.c~mm-mmap-reorganize-munmap-to-use-maple-states +145 -83

313 lines not on this page · raw message

mm/mremap.c renamed from mm/mremap.c~mm-mmap-reorganize-munmap-to-use-maple-states +10 -7
@@ -975,20 +975,23 @@ SYSCALL_DEFINE5(mremap, unsigned long, a
 	/*
 	 * Always allow a shrinking remap: that just unmaps
 	 * the unnecessary pages..
-	 * __do_munmap does all the needed commit accounting, and
+	 * do_mas_munmap does all the needed commit accounting, and
 	 * downgrades mmap_lock to read if so directed.
 	 */
 	if (old_len >= new_len) {
 		int retval;
+		MA_STATE(mas, &mm->mm_mt, addr + new_len, addr + new_len);
 
-		retval = __do_munmap(mm, addr+new_len, old_len - new_len,
-				  &uf_unmap, true);
-		if (retval < 0 && old_len != new_len) {
-			ret = retval;
-			goto out;
+		retval = do_mas_munmap(&mas, mm, addr + new_len,
+				       old_len - new_len, &uf_unmap, true);
 		/* Returning 1 indicates mmap_lock is downgraded to read. */
-		} else if (retval == 1)
+		if (retval == 1) {
 			downgraded = true;
+		} else if (retval < 0 && old_len != new_len) {
+			ret = retval;
+			goto out;
+		}
+
 		ret = addr;
 		goto out;
 	}

_

Patches currently in -mm which might be from [email protected] are