From c497f6e54a906964b62ced67ab610a61953e573e Mon Sep 17 00:00:00 2001 From: "Liam R. Howlett" Date: Thu, 21 Apr 2022 13:11:36 -0400 Subject: [PATCH] mm/mmap: Optimize case 6 in __vma_adjust() Signed-off-by: Liam R. Howlett --- mm/mmap.c | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/mm/mmap.c b/mm/mmap.c index dbfd3576b6d0..01dd9af0b13e 100644 --- a/mm/mmap.c +++ b/mm/mmap.c @@ -641,7 +641,7 @@ int __vma_adjust(struct vm_area_struct *vma, unsigned long start, struct vm_area_struct *expand) { struct mm_struct *mm = vma->vm_mm; - struct vm_area_struct *next = find_vma(mm, vma->vm_end); + struct vm_area_struct *next_next, *next = find_vma(mm, vma->vm_end); struct vm_area_struct *orig_vma = vma; struct address_space *mapping = NULL; struct rb_root_cached *root = NULL; @@ -682,8 +682,9 @@ int __vma_adjust(struct vm_area_struct *vma, unsigned long start, * remove_next == 1 is case 1 or 7. */ remove_next = 1 + (end > next->vm_end); + next_next = find_vma(mm, next->vm_end); VM_WARN_ON(remove_next == 2 && - end != find_vma(mm, next->vm_end)->vm_end); + end != next_next->vm_end); /* trim end to next, for case 6 first pass */ end = next->vm_end; } @@ -863,7 +864,7 @@ again: * "next->prev->vm_end" changed and the * "vma->next" gap must be updated. */ - next = find_vma(mm, vma->vm_end); + next = next_next; } else { /* * For the scope of the comment "next" and @@ -878,6 +879,7 @@ again: next = vma; } if (remove_next == 2) { + vma_changed = false; remove_next = 1; end = next->vm_end; goto again; -- 2.49.0