linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] x86/mm: trivial code cleanup for memory_map_top_doown()
@ 2017-02-17 14:30 Wei Yang
  2017-03-13 18:50 ` Borislav Petkov
  0 siblings, 1 reply; 6+ messages in thread
From: Wei Yang @ 2017-02-17 14:30 UTC (permalink / raw)
  To: tglx, mingo, hpa; +Cc: x86, linux-kernel, Wei Yang

In case (last_start <= step_size), start is for sure to be 0. So, it is
save to do the round_down for all cases and set start to map_start when
start is smaller than map_start.

>From the performance point of view, this also reduces the check on each
iteration.

This patch unifies the code on round_down memory range in
memory_map_top_doown() and also removes a redundant assignment of start
which will be assigned the correct value in each iteration.

Signed-off-by: Wei Yang <richard.weiyang@gmail.com>
---
 arch/x86/mm/init.c | 10 ++++------
 1 file changed, 4 insertions(+), 6 deletions(-)

diff --git a/arch/x86/mm/init.c b/arch/x86/mm/init.c
index 22af912d66d2..d8ad5e825b10 100644
--- a/arch/x86/mm/init.c
+++ b/arch/x86/mm/init.c
@@ -514,7 +514,7 @@ static void __init memory_map_top_down(unsigned long map_start,
 	step_size = PMD_SIZE;
 	max_pfn_mapped = 0; /* will get exact value next */
 	min_pfn_mapped = real_end >> PAGE_SHIFT;
-	last_start = start = real_end;
+	last_start = real_end;
 
 	/*
 	 * We start from the top (end of memory) and go to the bottom.
@@ -523,12 +523,10 @@ static void __init memory_map_top_down(unsigned long map_start,
 	 * for page table.
 	 */
 	while (last_start > map_start) {
-		if (last_start > step_size) {
-			start = round_down(last_start - 1, step_size);
-			if (start < map_start)
-				start = map_start;
-		} else
+		start = round_down(last_start - 1, step_size);
+		if (start < map_start)
 			start = map_start;
+
 		mapped_ram_size += init_range_memory_mapping(start,
 							last_start);
 		last_start = start;
-- 
2.11.0

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

* Re: [PATCH] x86/mm: trivial code cleanup for memory_map_top_doown()
  2017-02-17 14:30 [PATCH] x86/mm: trivial code cleanup for memory_map_top_doown() Wei Yang
@ 2017-03-13 18:50 ` Borislav Petkov
  2017-03-14  3:56   ` Wei Yang
  0 siblings, 1 reply; 6+ messages in thread
From: Borislav Petkov @ 2017-03-13 18:50 UTC (permalink / raw)
  To: Wei Yang; +Cc: tglx, mingo, hpa, x86, linux-kernel

On Fri, Feb 17, 2017 at 10:30:33PM +0800, Wei Yang wrote:
> In case (last_start <= step_size), start is for sure to be 0. So, it is

Well, lemme see:

[    0.000000] memory_map_top_down: entry, [0x100000:0x7ffdf000)
[    0.000000] memory_map_top_down: addr: 0x7fc00000, real_end: 0x7fe00000
[    0.000000] memory_map_top_down: last_start: 0x40000000 <= step_size: 0x2000000000, start: 0x40000000
											      ^^^^^^^^^^
It doesn't look like 0 to me.

---
diff --git a/arch/x86/mm/init.c b/arch/x86/mm/init.c
index 2193799ca800..d3b02a416df3 100644
--- a/arch/x86/mm/init.c
+++ b/arch/x86/mm/init.c
@@ -506,10 +506,14 @@ static void __init memory_map_top_down(unsigned long map_start,
 	unsigned long addr;
 	unsigned long mapped_ram_size = 0;
 
+	pr_info("%s: entry, [0x%lx:0x%lx)\n", __func__, map_start, map_end);
+
 	/* xen has big range in reserved near end of ram, skip it at first.*/
 	addr = memblock_find_in_range(map_start, map_end, PMD_SIZE, PMD_SIZE);
 	real_end = addr + PMD_SIZE;
 
+	pr_info("%s: addr: 0x%lx, real_end: 0x%lx\n", __func__, addr, real_end);
+
 	/* step_size need to be small so pgt_buf from BRK could cover it */
 	step_size = PMD_SIZE;
 	max_pfn_mapped = 0; /* will get exact value next */
@@ -527,8 +531,13 @@ static void __init memory_map_top_down(unsigned long map_start,
 			start = round_down(last_start - 1, step_size);
 			if (start < map_start)
 				start = map_start;
-		} else
+		} else {
+			pr_info("%s: last_start: 0x%lx <= step_size: 0x%lx, start: 0x%lx\n",
+				__func__, last_start, step_size, start);
+
 			start = map_start;
+		}
+
 		mapped_ram_size += init_range_memory_mapping(start,
 							last_start);
 		last_start = start;

-- 
Regards/Gruss,
    Boris.

Good mailing practices for 400: avoid top-posting and trim the reply.

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

* Re: [PATCH] x86/mm: trivial code cleanup for memory_map_top_doown()
  2017-03-13 18:50 ` Borislav Petkov
@ 2017-03-14  3:56   ` Wei Yang
  2017-03-20  2:26     ` Wei Yang
  2017-05-02 13:26     ` Wei Yang
  0 siblings, 2 replies; 6+ messages in thread
From: Wei Yang @ 2017-03-14  3:56 UTC (permalink / raw)
  To: Borislav Petkov; +Cc: Wei Yang, tglx, mingo, hpa, x86, linux-kernel

[-- Attachment #1: Type: text/plain, Size: 1487 bytes --]

On Mon, Mar 13, 2017 at 07:50:21PM +0100, Borislav Petkov wrote:
>On Fri, Feb 17, 2017 at 10:30:33PM +0800, Wei Yang wrote:
>> In case (last_start <= step_size), start is for sure to be 0. So, it is
>

Hmm, I may write it more specific:

"start" is for sure to be set to 0 with round_down(last_start - 1, step_size).

>Well, lemme see:
>
>[    0.000000] memory_map_top_down: entry, [0x100000:0x7ffdf000)
>[    0.000000] memory_map_top_down: addr: 0x7fc00000, real_end: 0x7fe00000
>[    0.000000] memory_map_top_down: last_start: 0x40000000 <= step_size: 0x2000000000, start: 0x40000000
>											      ^^^^^^^^^^
>It doesn't look like 0 to me.
>
>---
>diff --git a/arch/x86/mm/init.c b/arch/x86/mm/init.c
>index 2193799ca800..d3b02a416df3 100644
>--- a/arch/x86/mm/init.c
>+++ b/arch/x86/mm/init.c
>@@ -527,8 +531,13 @@ static void __init memory_map_top_down(unsigned long map_start,
> 			start = round_down(last_start - 1, step_size);
> 			if (start < map_start)
> 				start = map_start;
>-		} else
>+		} else {
>+			pr_info("%s: last_start: 0x%lx <= step_size: 0x%lx, start: 0x%lx\n",
>+				__func__, last_start, step_size, start);
>+

If you change this log with the following

			pr_err("%s: last_start: 0x%lx <= step_size: 0x%lx, start: 0x%lx\n",
				__func__, last_start, step_size,
				round_down(last_start - 1, step_size));

You could see after calculation, start is 0 when (last_start <= step_size).

-- 
Wei Yang
Help you, Help me

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 819 bytes --]

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

* Re: [PATCH] x86/mm: trivial code cleanup for memory_map_top_doown()
  2017-03-14  3:56   ` Wei Yang
@ 2017-03-20  2:26     ` Wei Yang
  2017-05-02 13:26     ` Wei Yang
  1 sibling, 0 replies; 6+ messages in thread
From: Wei Yang @ 2017-03-20  2:26 UTC (permalink / raw)
  To: Wei Yang; +Cc: Borislav Petkov, tglx, mingo, hpa, x86, linux-kernel

