linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [Patch v2 1/3] mm/mmap.c: prev could be retrieved from vma->vm_prev
@ 2019-10-06  1:26 Wei Yang
  2019-10-06  1:26 ` [Patch v2 2/3] mm/mmap.c: __vma_unlink_prev is not necessary now Wei Yang
  2019-10-06  1:26 ` [Patch v2 3/3] mm/mmap.c: extract __vma_unlink_list as counter part for __vma_link_list Wei Yang
  0 siblings, 2 replies; 3+ messages in thread
From: Wei Yang @ 2019-10-06  1:26 UTC (permalink / raw)
  To: akpm, mgorman, vbabka, osalvador, hch, willy
  Cc: linux-mm, linux-kernel, Wei Yang

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.

Signed-off-by: Wei Yang <richardw.yang@linux.intel.com>

---
v2: rebase on top of 5.4-rc1
---
 mm/mmap.c | 20 +++++++-------------
 1 file changed, 7 insertions(+), 13 deletions(-)

diff --git a/mm/mmap.c b/mm/mmap.c
index 338213aed65a..c61403f25833 100644
--- 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);
 }
 
 /*
@@ -900,7 +894,7 @@ int __vma_adjust(struct vm_area_struct *vma, unsigned long start,
 			 * "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) {
-- 
2.17.1


^ permalink raw reply related	[flat|nested] 3+ messages in thread

* [Patch v2 2/3] mm/mmap.c: __vma_unlink_prev is not necessary now
  2019-10-06  1:26 [Patch v2 1/3] mm/mmap.c: prev could be retrieved from vma->vm_prev Wei Yang
@ 2019-10-06  1:26 ` Wei Yang
  2019-10-06  1:26 ` [Patch v2 3/3] mm/mmap.c: extract __vma_unlink_list as counter part for __vma_link_list Wei Yang
  1 sibling, 0 replies; 3+ messages in thread
From: Wei Yang @ 2019-10-06  1:26 UTC (permalink / raw)
  To: akpm, mgorman, vbabka, osalvador, hch, willy
  Cc: linux-mm, linux-kernel, Wei Yang

The third parameter of __vma_unlink_common could differentiate these two
types. __vma_unlink_prev is not necessary now.

Signed-off-by: Wei Yang <richardw.yang@linux.intel.com>

---
v2: rebase on top of 5.4-rc1
---
 mm/mmap.c | 9 +--------
 1 file changed, 1 insertion(+), 8 deletions(-)

diff --git a/mm/mmap.c b/mm/mmap.c
index c61403f25833..2ca805209c47 100644
--- a/mm/mmap.c
+++ b/mm/mmap.c
@@ -702,13 +702,6 @@ static __always_inline void __vma_unlink_common(struct mm_struct *mm,
 	vmacache_invalidate(mm);
 }
 
-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, vma);
-}
-
 /*
  * We cannot adjust vm_start, vm_end, vm_pgoff fields of a vma that
  * is already present in an i_mmap tree without adjusting the tree.
@@ -883,7 +876,7 @@ int __vma_adjust(struct vm_area_struct *vma, unsigned long start,
 		 * us to remove next before dropping the locks.
 		 */
 		if (remove_next != 3)
-			__vma_unlink_prev(mm, next, vma);
+			__vma_unlink_common(mm, next, next);
 		else
 			/*
 			 * vma is not before next if they've been
-- 
2.17.1


^ permalink raw reply related	[flat|nested] 3+ messages in thread

* [Patch v2 3/3] mm/mmap.c: extract __vma_unlink_list as counter part for __vma_link_list
  2019-10-06  1:26 [Patch v2 1/3] mm/mmap.c: prev could be retrieved from vma->vm_prev Wei Yang
  2019-10-06  1:26 ` [Patch v2 2/3] mm/mmap.c: __vma_unlink_prev is not necessary now Wei Yang
@ 2019-10-06  1:26 ` Wei Yang
  1 sibling, 0 replies; 3+ messages in thread
From: Wei Yang @ 2019-10-06  1:26 UTC (permalink / raw)
  To: akpm, mgorman, vbabka, osalvador, hch, willy
  Cc: linux-mm, linux-kernel, Wei Yang

Just make the code a little easy to read.

Signed-off-by: Wei Yang <richardw.yang@linux.intel.com>

---
Note: For nommu part, the code is not tested.

---
v2: rebase on top of 5.4-rc1
---
 mm/internal.h |  1 +
 mm/mmap.c     | 12 +-----------
 mm/nommu.c    |  8 +-------
 mm/util.c     | 14 ++++++++++++++
 4 files changed, 17 insertions(+), 18 deletions(-)

diff --git a/mm/internal.h b/mm/internal.h
index 8e596fa8a7de..f93fd474dac3 100644
--- a/mm/internal.h
+++ b/mm/internal.h
@@ -291,6 +291,7 @@ static inline bool is_data_mapping(vm_flags_t flags)
 /* mm/util.c */
 void __vma_link_list(struct mm_struct *mm, struct vm_area_struct *vma,
 		struct vm_area_struct *prev);
