Skip to contentSkip to conversation

mm: get rid of odd jump labels in find_mergeable_anon_vma()

PATCH Applied linmiaohe 4 participants 4 messages Nov 18, 2019

Subsystems (2)
lore
Share & tools
lore

linmiaohe

author
#0 lore raw

PATCH v4 1/1 mm: get rid of odd jump labels in find_mergeable_anon_vma()

From: Miaohe Lin <[email protected]>

The jump labels try_prev and none are not really needed in find_mergeable_anon_vma(), eliminate them to improve readability.

---
-v2:
Fix commit descriptions and further simplify the code as suggested by David Hildenbrand and John Hubbard.
-v3:
Rewrite patch version info. Don't show this in commit log.
-v4:
Get rid of var near completely as well.

---
 mm/mmap.c | 36 ++++++++++++++++--------------------
 1 file changed, 16 insertions(+), 20 deletions(-)
mm/mmap.c +16 -20
index 91d5e097a4ed..4d93bda30eac 100644
@@ -1273,26 +1273,22 @@ static struct anon_vma *reusable_anon_vma(struct vm_area_struct *old, struct vm_
  */
 struct anon_vma *find_mergeable_anon_vma(struct vm_area_struct *vma)
 {
-	struct anon_vma *anon_vma;
-	struct vm_area_struct *near;
-
-	near = vma->vm_next;
-	if (!near)
-		goto try_prev;
-
-	anon_vma = reusable_anon_vma(near, vma, near);
-	if (anon_vma)
-		return anon_vma;
-try_prev:
-	near = vma->vm_prev;
-	if (!near)
-		goto none;
-
-	anon_vma = reusable_anon_vma(near, near, vma);
-	if (anon_vma)
-		return anon_vma;
-none:
+	struct anon_vma *anon_vma = NULL;
+
+	/* Try next first. */
+	if (vma->vm_next) {
+		anon_vma = reusable_anon_vma(vma->vm_next, vma, vma->vm_next);
+		if (anon_vma)
+			return anon_vma;
+	}
+
+	/* Try prev next. */
+	if (vma->vm_prev)
+		anon_vma = reusable_anon_vma(vma->vm_prev, vma->vm_prev, vma);
+
 	/*
+	 * We might reach here with anon_vma == NULL if we can't find
+	 * any reusable anon_vma.
 	 * There's no absolute need to look only at touching neighbours:
 	 * we could search further afield for "compatible" anon_vmas.
 	 * But it would probably just be a waste of time searching,
@@ -1300,7 +1296,7 @@ struct anon_vma *find_mergeable_anon_vma(struct vm_area_struct *vma)
 	 * We're trying to allow mprotect remerging later on,
 	 * not trying to minimize memory used for anon_vmas.
 	 */
-	return NULL;
+	return anon_vma;
 }
 
 /*
Signature · 1 line
2.21.GIT
Reviewed-by on v4 1/1
#1 lore raw
Quoted 9 lines · linmiaohe

From: Miaohe Lin <[email protected]>

The jump labels try_prev and none are not really needed in find_mergeable_anon_vma(), eliminate them to improve readability.

Quoted 69 lines

---
-v2:
Fix commit descriptions and further simplify the code as suggested by David Hildenbrand and John Hubbard.
-v3:
Rewrite patch version info. Don't show this in commit log.
-v4:
Get rid of var near completely as well.
---
mm/mmap.c | 36 ++++++++++++++++--------------------

1 file changed, 16 insertions(+), 20 deletions(-)
mm/mmap.c +16 -20
index 91d5e097a4ed..4d93bda30eac 100644
@@ -1273,26 +1273,22 @@ static struct anon_vma *reusable_anon_vma(struct vm_area_struct *old, struct vm_
 */
 struct anon_vma *find_mergeable_anon_vma(struct vm_area_struct *vma)
 {
-	struct anon_vma *anon_vma;
-	struct vm_area_struct *near;
-
-	near = vma->vm_next;
-	if (!near)
-		goto try_prev;
-
-	anon_vma = reusable_anon_vma(near, vma, near);
-	if (anon_vma)
-		return anon_vma;
-try_prev:
-	near = vma->vm_prev;
-	if (!near)
-		goto none;
-
-	anon_vma = reusable_anon_vma(near, near, vma);
-	if (anon_vma)
-		return anon_vma;
-none:
+	struct anon_vma *anon_vma = NULL;
+
+	/* Try next first. */
+	if (vma->vm_next) {
+		anon_vma = reusable_anon_vma(vma->vm_next, vma, vma->vm_next);
+		if (anon_vma)
+			return anon_vma;
+	}
+
+	/* Try prev next. */
+	if (vma->vm_prev)
+		anon_vma = reusable_anon_vma(vma->vm_prev, vma->vm_prev, vma);
+
 	/*
+	 * We might reach here with anon_vma == NULL if we can't find
+	 * any reusable anon_vma.
 	 * There's no absolute need to look only at touching neighbours:
 	 * we could search further afield for "compatible" anon_vmas.
 	 * But it would probably just be a waste of time searching,
@@ -1300,7 +1296,7 @@ struct anon_vma *find_mergeable_anon_vma(struct vm_area_struct *vma)
 	 * We're trying to allow mprotect remerging later on,
 	 * not trying to minimize memory used for anon_vmas.
 	 */
-	return NULL;
+	return anon_vma;
 }
 
 /*
Signature · 1 line
2.21.GIT
Signature · 2 lines
Wei Yang
Help you, Help me
Reviewed-by on v4 1/1
#2 lore raw
In reply to linmiaohe
Quoted 69 lines · linmiaohe

From: Miaohe Lin <[email protected]>

The jump labels try_prev and none are not really needed in find_mergeable_anon_vma(), eliminate them to improve readability.

---
-v2:
Fix commit descriptions and further simplify the code as suggested by David Hildenbrand and John Hubbard.
-v3:
Rewrite patch version info. Don't show this in commit log.
-v4:
Get rid of var near completely as well.

---
  mm/mmap.c | 36 ++++++++++++++++--------------------
  1 file changed, 16 insertions(+), 20 deletions(-)
mm/mmap.c +15 -19
index 91d5e097a4ed..4d93bda30eac 100644
@@ -1273,26 +1273,22 @@ static struct anon_vma *reusable_anon_vma(struct vm_area_struct *old, struct vm_
   */
  struct anon_vma *find_mergeable_anon_vma(struct vm_area_struct *vma)
  {
-	struct anon_vma *anon_vma;
-	struct vm_area_struct *near;
-
-	near = vma->vm_next;
-	if (!near)
-		goto try_prev;
-
-	anon_vma = reusable_anon_vma(near, vma, near);
-	if (anon_vma)
-		return anon_vma;
-try_prev:
-	near = vma->vm_prev;
-	if (!near)
-		goto none;
-
-	anon_vma = reusable_anon_vma(near, near, vma);
-	if (anon_vma)
-		return anon_vma;
-none:
+	struct anon_vma *anon_vma = NULL;
+
+	/* Try next first. */
+	if (vma->vm_next) {
+		anon_vma = reusable_anon_vma(vma->vm_next, vma, vma->vm_next);
+		if (anon_vma)
+			return anon_vma;
+	}
+
+	/* Try prev next. */
+	if (vma->vm_prev)
+		anon_vma = reusable_anon_vma(vma->vm_prev, vma->vm_prev, vma);
+
  	/*
+	 * We might reach here with anon_vma == NULL if we can't find
+	 * any reusable anon_vma.
  	 * There's no absolute need to look only at touching neighbours:
  	 * we could search further afield for "compatible" anon_vmas.
  	 * But it would probably just be a waste of time searching,

mm/mmap.c struct anon_vma *find_mergeable_anon_vma(struct vm_area_struct *vma) · line 1302

Quoted 8 lines
mm/mmap.c +1 -1
@@ -1300,7 +1296,7 @@ struct anon_vma *find_mergeable_anon_vma(struct vm_area_struct *vma)
  	 * We're trying to allow mprotect remerging later on,
  	 * not trying to minimize memory used for anon_vmas.
  	 */
-	return NULL;
+	return anon_vma;
  }
 
  /*

Looks much better, thanks!

Signature · 3 lines
Thanks,

David / dhildenb