diff mbox series

[05/10] mm/mmap/vma_merge: initialize mid and next in natural order

Message ID 20230309111258.24079-6-vbabka@suse.cz (mailing list archive)
State New
Headers show
Series cleanup vma_merge() and improve mergeability tests | expand

Commit Message

Vlastimil Babka March 9, 2023, 11:12 a.m. UTC
It is more intuitive to go from prev to mid and then next. No functional
change.

Signed-off-by: Vlastimil Babka <vbabka@suse.cz>
---
 mm/mmap.c | 9 +++++----
 1 file changed, 5 insertions(+), 4 deletions(-)

Comments

Lorenzo Stoakes March 15, 2023, 8:10 p.m. UTC | #1
On Thu, Mar 09, 2023 at 12:12:53PM +0100, Vlastimil Babka wrote:
> It is more intuitive to go from prev to mid and then next. No functional
> change.
>
> Signed-off-by: Vlastimil Babka <vbabka@suse.cz>
> ---
>  mm/mmap.c | 9 +++++----
>  1 file changed, 5 insertions(+), 4 deletions(-)
>
> diff --git a/mm/mmap.c b/mm/mmap.c
> index 420d6847c94c..be60b344e4b1 100644
> --- a/mm/mmap.c
> +++ b/mm/mmap.c
> @@ -912,10 +912,11 @@ struct vm_area_struct *vma_merge(struct vma_iterator *vmi, struct mm_struct *mm,
>  	if (vm_flags & VM_SPECIAL)
>  		return NULL;
>
> -	next = find_vma(mm, prev ? prev->vm_end : 0);
> -	mid = next;
> -	if (next && next->vm_end == end)		/* cases 6, 7, 8 */
> -		next = find_vma(mm, next->vm_end);
> +	mid = find_vma(mm, prev ? prev->vm_end : 0);
> +	if (mid && mid->vm_end == end)			/* cases 6, 7, 8 */
> +		next = find_vma(mm, mid->vm_end);
> +	else
> +		next = mid;

It feels like the original implementation may have been backwards like this just
to avoid this else branch. Which is silly.

>
>  	/* verify some invariant that must be enforced by the caller */
>  	VM_WARN_ON(prev && addr <= prev->vm_start);
> --
> 2.39.2
>

Reviewed-by: Lorenzo Stoakes <lstoakes@gmail.com>
diff mbox series

Patch

diff --git a/mm/mmap.c b/mm/mmap.c
index 420d6847c94c..be60b344e4b1 100644
--- a/mm/mmap.c
+++ b/mm/mmap.c
@@ -912,10 +912,11 @@  struct vm_area_struct *vma_merge(struct vma_iterator *vmi, struct mm_struct *mm,
 	if (vm_flags & VM_SPECIAL)
 		return NULL;
 
-	next = find_vma(mm, prev ? prev->vm_end : 0);
-	mid = next;
-	if (next && next->vm_end == end)		/* cases 6, 7, 8 */
-		next = find_vma(mm, next->vm_end);
+	mid = find_vma(mm, prev ? prev->vm_end : 0);
+	if (mid && mid->vm_end == end)			/* cases 6, 7, 8 */
+		next = find_vma(mm, mid->vm_end);
+	else
+		next = mid;
 
 	/* verify some invariant that must be enforced by the caller */
 	VM_WARN_ON(prev && addr <= prev->vm_start);