public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
From: Joe Perches <joe@perches.com>
To: Pekka Enberg <penberg@kernel.org>
Cc: Yinghai Lu <yinghai@kernel.org>,
	mingo@kernel.org, linux-kernel@vger.kernel.org, x86@kernel.org,
	Tejun Heo <tj@kernel.org>
Subject: Re: [PATCH 2/3] x86/mm: Simplify for-loop in free_init_pages()
Date: Sat, 14 Jul 2012 15:38:09 -0700	[thread overview]
Message-ID: <1342305489.8377.47.camel@joe2Laptop> (raw)
In-Reply-To: <CAOJsxLEU=Ls1XtS0nndmJrvAObHuaasHBu8=7iFbjYVBX8g=Ng@mail.gmail.com>

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
 }



  parent reply	other threads:[~2012-07-14 22:38 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
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 [this message]
2012-07-14 20:34 ` [PATCH 1/3] x86/mm: Simplify memory mapping PFN calculation Yinghai Lu

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1342305489.8377.47.camel@joe2Laptop \
    --to=joe@perches.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mingo@kernel.org \
    --cc=penberg@kernel.org \
    --cc=tj@kernel.org \
    --cc=x86@kernel.org \
    --cc=yinghai@kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox