]> www.infradead.org Git - users/jedix/linux-maple.git/commitdiff
mmap: Change zeroing of maple tree in __vma_adjust
authorLiam R. Howlett <Liam.Howlett@oracle.com>
Mon, 6 Sep 2021 03:31:15 +0000 (23:31 -0400)
committerMatthew Wilcox (Oracle) <willy@infradead.org>
Sat, 30 Oct 2021 03:37:29 +0000 (23:37 -0400)
Only write to the maple tree if we are not inserting or the insert isn't
going to overwrite the area to clear.  This avoids spanning writes and
node coealescing when unnecessary.

Signed-off-by: Liam R. Howlett <Liam.Howlett@oracle.com>
mm/mmap.c

index e6e128c09b9403114ec2c737cb653bba9750aa13..4308359ba3dc9de5b63273a9342b5ccc6fdcb1b8 100644 (file)
--- a/mm/mmap.c
+++ b/mm/mmap.c
@@ -615,6 +615,7 @@ int __vma_adjust(struct vm_area_struct *vma, unsigned long start,
        bool vma_changed = false;
        long adjust_next = 0;
        int remove_next = 0;
+       unsigned long old_start;
 
        if (next && !insert) {
                struct vm_area_struct *exporter = NULL, *importer = NULL;
@@ -740,25 +741,29 @@ again:
                        vma_interval_tree_remove(next, root);
        }
 
+       old_start = vma->vm_start;
        if (start != vma->vm_start) {
-               if (vma->vm_start < start)
-                       vma_mt_szero(mm, vma->vm_start, start);
-               else
-                       vma_changed = true;
+               vma_changed = true;
                vma->vm_start = start;
        }
        if (end != vma->vm_end) {
-               if (vma->vm_end > end)
-                       vma_mt_szero(mm, end, vma->vm_end);
-               else
+               if (vma->vm_end > end) {
+                       if (!insert || (insert && (insert->vm_start != end)))
+                               vma_mt_szero(mm, end, vma->vm_end);
+               } else
                        vma_changed = true;
                vma->vm_end = end;
                if (!next)
                        mm->highest_vm_end = vm_end_gap(vma);
        }
 
-       if (vma_changed)
+       if (vma_changed) {
                vma_store(mm, vma);
+               if (old_start < start) {
+                       if (insert && (insert->vm_start != old_start))
+                               vma_mt_szero(mm, old_start, start);
+               }
+       }
 
        vma->vm_pgoff = pgoff;
        if (adjust_next) {