From 0b6c487acdd2c1054a64c7c04746f6aa2ebd642a Mon Sep 17 00:00:00 2001 From: "Liam R. Howlett" Date: Sun, 5 Sep 2021 23:31:15 -0400 Subject: [PATCH] mmap: Change zeroing of maple tree in __vma_adjust 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 --- mm/mmap.c | 22 +++++++++++++--------- 1 file changed, 13 insertions(+), 9 deletions(-) diff --git a/mm/mmap.c b/mm/mmap.c index ff158583ee09c..a732f116f0ecf 100644 --- a/mm/mmap.c +++ b/mm/mmap.c @@ -579,7 +579,6 @@ static void vma_link(struct mm_struct *mm, struct vm_area_struct *vma) */ static void __insert_vm_struct(struct mm_struct *mm, struct vm_area_struct *vma) { - BUG_ON(find_vma_intersection(mm, vma->vm_start, vma->vm_end)); vma_mt_store(mm, vma); mm->map_count++; } @@ -698,6 +697,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; @@ -823,23 +823,27 @@ 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 (vma_changed) + if (vma_changed) { vma_mt_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) { -- 2.50.1