+void __vma_unlink_list(struct mm_struct *mm, struct vm_area_struct *vma);
 
 #ifdef CONFIG_MMU
 extern long populate_vma_page_range(struct vm_area_struct *vma,
diff --git a/mm/mmap.c b/mm/mmap.c
index 2ca805209c47..3ab5d20289be 100644
--- a/mm/mmap.c
+++ b/mm/mmap.c
@@ -686,18 +686,8 @@ static __always_inline void __vma_unlink_common(struct mm_struct *mm,
 						struct vm_area_struct *vma,
 						struct vm_area_struct *ignore)
 {
-	struct vm_area_struct *prev, *next;
-
 	vma_rb_erase_ignore(vma, &mm->mm_rb, ignore);
-	next = vma->vm_next;
-	prev = vma->vm_prev;
-	if (prev)
-		prev->vm_next = next;
-	else
-		mm->mmap = next;
-	if (next)
-		next->vm_prev = prev;
-
+	__vma_unlink_list(mm, vma);
 	/* Kill the cache */
 	vmacache_invalidate(mm);
 }
diff --git a/mm/nommu.c b/mm/nommu.c
index 2bb923210128..21ddf689d4fa 100644
--- a/mm/nommu.c
+++ b/mm/nommu.c
@@ -673,13 +673,7 @@ static void delete_vma_from_mm(struct vm_area_struct *vma)
 	/* remove from the MM's tree and list */
 	rb_erase(&vma->vm_rb, &mm->mm_rb);
 
-	if (vma->vm_prev)
-		vma->vm_prev->vm_next = vma->vm_next;
-	else
-		mm->mmap = vma->vm_next;
-
-	if (vma->vm_next)
-		vma->vm_next->vm_prev = vma->vm_prev;
+	__vma_unlink_list(mm, vma);
 }
 
 /*
diff --git a/mm/util.c b/mm/util.c
index 023defd39a0d..988d11e6c17c 100644
--- a/mm/util.c
+++ b/mm/util.c
@@ -288,6 +288,20 @@ void __vma_link_list(struct mm_struct *mm, struct vm_area_struct *vma,
 		next->vm_prev = vma;
 }
 
+void __vma_unlink_list(struct mm_struct *mm, struct vm_area_struct *vma)
+{
+	struct vm_area_struct *prev, *next;
+
+	next = vma->vm_next;
+	prev = vma->vm_prev;
+	if (prev)
+		prev->vm_next = next;
+	else
+		mm->mmap = next;
+	if (next)
+		next->vm_prev = prev;
+}
+
 /* Check if the vma is being used as a stack by this task */
 int vma_is_stack_for_current(struct vm_area_struct *vma)
 {
-- 
2.17.1


^ permalink raw reply related	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2019-10-06  1:31 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-10-06  1:26 [Patch v2 1/3] mm/mmap.c: prev could be retrieved from vma->vm_prev Wei Yang
2019-10-06  1:26 ` [Patch v2 2/3] mm/mmap.c: __vma_unlink_prev is not necessary now Wei Yang
2019-10-06  1:26 ` [Patch v2 3/3] mm/mmap.c: extract __vma_unlink_list as counter part for __vma_link_list Wei Yang

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).