linux-mm.kvack.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] mm/vmalloc.c: Remove always-true conditional in vmap_init_free_space
@ 2019-07-08 17:06 Pengfei Li
  2019-07-08 17:35 ` Matthew Wilcox
  0 siblings, 1 reply; 3+ messages in thread
From: Pengfei Li @ 2019-07-08 17:06 UTC (permalink / raw)
  To: akpm
  Cc: urezki, rpenyaev, peterz, guro, rick.p.edgecombe, rppt,
	aryabinin, linux-mm, linux-kernel, Pengfei Li

When unsigned long variables are subtracted from one another,
the result is always non-negative.

The vmap_area_list is sorted by address.

So the following two conditions are always true.

1) if (busy->va_start - vmap_start > 0)
2) if (vmap_end - vmap_start > 0)

Just remove them.

Signed-off-by: Pengfei Li <lpf.vector@gmail.com>
---
 mm/vmalloc.c | 32 +++++++++++++-------------------
 1 file changed, 13 insertions(+), 19 deletions(-)

diff --git a/mm/vmalloc.c b/mm/vmalloc.c
index 0f76cca32a1c..c7bdbdc18472 100644
--- a/mm/vmalloc.c
+++ b/mm/vmalloc.c
@@ -1810,31 +1810,25 @@ static void vmap_init_free_space(void)
 	 *  |<--------------------------------->|
 	 */
 	list_for_each_entry(busy, &vmap_area_list, list) {
-		if (busy->va_start - vmap_start > 0) {
-			free = kmem_cache_zalloc(vmap_area_cachep, GFP_NOWAIT);
-			if (!WARN_ON_ONCE(!free)) {
-				free->va_start = vmap_start;
-				free->va_end = busy->va_start;
-
-				insert_vmap_area_augment(free, NULL,
-					&free_vmap_area_root,
-						&free_vmap_area_list);
-			}
-		}
-
-		vmap_start = busy->va_end;
-	}
-
-	if (vmap_end - vmap_start > 0) {
 		free = kmem_cache_zalloc(vmap_area_cachep, GFP_NOWAIT);
 		if (!WARN_ON_ONCE(!free)) {
 			free->va_start = vmap_start;
-			free->va_end = vmap_end;
+			free->va_end = busy->va_start;
 
 			insert_vmap_area_augment(free, NULL,
-				&free_vmap_area_root,
-					&free_vmap_area_list);
+				&free_vmap_area_root, &free_vmap_area_list);
 		}
+
+		vmap_start = busy->va_end;
+	}
+
+	free = kmem_cache_zalloc(vmap_area_cachep, GFP_NOWAIT);
+	if (!WARN_ON_ONCE(!free)) {
+		free->va_start = vmap_start;
+		free->va_end = vmap_end;
+
+		insert_vmap_area_augment(free, NULL,
+			&free_vmap_area_root, &free_vmap_area_list);
 	}
 }
 
-- 
2.21.0


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

* Re: [PATCH] mm/vmalloc.c: Remove always-true conditional in vmap_init_free_space
  2019-07-08 17:06 [PATCH] mm/vmalloc.c: Remove always-true conditional in vmap_init_free_space Pengfei Li
@ 2019-07-08 17:35 ` Matthew Wilcox
  2019-07-08 17:57   ` Pengfei Li
  0 siblings, 1 reply; 3+ messages in thread
From: Matthew Wilcox @ 2019-07-08 17:35 UTC (permalink / raw)
  To: Pengfei Li
  Cc: akpm, urezki, rpenyaev, peterz, guro, rick.p.edgecombe, rppt,
	aryabinin, linux-mm, linux-kernel

On Tue, Jul 09, 2019 at 01:06:31AM +0800, Pengfei Li wrote:
> When unsigned long variables are subtracted from one another,
> the result is always non-negative.
> 
> The vmap_area_list is sorted by address.
> 
> So the following two conditions are always true.
> 
> 1) if (busy->va_start - vmap_start > 0)
> 2) if (vmap_end - vmap_start > 0)
> 
> Just remove them.

That condition won't be true if busy->va_start == vmap_start.


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

* Re: [PATCH] mm/vmalloc.c: Remove always-true conditional in vmap_init_free_space
  2019-07-08 17:35 ` Matthew Wilcox
@ 2019-07-08 17:57   ` Pengfei Li
  0 siblings, 0 replies; 3+ messages in thread
From: Pengfei Li @ 2019-07-08 17:57 UTC (permalink / raw)
  To: Matthew Wilcox
  Cc: akpm, Uladzislau Rezki, rpenyaev, peterz, guro, rick.p.edgecombe,
	rppt, aryabinin, linux-mm, linux-kernel

On Tue, Jul 9, 2019 at 1:35 AM Matthew Wilcox <willy@infradead.org> wrote:
>
> On Tue, Jul 09, 2019 at 01:06:31AM +0800, Pengfei Li wrote:
> > When unsigned long variables are subtracted from one another,
> > the result is always non-negative.
> >
> > The vmap_area_list is sorted by address.
> >
> > So the following two conditions are always true.
> >
> > 1) if (busy->va_start - vmap_start > 0)
> > 2) if (vmap_end - vmap_start > 0)
> >
> > Just remove them.
>
> That condition won't be true if busy->va_start == vmap_start.

Yes, you're right.
Sorry for my bad job.


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

end of thread, other threads:[~2019-07-08 17:58 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-07-08 17:06 [PATCH] mm/vmalloc.c: Remove always-true conditional in vmap_init_free_space Pengfei Li
2019-07-08 17:35 ` Matthew Wilcox
2019-07-08 17:57   ` Pengfei Li

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox