public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH 1/3] x86/mm: Simplify memory mapping PFN calculation
@ 2012-07-14 13:41 Pekka Enberg
  2012-07-14 13:41 ` [PATCH 2/3] x86/mm: Simplify for-loop in free_init_pages() Pekka Enberg
  2012-07-14 20:34 ` [PATCH 1/3] x86/mm: Simplify memory mapping PFN calculation Yinghai Lu
  0 siblings, 2 replies; 8+ messages in thread
From: Pekka Enberg @ 2012-07-14 13:41 UTC (permalink / raw)
  To: mingo; +Cc: linux-kernel, x86, Pekka Enberg, Tejun Heo, Yinghai Lu

Introduce two new helper functions, addr_to_pmd_pfn() and
addr_to_pud_pfn(), to simplify init_memory_mapping() code flow.

Cc: Tejun Heo <tj@kernel.org>
Cc: Yinghai Lu <yinghai@kernel.org>
Signed-off-by: Pekka Enberg <penberg@kernel.org>
---
 arch/x86/mm/init.c |   38 +++++++++++++++++++++-----------------
 1 files changed, 21 insertions(+), 17 deletions(-)

diff --git a/arch/x86/mm/init.c b/arch/x86/mm/init.c
index bc4e9d8..9eb53c2 100644
--- a/arch/x86/mm/init.c
+++ b/arch/x86/mm/init.c
@@ -117,6 +117,16 @@ static int __meminit save_mr(struct map_range *mr, int nr_range,
 	return nr_range;
 }
 
+static unsigned long addr_to_pmd_pfn(unsigned long addr)
+{
+	return (addr >> PMD_SHIFT) << (PMD_SHIFT - PAGE_SHIFT);
+}
+
+static unsigned long addr_to_pud_pfn(unsigned long addr)
+{
+	return (addr >> PUD_SHIFT) << (PUD_SHIFT - PAGE_SHIFT);
+}
+
 /*
  * Setup the direct mapping of the physical memory at PAGE_OFFSET.
  * This runs before bootmem is initialized and gets pages directly from
@@ -180,11 +190,9 @@ unsigned long __init_refok init_memory_mapping(unsigned long start,
 	if (pos == 0)
 		end_pfn = 1<<(PMD_SHIFT - PAGE_SHIFT);
 	else
-		end_pfn = ((pos + (PMD_SIZE - 1))>>PMD_SHIFT)
-				 << (PMD_SHIFT - PAGE_SHIFT);
+		end_pfn = addr_to_pmd_pfn(pos + (PMD_SIZE - 1));
 #else /* CONFIG_X86_64 */
-	end_pfn = ((pos + (PMD_SIZE - 1)) >> PMD_SHIFT)
-			<< (PMD_SHIFT - PAGE_SHIFT);
+	end_pfn = addr_to_pmd_pfn(pos + (PMD_SIZE - 1));
 #endif
 	if (end_pfn > (end >> PAGE_SHIFT))
 		end_pfn = end >> PAGE_SHIFT;
@@ -194,15 +202,13 @@ unsigned long __init_refok init_memory_mapping(unsigned long start,
 	}
 
 	/* big page (2M) range */
-	start_pfn = ((pos + (PMD_SIZE - 1))>>PMD_SHIFT)
-			 << (PMD_SHIFT - PAGE_SHIFT);
+	start_pfn = addr_to_pmd_pfn(pos + (PMD_SIZE - 1));
 #ifdef CONFIG_X86_32
-	end_pfn = (end>>PMD_SHIFT) << (PMD_SHIFT - PAGE_SHIFT);
+	end_pfn = addr_to_pmd_pfn(end);
 #else /* CONFIG_X86_64 */
-	end_pfn = ((pos + (PUD_SIZE - 1))>>PUD_SHIFT)
-			 << (PUD_SHIFT - PAGE_SHIFT);
-	if (end_pfn > ((end>>PMD_SHIFT)<<(PMD_SHIFT - PAGE_SHIFT)))
-		end_pfn = ((end>>PMD_SHIFT)<<(PMD_SHIFT - PAGE_SHIFT));
+	end_pfn = addr_to_pud_pfn(pos + (PUD_SIZE - 1));
+	if (end_pfn > addr_to_pmd_pfn(end))
+		end_pfn = addr_to_pmd_pfn(end);
 #endif
 
 	if (start_pfn < end_pfn) {
@@ -213,9 +219,8 @@ unsigned long __init_refok init_memory_mapping(unsigned long start,
 
 #ifdef CONFIG_X86_64
 	/* big page (1G) range */
-	start_pfn = ((pos + (PUD_SIZE - 1))>>PUD_SHIFT)
-			 << (PUD_SHIFT - PAGE_SHIFT);
-	end_pfn = (end >> PUD_SHIFT) << (PUD_SHIFT - PAGE_SHIFT);
+	start_pfn = addr_to_pud_pfn(pos + (PUD_SIZE - 1));
+	end_pfn = addr_to_pud_pfn(end);
 	if (start_pfn < end_pfn) {
 		nr_range = save_mr(mr, nr_range, start_pfn, end_pfn,
 				page_size_mask &
@@ -224,9 +229,8 @@ unsigned long __init_refok init_memory_mapping(unsigned long start,
 	}
 
 	/* tail is not big page (1G) alignment */
-	start_pfn = ((pos + (PMD_SIZE - 1))>>PMD_SHIFT)
-			 << (PMD_SHIFT - PAGE_SHIFT);
-	end_pfn = (end >> PMD_SHIFT) << (PMD_SHIFT - PAGE_SHIFT);
+	start_pfn = addr_to_pmd_pfn(pos + (PMD_SIZE - 1));
+	end_pfn = addr_to_pmd_pfn(end);
 	if (start_pfn < end_pfn) {
 		nr_range = save_mr(mr, nr_range, start_pfn, end_pfn,
 				page_size_mask & (1<<PG_LEVEL_2M));
-- 
1.7.7.6


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

* [PATCH 2/3] x86/mm: Simplify for-loop in free_init_pages()
  2012-07-14 13:41 [PATCH 1/3] x86/mm: Simplify memory mapping PFN calculation Pekka Enberg
@ 2012-07-14 13:41 ` Pekka Enberg
  2012-07-14 20:36   ` Yinghai Lu
  2012-07-14 20:34 ` [PATCH 1/3] x86/mm: Simplify memory mapping PFN calculation Yinghai Lu
  1 sibling, 1 reply; 8+ messages in thread
From: Pekka Enberg @ 2012-07-14 13:41 UTC (permalink / raw)
  To: mingo; +Cc: linux-kernel, x86, Pekka Enberg, Tejun Heo, Yinghai Lu

As a cleanup, move initial "addr" assignment to the for-loop construct
in free_init_pages().

Cc: Tejun Heo <tj@kernel.org>
Cc: Yinghai Lu <yinghai@kernel.org>
Signed-off-by: Pekka Enberg <penberg@kernel.org>
---
 arch/x86/mm/init.c |    4 +---
 1 files changed, 1 insertions(+), 3 deletions(-)

diff --git a/arch/x86/mm/init.c b/arch/x86/mm/init.c
index 9eb53c2..e270f94 100644
--- a/arch/x86/mm/init.c
+++ b/arch/x86/mm/init.c
@@ -349,8 +349,6 @@ void free_init_pages(char *what, unsigned long begin, unsigned long end)
 	if (begin >= end)
 		return;
 
-	addr = begin;
-
 	/*
 	 * If debugging page accesses then do not free this memory but
 	 * mark them not present - any buggy init-section access will
@@ -371,7 +369,7 @@ void free_init_pages(char *what, unsigned long begin, unsigned long end)
 
 	printk(KERN_INFO "Freeing %s: %luk freed\n", what, (end - begin) >> 10);
 
-	for (; addr < end; addr += PAGE_SIZE) {
+	for (addr = begin; addr < end; addr += PAGE_SIZE) {
 		ClearPageReserved(virt_to_page(addr));
 		init_page_count(virt_to_page(addr));
 		memset((void *)addr, POISON_FREE_INITMEM, PAGE_SIZE);
-- 
1.7.7.6


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

* Re: [PATCH 1/3] x86/mm: Simplify memory mapping PFN calculation
  2012-07-14 13:41 [PATCH 1/3] x86/mm: Simplify memory mapping PFN calculation Pekka Enberg
  2012-07-14 13:41 ` [PATCH 2/3] x86/mm: Simplify for-loop in free_init_pages() Pekka Enberg
@ 2012-07-14 20:34 ` Yinghai Lu
  1 sibling, 0 replies; 8+ messages in thread
From: Yinghai Lu @ 2012-07-14 20:34 UTC (permalink / raw)
  To: Pekka Enberg; +Cc: mingo, linux-kernel, x86, Tejun Heo

On Sat, Jul 14, 2012 at 6:41 AM, Pekka Enberg <penberg@kernel.org> wrote:
> Introduce two new helper functions, addr_to_pmd_pfn() and
> addr_to_pud_pfn(), to simplify init_memory_mapping() code flow.
>
> Cc: Tejun Heo <tj@kernel.org>
> Cc: Yinghai Lu <yinghai@kernel.org>
> Signed-off-by: Pekka Enberg <penberg@kernel.org>

Acked-by: Yinghai Lu <yinghai@kernel.org>

> ---
>  arch/x86/mm/init.c |   38 +++++++++++++++++++++-----------------
>  1 files changed, 21 insertions(+), 17 deletions(-)
>
> diff --git a/arch/x86/mm/init.c b/arch/x86/mm/init.c
> index bc4e9d8..9eb53c2 100644
> --- a/arch/x86/mm/init.c
> +++ b/arch/x86/mm/init.c
> @@ -117,6 +117,16 @@ static int __meminit save_mr(struct map_range *mr, int nr_range,
>         return nr_range;
>  }
>
> +static unsigned long addr_to_pmd_pfn(unsigned long addr)
> +{
> +       return (addr >> PMD_SHIFT) << (PMD_SHIFT - PAGE_SHIFT);
> +}
> +
> +static unsigned long addr_to_pud_pfn(unsigned long addr)
> +{
> +       return (addr >> PUD_SHIFT) << (PUD_SHIFT - PAGE_SHIFT);
> +}
> +
>  /*
>   * Setup the direct mapping of the physical memory at PAGE_OFFSET.
>   * This runs before bootmem is initialized and gets pages directly from
> @@ -180,11 +190,9 @@ unsigned long __init_refok init_memory_mapping(unsigned long start,
>         if (pos == 0)
>                 end_pfn = 1<<(PMD_SHIFT - PAGE_SHIFT);
>         else
> -               end_pfn = ((pos + (PMD_SIZE - 1))>>PMD_SHIFT)
> -                                << (PMD_SHIFT - PAGE_SHIFT);
> +               end_pfn = addr_to_pmd_pfn(pos + (PMD_SIZE - 1));
>  #else /* CONFIG_X86_64 */
> -       end_pfn = ((pos + (PMD_SIZE - 1)) >> PMD_SHIFT)
> -                       << (PMD_SHIFT - PAGE_SHIFT);
> +       end_pfn = addr_to_pmd_pfn(pos + (PMD_SIZE - 1));
>  #endif
>         if (end_pfn > (end >> PAGE_SHIFT))
>                 end_pfn = end >> PAGE_SHIFT;
> @@ -194,15 +202,13 @@ unsigned long __init_refok init_memory_mapping(unsigned long start,
>         }
>
>         /* big page (2M) range */
> -       start_pfn = ((pos + (PMD_SIZE - 1))>>PMD_SHIFT)
> -                        << (PMD_SHIFT - PAGE_SHIFT);
> +       start_pfn = addr_to_pmd_pfn(pos + (PMD_SIZE - 1));
>  #ifdef CONFIG_X86_32
> -       end_pfn = (end>>PMD_SHIFT) << (PMD_SHIFT - PAGE_SHIFT);
> +       end_pfn = addr_to_pmd_pfn(end);
>  #else /* CONFIG_X86_64 */
> -       end_pfn = ((pos + (PUD_SIZE - 1))>>PUD_SHIFT)
> -                        << (PUD_SHIFT - PAGE_SHIFT);
> -       if (end_pfn > ((end>>PMD_SHIFT)<<(PMD_SHIFT - PAGE_SHIFT)))
> -               end_pfn = ((end>>PMD_SHIFT)<<(PMD_SHIFT - PAGE_SHIFT));
> +       end_pfn = addr_to_pud_pfn(pos + (PUD_SIZE - 1));
> +       if (end_pfn > addr_to_pmd_pfn(end))
> +               end_pfn = addr_to_pmd_pfn(end);
>  #endif
>
>         if (start_pfn < end_pfn) {
> @@ -213,9 +219,8 @@ unsigned long __init_refok init_memory_mapping(unsigned long start,
>
>  #ifdef CONFIG_X86_64
>         /* big page (1G) range */
> -       start_pfn = ((pos + (PUD_SIZE - 1))>>PUD_SHIFT)
> -                        << (PUD_SHIFT - PAGE_SHIFT);
> -       end_pfn = (end >> PUD_SHIFT) << (PUD_SHIFT - PAGE_SHIFT);
> +       start_pfn = addr_to_pud_pfn(pos + (PUD_SIZE - 1));
> +       end_pfn = addr_to_pud_pfn(end);
>         if (start_pfn < end_pfn) {
>                 nr_range = save_mr(mr, nr_range, start_pfn, end_pfn,
>                                 page_size_mask &
> @@ -224,9 +229,8 @@ unsigned long __init_refok init_memory_mapping(unsigned long start,
>         }
>
>         /* tail is not big page (1G) alignment */
> -       start_pfn = ((pos + (PMD_SIZE - 1))>>PMD_SHIFT)
> -                        << (PMD_SHIFT - PAGE_SHIFT);
> -       end_pfn = (end >> PMD_SHIFT) << (PMD_SHIFT - PAGE_SHIFT);
> +       start_pfn = addr_to_pmd_pfn(pos + (PMD_SIZE - 1));
> +       end_pfn = addr_to_pmd_pfn(end);
>         if (start_pfn < end_pfn) {
>                 nr_range = save_mr(mr, nr_range, start_pfn, end_pfn,
>                                 page_size_mask & (1<<PG_LEVEL_2M));
> --
> 1.7.7.6
>

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

* Re: [PATCH 2/3] x86/mm: Simplify for-loop in free_init_pages()
  2012-07-14 13:41 ` [PATCH 2/3] x86/mm: Simplify for-loop in free_init_pages() Pekka Enberg
@ 2012-07-14 20:36   ` Yinghai Lu
  2012-07-14 20:43     ` Joe Perches
  0 siblings, 1 reply; 8+ messages in thread
From: Yinghai Lu @ 2012-07-14 20:36 UTC (permalink / raw)
  To: Pekka Enberg; +Cc: mingo, linux-kernel, x86, Tejun Heo

On Sat, Jul 14, 2012 at 6:41 AM, Pekka Enberg <penberg@kernel.org> wrote:
> As a cleanup, move initial "addr" assignment to the for-loop construct
> in free_init_pages().
>
> Cc: Tejun Heo <tj@kernel.org>
> Cc: Yinghai Lu <yinghai@kernel.org>
> Signed-off-by: Pekka Enberg <penberg@kernel.org>

Acked-by: Yinghai Lu <yinghai@kernel.org>

> ---
>  arch/x86/mm/init.c |    4 +---
>  1 files changed, 1 insertions(+), 3 deletions(-)
>
> diff --git a/arch/x86/mm/init.c b/arch/x86/mm/init.c
> index 9eb53c2..e270f94 100644
> --- a/arch/x86/mm/init.c
> +++ b/arch/x86/mm/init.c
> @@ -349,8 +349,6 @@ void free_init_pages(char *what, unsigned long begin, unsigned long end)
>         if (begin >= end)
>                 return;
>
> -       addr = begin;
> -
>         /*
>          * If debugging page accesses then do not free this memory but
>          * mark them not present - any buggy init-section access will
> @@ -371,7 +369,7 @@ void free_init_pages(char *what, unsigned long begin, unsigned long end)
>
>         printk(KERN_INFO "Freeing %s: %luk freed\n", what, (end - begin) >> 10);
>
> -       for (; addr < end; addr += PAGE_SIZE) {
> +       for (addr = begin; addr < end; addr += PAGE_SIZE) {
>                 ClearPageReserved(virt_to_page(addr));
>                 init_page_count(virt_to_page(addr));
>                 memset((void *)addr, POISON_FREE_INITMEM, PAGE_SIZE);
> --
> 1.7.7.6
>

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

* Re: [PATCH 2/3] x86/mm: Simplify for-loop in free_init_pages()
  2012-07-14 20:36   ` Yinghai Lu
@ 2012-07-14 20:43     ` Joe Perches
  2012-07-14 20:48       ` Pekka Enberg
  0 siblings, 1 reply; 8+ messages in thread
From: Joe Perches @ 2012-07-14 20:43 UTC (permalink / raw)
  To: Yinghai Lu; +Cc: Pekka Enberg, mingo, linux-kernel, x86, Tejun Heo

On Sat, 2012-07-14 at 13:36 -0700, Yinghai Lu wrote:
> On Sat, Jul 14, 2012 at 6:41 AM, Pekka Enberg <penberg@kernel.org> wrote:
> > As a cleanup, move initial "addr" assignment to the for-loop construct
> > in free_init_pages().

Not really a good idea.

> > diff --git a/arch/x86/mm/init.c b/arch/x86/mm/init.c
[]
> > @@ -349,8 +349,6 @@ void free_init_pages(char *what, unsigned long begin, unsigned long end)
> >         if (begin >= end)
> >                 return;
> >
> > -       addr = begin;
> > -
> >         /*
> >          * If debugging page accesses then do not free this memory but
> >          * mark them not present - any buggy init-section access will
> > @@ -371,7 +369,7 @@ void free_init_pages(char *what, unsigned long begin, unsigned long end)
> >
> >         printk(KERN_INFO "Freeing %s: %luk freed\n", what, (end - begin) >> 10);
> >
> > -       for (; addr < end; addr += PAGE_SIZE) {
> > +       for (addr = begin; addr < end; addr += PAGE_SIZE) {
> >                 ClearPageReserved(virt_to_page(addr));
> >                 init_page_count(virt_to_page(addr));
> >                 memset((void *)addr, POISON_FREE_INITMEM, PAGE_SIZE);
> > --

Now there's an unused variable warning when CONFIG_DEBUG_PAGEALLOC


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

* Re: [PATCH 2/3] x86/mm: Simplify for-loop in free_init_pages()
  2012-07-14 20:43     ` Joe Perches
@ 2012-07-14 20:48       ` Pekka Enberg
  2012-07-14 20:51         ` Joe Perches
  2012-07-14 22:38         ` Joe Perches
  0 siblings, 2 replies; 8+ messages in thread
From: Pekka Enberg @ 2012-07-14 20:48 UTC (permalink / raw)
  To: Joe Perches; +Cc: Yinghai Lu, mingo, linux-kernel, x86, Tejun Heo

On Sat, Jul 14, 2012 at 11:43 PM, Joe Perches <joe@perches.com> wrote:
> On Sat, 2012-07-14 at 13:36 -0700, Yinghai Lu wrote:
>> On Sat, Jul 14, 2012 at 6:41 AM, Pekka Enberg <penberg@kernel.org> wrote:
>> > As a cleanup, move initial "addr" assignment to the for-loop construct
>> > in free_init_pages().
>
> Not really a good idea.

Of course it's a good idea. The current code flow makes no sense.

>> > diff --git a/arch/x86/mm/init.c b/arch/x86/mm/init.c
> []
>> > @@ -349,8 +349,6 @@ void free_init_pages(char *what, unsigned long begin, unsigned long end)
>> >         if (begin >= end)
>> >                 return;
>> >
>> > -       addr = begin;
>> > -
>> >         /*
>> >          * If debugging page accesses then do not free this memory but
>> >          * mark them not present - any buggy init-section access will
>> > @@ -371,7 +369,7 @@ void free_init_pages(char *what, unsigned long begin, unsigned long end)
>> >
>> >         printk(KERN_INFO "Freeing %s: %luk freed\n", what, (end - begin) >> 10);
>> >
>> > -       for (; addr < end; addr += PAGE_SIZE) {
>> > +       for (addr = begin; addr < end; addr += PAGE_SIZE) {
>> >                 ClearPageReserved(virt_to_page(addr));
>> >                 init_page_count(virt_to_page(addr));
>> >                 memset((void *)addr, POISON_FREE_INITMEM, PAGE_SIZE);
>> > --
>
> Now there's an unused variable warning when CONFIG_DEBUG_PAGEALLOC

Sure, that needs fixing. It'd probably be simplest to introduce a
__free_init_pages() helper.

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

* Re: [PATCH 2/3] x86/mm: Simplify for-loop in free_init_pages()
  2012-07-14 20:48       ` Pekka Enberg
@ 2012-07-14 20:51         ` Joe Perches
  2012-07-14 22:38         ` Joe Perches
  1 sibling, 0 replies; 8+ messages in thread
From: Joe Perches @ 2012-07-14 20:51 UTC (permalink / raw)
  To: Pekka Enberg; +Cc: Yinghai Lu, mingo, linux-kernel, x86, Tejun Heo

On Sat, 2012-07-14 at 23:48 +0300, Pekka Enberg wrote:
> On Sat, Jul 14, 2012 at 11:43 PM, Joe Perches <joe@perches.com> wrote:
> > On Sat, 2012-07-14 at 13:36 -0700, Yinghai Lu wrote:
> >> On Sat, Jul 14, 2012 at 6:41 AM, Pekka Enberg <penberg@kernel.org> wrote:
> >> > As a cleanup, move initial "addr" assignment to the for-loop construct
> >> > in free_init_pages().
> >
> > Not really a good idea.
> 
> Of course it's a good idea. The current code flow makes no sense.
> 
> >> > diff --git a/arch/x86/mm/init.c b/arch/x86/mm/init.c
> > []
> >> > @@ -349,8 +349,6 @@ void free_init_pages(char *what, unsigned long begin, unsigned long end)
> >> >         if (begin >= end)
> >> >                 return;
> >> >
> >> > -       addr = begin;
> >> > -
> >> >         /*
> >> >          * If debugging page accesses then do not free this memory but
> >> >          * mark them not present - any buggy init-section access will
> >> > @@ -371,7 +369,7 @@ void free_init_pages(char *what, unsigned long begin, unsigned long end)
> >> >
> >> >         printk(KERN_INFO "Freeing %s: %luk freed\n", what, (end - begin) >> 10);
> >> >
> >> > -       for (; addr < end; addr += PAGE_SIZE) {
> >> > +       for (addr = begin; addr < end; addr += PAGE_SIZE) {
> >> >                 ClearPageReserved(virt_to_page(addr));
> >> >                 init_page_count(virt_to_page(addr));
> >> >                 memset((void *)addr, POISON_FREE_INITMEM, PAGE_SIZE);
> >> > --
> >
> > Now there's an unused variable warning when CONFIG_DEBUG_PAGEALLOC
> 
> Sure, that needs fixing. It'd probably be simplest to introduce a
> __free_init_pages() helper.
> 

The proposed patch introduces a warning.
That's the only reason it's not a good idea.
There are lots of ways to fix it.



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

* Re: [PATCH 2/3] x86/mm: Simplify for-loop in free_init_pages()
  2012-07-14 20:48       ` Pekka Enberg
  2012-07-14 20:51         ` Joe Perches
@ 2012-07-14 22:38         ` Joe Perches
  1 sibling, 0 replies; 8+ messages in thread
From: Joe Perches @ 2012-07-14 22:38 UTC (permalink / raw)
  To: Pekka Enberg; +Cc: Yinghai Lu, mingo, linux-kernel, x86, Tejun Heo

On Sat, 2012-07-14 at 23:48 +0300, Pekka Enberg wrote:
> On Sat, Jul 14, 2012 at 11:43 PM, Joe Perches <joe@perches.com> wrote:
> > On Sat, 2012-07-14 at 13:36 -0700, Yinghai Lu wrote:
> >> On Sat, Jul 14, 2012 at 6:41 AM, Pekka Enberg <penberg@kernel.org> wrote:
> >> > As a cleanup, move initial "addr" assignment to the for-loop construct
> >> > in free_init_pages().
> >
> > Not really a good idea.
> 
> Of course it's a good idea. The current code flow makes no sense.
> 
> >> > diff --git a/arch/x86/mm/init.c b/arch/x86/mm/init.c
> > []
> >> > @@ -349,8 +349,6 @@ void free_init_pages(char *what, unsigned long begin, unsigned long end)
> >> >         if (begin >= end)
> >> >                 return;
> >> >
> >> > -       addr = begin;
> >> > -
> >> >         /*
> >> >          * If debugging page accesses then do not free this memory but
> >> >          * mark them not present - any buggy init-section access will
> >> > @@ -371,7 +369,7 @@ void free_init_pages(char *what, unsigned long begin, unsigned long end)
> >> >
> >> >         printk(KERN_INFO "Freeing %s: %luk freed\n", what, (end - begin) >> 10);
> >> >
> >> > -       for (; addr < end; addr += PAGE_SIZE) {
> >> > +       for (addr = begin; addr < end; addr += PAGE_SIZE) {
> >> >                 ClearPageReserved(virt_to_page(addr));
> >> >                 init_page_count(virt_to_page(addr));
> >> >                 memset((void *)addr, POISON_FREE_INITMEM, PAGE_SIZE);
> >> > --
> >
> > Now there's an unused variable warning when CONFIG_DEBUG_PAGEALLOC
> 
> Sure, that needs fixing. It'd probably be simplest to introduce a
> __free_init_pages() helper.
> 

Perhaps:

 arch/x86/mm/init.c |   14 ++++++--------
 1 files changed, 6 insertions(+), 8 deletions(-)

diff --git a/arch/x86/mm/init.c b/arch/x86/mm/init.c
index bc4e9d8..1023484 100644
--- a/arch/x86/mm/init.c
+++ b/arch/x86/mm/init.c
@@ -330,7 +330,6 @@ int devmem_is_allowed(unsigned long pagenr)
 
 void free_init_pages(char *what, unsigned long begin, unsigned long end)
 {
-	unsigned long addr;
 	unsigned long begin_aligned, end_aligned;
 
 	/* Make sure boundaries are page aligned */
@@ -345,8 +344,6 @@ void free_init_pages(char *what, unsigned long begin, unsigned long end)
 	if (begin >= end)
 		return;
 
-	addr = begin;
-
 	/*
 	 * If debugging page accesses then do not free this memory but
 	 * mark them not present - any buggy init-section access will
@@ -367,12 +364,13 @@ void free_init_pages(char *what, unsigned long begin, unsigned long end)
 
 	printk(KERN_INFO "Freeing %s: %luk freed\n", what, (end - begin) >> 10);
 
-	for (; addr < end; addr += PAGE_SIZE) {
-		ClearPageReserved(virt_to_page(addr));
-		init_page_count(virt_to_page(addr));
-		memset((void *)addr, POISON_FREE_INITMEM, PAGE_SIZE);
-		free_page(addr);
+	while (begin < end) {
+		ClearPageReserved(virt_to_page(begin));
+		init_page_count(virt_to_page(begin));
+		memset((void *)begin, POISON_FREE_INITMEM, PAGE_SIZE);
+		free_page(begin);
 		totalram_pages++;
+		begin += PAGE_SIZE;
 	}
 #endif
 }



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

end of thread, other threads:[~2012-07-14 22:38 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2012-07-14 13:41 [PATCH 1/3] x86/mm: Simplify memory mapping PFN calculation Pekka Enberg
2012-07-14 13:41 ` [PATCH 2/3] x86/mm: Simplify for-loop in free_init_pages() Pekka Enberg
2012-07-14 20:36   ` Yinghai Lu
2012-07-14 20:43     ` Joe Perches
2012-07-14 20:48       ` Pekka Enberg
2012-07-14 20:51         ` Joe Perches
2012-07-14 22:38         ` Joe Perches
2012-07-14 20:34 ` [PATCH 1/3] x86/mm: Simplify memory mapping PFN calculation Yinghai Lu

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