[-- Attachment #1: Type: text/plain, Size: 1695 bytes --]

Hi, Borislav

Do you still have some concern on this change?

On Tue, Mar 14, 2017 at 11:56:39AM +0800, Wei Yang wrote:
>On Mon, Mar 13, 2017 at 07:50:21PM +0100, Borislav Petkov wrote:
>>On Fri, Feb 17, 2017 at 10:30:33PM +0800, Wei Yang wrote:
>>> In case (last_start <= step_size), start is for sure to be 0. So, it is
>>
>
>Hmm, I may write it more specific:
>
>"start" is for sure to be set to 0 with round_down(last_start - 1, step_size).
>
>>Well, lemme see:
>>
>>[    0.000000] memory_map_top_down: entry, [0x100000:0x7ffdf000)
>>[    0.000000] memory_map_top_down: addr: 0x7fc00000, real_end: 0x7fe00000
>>[    0.000000] memory_map_top_down: last_start: 0x40000000 <= step_size: 0x2000000000, start: 0x40000000
>>											      ^^^^^^^^^^
>>It doesn't look like 0 to me.
>>
>>---
>>diff --git a/arch/x86/mm/init.c b/arch/x86/mm/init.c
>>index 2193799ca800..d3b02a416df3 100644
>>--- a/arch/x86/mm/init.c
>>+++ b/arch/x86/mm/init.c
>>@@ -527,8 +531,13 @@ static void __init memory_map_top_down(unsigned long map_start,
>> 			start = round_down(last_start - 1, step_size);
>> 			if (start < map_start)
>> 				start = map_start;
>>-		} else
>>+		} else {
>>+			pr_info("%s: last_start: 0x%lx <= step_size: 0x%lx, start: 0x%lx\n",
>>+				__func__, last_start, step_size, start);
>>+
>
>If you change this log with the following
>
>			pr_err("%s: last_start: 0x%lx <= step_size: 0x%lx, start: 0x%lx\n",
>				__func__, last_start, step_size,
>				round_down(last_start - 1, step_size));
>
>You could see after calculation, start is 0 when (last_start <= step_size).
>
>-- 
>Wei Yang
>Help you, Help me



-- 
Wei Yang
Help you, Help me

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 819 bytes --]

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

* Re: [PATCH] x86/mm: trivial code cleanup for memory_map_top_doown()
  2017-03-14  3:56   ` Wei Yang
  2017-03-20  2:26     ` Wei Yang
@ 2017-05-02 13:26     ` Wei Yang
  2017-08-03  7:12       ` Wei Yang
  1 sibling, 1 reply; 6+ messages in thread
From: Wei Yang @ 2017-05-02 13:26 UTC (permalink / raw)
  To: Wei Yang; +Cc: Borislav Petkov, tglx, mingo, hpa, x86, linux-kernel

[-- Attachment #1: Type: text/plain, Size: 1714 bytes --]

Hi, Borislav and all

Do you agree with my analysis or you have other comments?

On Tue, Mar 14, 2017 at 11:56:39AM +0800, Wei Yang wrote:
>On Mon, Mar 13, 2017 at 07:50:21PM +0100, Borislav Petkov wrote:
>>On Fri, Feb 17, 2017 at 10:30:33PM +0800, Wei Yang wrote:
>>> In case (last_start <= step_size), start is for sure to be 0. So, it is
>>
>
>Hmm, I may write it more specific:
>
>"start" is for sure to be set to 0 with round_down(last_start - 1, step_size).
>
>>Well, lemme see:
>>
>>[    0.000000] memory_map_top_down: entry, [0x100000:0x7ffdf000)
>>[    0.000000] memory_map_top_down: addr: 0x7fc00000, real_end: 0x7fe00000
>>[    0.000000] memory_map_top_down: last_start: 0x40000000 <= step_size: 0x2000000000, start: 0x40000000
>>											      ^^^^^^^^^^
>>It doesn't look like 0 to me.
>>
>>---
>>diff --git a/arch/x86/mm/init.c b/arch/x86/mm/init.c
>>index 2193799ca800..d3b02a416df3 100644
>>--- a/arch/x86/mm/init.c
>>+++ b/arch/x86/mm/init.c
>>@@ -527,8 +531,13 @@ static void __init memory_map_top_down(unsigned long map_start,
>> 			start = round_down(last_start - 1, step_size);
>> 			if (start < map_start)
>> 				start = map_start;
>>-		} else
>>+		} else {
>>+			pr_info("%s: last_start: 0x%lx <= step_size: 0x%lx, start: 0x%lx\n",
>>+				__func__, last_start, step_size, start);
>>+
>
>If you change this log with the following
>
>			pr_err("%s: last_start: 0x%lx <= step_size: 0x%lx, start: 0x%lx\n",
>				__func__, last_start, step_size,
>				round_down(last_start - 1, step_size));
>
>You could see after calculation, start is 0 when (last_start <= step_size).
>
>-- 
>Wei Yang
>Help you, Help me



-- 
Wei Yang
Help you, Help me

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 819 bytes --]

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

* Re: [PATCH] x86/mm: trivial code cleanup for memory_map_top_doown()
  2017-05-02 13:26     ` Wei Yang
@ 2017-08-03  7:12       ` Wei Yang
  0 siblings, 0 replies; 6+ messages in thread
From: Wei Yang @ 2017-08-03  7:12 UTC (permalink / raw)
  To: Wei Yang
  Cc: Borislav Petkov, Thomas Gleixner, Ingo Molnar, H. Peter Anvin,
	the arch/x86 maintainers, Linux Kernel Mailing List

Hmm.... ping...

On Tue, May 2, 2017 at 9:26 PM, Wei Yang <richard.weiyang@gmail.com> wrote:
> Hi, Borislav and all
>
> Do you agree with my analysis or you have other comments?
>
> On Tue, Mar 14, 2017 at 11:56:39AM +0800, Wei Yang wrote:
>>On Mon, Mar 13, 2017 at 07:50:21PM +0100, Borislav Petkov wrote:
>>>On Fri, Feb 17, 2017 at 10:30:33PM +0800, Wei Yang wrote:
>>>> In case (last_start <= step_size), start is for sure to be 0. So, it is
>>>
>>
>>Hmm, I may write it more specific:
>>
>>"start" is for sure to be set to 0 with round_down(last_start - 1, step_size).
>>
>>>Well, lemme see:
>>>
>>>[    0.000000] memory_map_top_down: entry, [0x100000:0x7ffdf000)
>>>[    0.000000] memory_map_top_down: addr: 0x7fc00000, real_end: 0x7fe00000
>>>[    0.000000] memory_map_top_down: last_start: 0x40000000 <= step_size: 0x2000000000, start: 0x40000000
>>>                                                                                            ^^^^^^^^^^
>>>It doesn't look like 0 to me.
>>>
>>>---
>>>diff --git a/arch/x86/mm/init.c b/arch/x86/mm/init.c
>>>index 2193799ca800..d3b02a416df3 100644
>>>--- a/arch/x86/mm/init.c
>>>+++ b/arch/x86/mm/init.c
>>>@@ -527,8 +531,13 @@ static void __init memory_map_top_down(unsigned long map_start,
>>>                      start = round_down(last_start - 1, step_size);
>>>                      if (start < map_start)
>>>                              start = map_start;
>>>-             } else
>>>+             } else {
>>>+                     pr_info("%s: last_start: 0x%lx <= step_size: 0x%lx, start: 0x%lx\n",
>>>+                             __func__, last_start, step_size, start);
>>>+
>>
>>If you change this log with the following
>>
>>                       pr_err("%s: last_start: 0x%lx <= step_size: 0x%lx, start: 0x%lx\n",
>>                               __func__, last_start, step_size,
>>                               round_down(last_start - 1, step_size));
>>
>>You could see after calculation, start is 0 when (last_start <= step_size).
>>
>>--
>>Wei Yang
>>Help you, Help me
>
>
>
> --
> Wei Yang
> Help you, Help me

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

end of thread, other threads:[~2017-08-03  7:13 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2017-02-17 14:30 [PATCH] x86/mm: trivial code cleanup for memory_map_top_doown() Wei Yang
2017-03-13 18:50 ` Borislav Petkov
2017-03-14  3:56   ` Wei Yang
2017-03-20  2:26     ` Wei Yang
2017-05-02 13:26     ` Wei Yang
2017-08-03  7:12       ` 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).