mm/mmap.c: prev could be retrieved from vma->vm_prev
authorWei Yang <richardw.yang@linux.intel.com>
Sun, 1 Dec 2019 01:50:43 +0000 (17:50 -0800)
committerLinus Torvalds <torvalds@linux-foundation.org>
Sun, 1 Dec 2019 14:29:19 +0000 (06:29 -0800)
Currently __vma_unlink_common handles two cases:

  * has_prev
  * or not

When has_prev is false, it is obvious prev is calculated from
vma->vm_prev in __vma_unlink_common.

When has_prev is true, the prev is passed through from __vma_unlink_prev
in __vma_adjust for non-case 8.  And at the beginning next is calculated
from vma->vm_next, which implies vma is next->vm_prev.

The above statement sounds a little complicated, while to think in
another point of view, no matter whether vma and next is swapped, the
mmap link list still preserves its property.  It is proper to access
vma->vm_prev.

Link: http://lkml.kernel.org/r/20191006012636.31521-1-richardw.yang@linux.intel.com
Signed-off-by: Wei Yang <richardw.yang@linux.intel.com>
Cc: Mel Gorman <mgorman@techsingularity.net>
Cc: Vlastimil Babka <vbabka@suse.cz>
Cc: Oscar Salvador <osalvador@suse.de>
Cc: Christoph Hellwig <hch@infradead.org>
Cc: Matthew Wilcox (Oracle) <willy@infradead.org>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
mm/mmap.c

index e27bc5d..4473c5e 100644 (file)
--- a/mm/mmap.c
+++ b/mm/mmap.c
@@ -684,23 +684,17 @@ static void __insert_vm_struct(struct mm_struct *mm, struct vm_area_struct *vma)
 
 static __always_inline void __vma_unlink_common(struct mm_struct *mm,
                                                struct vm_area_struct *vma,
-                                               struct vm_area_struct *prev,
-                                               bool has_prev,
                                                struct vm_area_struct *ignore)
 {
-       struct vm_area_struct *next;
+       struct vm_area_struct *prev, *next;
 
        vma_rb_erase_ignore(vma, &mm->mm_rb, ignore);
        next = vma->vm_next;
-       if (has_prev)
+       prev = vma->vm_prev;
+       if (prev)
                prev->vm_next = next;
-       else {
-               prev = vma->vm_prev;
-               if (prev)
-                       prev->vm_next = next;
-               else
-                       mm->mmap = next;
-       }
+       else
+               mm->mmap = next;
        if (next)
                next->vm_prev = prev;
 
@@ -712,7 +706,7 @@ static inline void __vma_unlink_prev(struct mm_struct *mm,
                                     struct vm_area_struct *vma,
                                     struct vm_area_struct *prev)
 {
-       __vma_unlink_common(mm, vma, prev, true, vma);
+       __vma_unlink_common(mm, vma, vma);
 }
 
 /*
@@ -898,7 +892,7 @@ again:
                         * "next" (which is stored in post-swap()
                         * "vma").
                         */
-                       __vma_unlink_common(mm, next, NULL, false, vma);
+                       __vma_unlink_common(mm, next, vma);
                if (file)
                        __remove_shared_vm_struct(next, file, mapping);
        } else if (insert) {