Skip to contentSkip to conversation

mm/memblock.c: using judgment statement can reduce loop and enhance readability.

PATCH In review [email protected] 2 participants 7 messages Nov 2, 2023 – Nov 3, 2023

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 mm/memblock.c: using judgment statement can reduce loop and enhance readability.

From: Liangliang Huang <[email protected]>

---
 mm/memblock.c | 6 +++++-
 1 file changed, 5 insertions(+), 1 deletion(-)
mm/memblock.c +5 -1
index 913b2520a9a0..e48dea7144bb 100644
@@ -655,7 +655,11 @@ static int __init_memblock memblock_add_range(struct memblock_type *type,
 			}
 		}
 		/* area below @rend is dealt with, forget about it */
-		base = min(rend, end);
+		if (end < rend) {
+			base = end;
+			break;
+		} else
+			base = rend;
 	}
 
 	/* insert the remaining portion */
Signature · 1 line
2.25.1
maintainer
#1 lore raw

Hi,

Quoted 1 line

Subject: [PATCH] mm/memblock.c: using judgment statement can reduce loop and enhance readability.

I disagree.

Quoted 12 lines · On Thu, Nov 02, 2023 at 10:37:10AM +0800, [email protected] wrote:

From: Liangliang Huang <[email protected]>

---
 mm/memblock.c | 6 +++++-
 1 file changed, 5 insertions(+), 1 deletion(-)
mm/memblock.c +0 -0
index 913b2520a9a0..e48dea7144bb 100644

mm/memblock.c static int __init_memblock memblock_add_range(struct memblock_type *type, · line 662

Quoted 9 lines
mm/memblock.c +5 -1
@@ -655,7 +655,11 @@ static int __init_memblock memblock_add_range(struct memblock_type *type,
 			}
 		}
 		/* area below @rend is dealt with, forget about it */
-		base = min(rend, end);
+		if (end < rend) {
+			base = end;
+			break;
+		} else
+			base = rend;

min() is perfectly clear and there no change in number of iterations of the loop.

Quoted 6 lines
mm/memblock.c +0 -0
 	}
 
 	/* insert the remaining portion */
Signature · 1 line
2.25.1
Signature · 2 lines
Sincerely yours,
Mike.
author
#2 lore raw

Hi, this patch can less loop once in this situation:
base more than rbase and end less than rend.
base end
rbase----|-------------| --------rend
| | | |
--------------------------------------------------->

Quoted 45 lines · Mike Rapoport <[email protected]> 于2023年11月2日周四 16:54写道:

Hi,

Quoted 1 line

Subject: [PATCH] mm/memblock.c: using judgment statement can reduce loop

and enhance readability.

I disagree.

mm/memblock.c static int __init_memblock

Quoted 12 lines · On Thu, Nov 02, 2023 at 10:37:10AM +0800, [email protected] wrote:

From: Liangliang Huang <[email protected]>

---
 mm/memblock.c | 6 +++++-
 1 file changed, 5 insertions(+), 1 deletion(-)
mm/memblock.c +0 -0
index 913b2520a9a0..e48dea7144bb 100644
@@ -655,7 +655,11 @@ static int __init_memblock

memblock_add_range(struct memblock_type *type,

mm/memblock.c static int __init_memblock memblock_add_range(struct memblock_type *type, · line 662

Quoted 9 lines
mm/memblock.c +5 -1
                      }
              }
              /* area below @rend is dealt with, forget about it */
-             base = min(rend, end);
+             if (end < rend) {
+                     base = end;
+                     break;
+             } else
+                     base = rend;

min() is perfectly clear and there no change in number of iterations of the loop.

Quoted 6 lines
mm/memblock.c +0 -1
      }
 
      /* insert the remaining portion */
--

2.25.1

--
Sincerely yours,
Mike.

author
#3 lore raw
In reply to Mike Rapoport

Hi,this patch can less loop once in this situation:
base more than rbase and end less than rend.
base end
rbase-----|--------------|-------rend
| | | |
-------------------------------------------------------->

Quoted 45 lines · Mike Rapoport <[email protected]> 于2023年11月2日周四 16:54写道:

Hi,

Quoted 1 line

Subject: [PATCH] mm/memblock.c: using judgment statement can reduce loop

and enhance readability.

I disagree.

mm/memblock.c static int __init_memblock

Quoted 12 lines · On Thu, Nov 02, 2023 at 10:37:10AM +0800, [email protected] wrote:

From: Liangliang Huang <[email protected]>

---
 mm/memblock.c | 6 +++++-
 1 file changed, 5 insertions(+), 1 deletion(-)
mm/memblock.c +0 -0
index 913b2520a9a0..e48dea7144bb 100644
@@ -655,7 +655,11 @@ static int __init_memblock

memblock_add_range(struct memblock_type *type,

mm/memblock.c static int __init_memblock memblock_add_range(struct memblock_type *type, · line 662

Quoted 9 lines
mm/memblock.c +5 -1
                      }
              }
              /* area below @rend is dealt with, forget about it */
-             base = min(rend, end);
+             if (end < rend) {
+                     base = end;
+                     break;
+             } else
+                     base = rend;

min() is perfectly clear and there no change in number of iterations of the loop.

Quoted 6 lines
mm/memblock.c +0 -1
      }
 
      /* insert the remaining portion */
--

2.25.1

--
Sincerely yours,
Mike.

maintainer
#4 lore raw
Quoted 6 lines · 黄亮亮

Hi,this patch can less loop once in this situation:
base more than rbase and end less than rend. base           end rbase-----|--------------|-------rend
      |            |                 |           | -------------------------------------------------------->

The loop won't be executed anyway because there's similar condition in the beginning of the loop.

Next time when you reply to the kernel mailing lists, please don't top post and make sure your reply is text-only.

And there is no need to send 4 badly formatted replies.

Quoted 47 lines

Mike Rapoport <[email protected]> 于2023年11月2日周四 16:54写道:

    Hi,

    > Subject: [PATCH] mm/memblock.c: using judgment statement can reduce loop
    and enhance readability.

    I disagree.

    On Thu, Nov 02, 2023 at 10:37:10AM +0800, [email protected] wrote:
    > From: Liangliang Huang <[email protected]>
    >
    > Signed-off-by: Liangliang Huang <[email protected]>
    > ---
    >  mm/memblock.c | 6 +++++-
    >  1 file changed, 5 insertions(+), 1 deletion(-)
    >
    > diff --git a/mm/memblock.c b/mm/memblock.c
    > index 913b2520a9a0..e48dea7144bb 100644
    > --- a/mm/memblock.c
    > +++ b/mm/memblock.c
    > @@ -655,7 +655,11 @@ static int __init_memblock memblock_add_range(struct
    memblock_type *type,
    >                       }
    >               }
    >               /* area below @rend is dealt with, forget about it */
    > -             base = min(rend, end);
    > +             if (end < rend) {
    > +                     base = end;
    > +                     break;
    > +             } else
    > +                     base = rend;

    min() is perfectly clear and there no change in number of iterations of the
    loop.

    >       }
    > 
    >       /* insert the remaining portion */
    > --
    > 2.25.1
    >

    --
    Sincerely yours,
    Mike.
Signature · 2 lines
Sincerely yours,
Mike.
author
#5 lore raw
Quoted 63 lines · Mike Rapoport <[email protected]> 于2023年11月3日周五 15:35写道:
Quoted 6 lines · 黄亮亮

Hi,this patch can less loop once in this situation:
base more than rbase and end less than rend.
base end
rbase-----|--------------|-------rend
| | | |
-------------------------------------------------------->

The loop won't be executed anyway because there's similar condition in the beginning of the loop.

Next time when you reply to the kernel mailing lists, please don't top post and make sure your reply is text-only.

And there is no need to send 4 badly formatted replies.

Quoted 5 lines

Mike Rapoport <[email protected]> 于2023年11月2日周四 16:54写道:

Hi,

> Subject: [PATCH] mm/memblock.c: using judgment statement can

reduce loop

Quoted 5 lines

and enhance readability.

I disagree.

On Thu, Nov 02, 2023 at 10:37:10AM +0800, [email protected]

Quoted 7 lines · wrote:
Quoted 7 lines

From: Liangliang Huang <[email protected]>

---
 mm/memblock.c | 6 +++++-
 1 file changed, 5 insertions(+), 1 deletion(-)
Quoted 5 lines

mm/memblock.c static int __init_memblock

Quoted 5 lines
mm/memblock.c +0 -0
index 913b2520a9a0..e48dea7144bb 100644
@@ -655,7 +655,11 @@ static int __init_memblock

memblock_add_range(struct

Quoted 4 lines
    memblock_type *type,
    >                       }
    >               }
    >               /* area below @rend is dealt with, forget about it */
Quoted 8 lines
    > -             base = min(rend, end);
    > +             if (end < rend) {
    > +                     base = end;
    > +                     break;
    > +             } else
    > +                     base = rend;

    min() is perfectly clear and there no change in number of iterations

of the

Quoted 9 lines
    loop.

    >       }
    >
    >       /* insert the remaining portion */
    > --
    > 2.25.1
    >
Quoted 9 lines
Quoted 4 lines
    --
    Sincerely yours,
    Mike.

--
Sincerely yours,
Mike.

I get your meanings, thanks.

author
#6 lore raw
In reply to Mike Rapoport

Hi,this patch can less loop once in this situation:
base more than rbase and end less than rend.

Quoted 45 lines · Mike Rapoport <[email protected]> 于2023年11月2日周四 16:54写道:

Hi,

Quoted 1 line

Subject: [PATCH] mm/memblock.c: using judgment statement can reduce loop

and enhance readability.

I disagree.

mm/memblock.c static int __init_memblock

Quoted 12 lines · On Thu, Nov 02, 2023 at 10:37:10AM +0800, [email protected] wrote:

From: Liangliang Huang <[email protected]>

---
 mm/memblock.c | 6 +++++-
 1 file changed, 5 insertions(+), 1 deletion(-)
mm/memblock.c +0 -0
index 913b2520a9a0..e48dea7144bb 100644
@@ -655,7 +655,11 @@ static int __init_memblock

memblock_add_range(struct memblock_type *type,

mm/memblock.c static int __init_memblock memblock_add_range(struct memblock_type *type, · line 662

Quoted 9 lines
mm/memblock.c +5 -1
                      }
              }
              /* area below @rend is dealt with, forget about it */
-             base = min(rend, end);
+             if (end < rend) {
+                     base = end;
+                     break;
+             } else
+                     base = rend;

min() is perfectly clear and there no change in number of iterations of the loop.

Quoted 6 lines
mm/memblock.c +0 -1
      }
 
      /* insert the remaining portion */
--

2.25.1

--
Sincerely yours,
Mike.