From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from psmtp.com (na3sys010amx175.postini.com [74.125.245.175]) by kanga.kvack.org (Postfix) with SMTP id F0B796B0033 for ; Thu, 22 Aug 2013 04:21:06 -0400 (EDT) Received: from m4.gw.fujitsu.co.jp (unknown [10.0.50.74]) by fgwmail5.fujitsu.co.jp (Postfix) with ESMTP id A243B3EE1DD for ; Thu, 22 Aug 2013 17:21:04 +0900 (JST) Received: from smail (m4 [127.0.0.1]) by outgoing.m4.gw.fujitsu.co.jp (Postfix) with ESMTP id 9084E45DE55 for ; Thu, 22 Aug 2013 17:21:04 +0900 (JST) Received: from s4.gw.fujitsu.co.jp (s4.gw.fujitsu.co.jp [10.0.50.94]) by m4.gw.fujitsu.co.jp (Postfix) with ESMTP id 6A62645DE4D for ; Thu, 22 Aug 2013 17:21:04 +0900 (JST) Received: from s4.gw.fujitsu.co.jp (localhost.localdomain [127.0.0.1]) by s4.gw.fujitsu.co.jp (Postfix) with ESMTP id 471031DB8032 for ; Thu, 22 Aug 2013 17:21:04 +0900 (JST) Received: from g01jpfmpwkw03.exch.g01.fujitsu.local (g01jpfmpwkw03.exch.g01.fujitsu.local [10.0.193.57]) by s4.gw.fujitsu.co.jp (Postfix) with ESMTP id D3A4E1DB803B for ; Thu, 22 Aug 2013 17:21:03 +0900 (JST) Message-ID: <5215C9B3.4090608@jp.fujitsu.com> Date: Thu, 22 Aug 2013 17:20:03 +0900 From: Yasuaki Ishimatsu MIME-Version: 1.0 Subject: Re: [PATCH 7/7] drivers: base: refactor add_memory_section() to add_memory_block() References: <1377018783-26756-1-git-send-email-sjenning@linux.vnet.ibm.com> <1377018783-26756-7-git-send-email-sjenning@linux.vnet.ibm.com> In-Reply-To: <1377018783-26756-7-git-send-email-sjenning@linux.vnet.ibm.com> Content-Type: text/plain; charset="ISO-2022-JP" Content-Transfer-Encoding: 7bit Sender: owner-linux-mm@kvack.org List-ID: To: Seth Jennings Cc: Greg Kroah-Hartman , Dave Hansen , Nathan Fontenot , Cody P Schafer , Andrew Morton , Lai Jiangshan , "Rafael J. Wysocki" , Yinghai Lu , Wanpeng Li , linux-kernel@vger.kernel.org, linux-mm@kvack.org, linuxppc-dev@lists.ozlabs.org (2013/08/21 2:13), Seth Jennings wrote: > Right now memory_dev_init() maintains the memory block pointer > between iterations of add_memory_section(). This is nasty. > > This patch refactors add_memory_section() to become add_memory_block(). > The refactoring pulls the section scanning out of memory_dev_init() > and simplifies the signature. > > Signed-off-by: Seth Jennings > --- > drivers/base/memory.c | 48 +++++++++++++++++++++--------------------------- > 1 file changed, 21 insertions(+), 27 deletions(-) > > diff --git a/drivers/base/memory.c b/drivers/base/memory.c > index 7d9d3bc..021283a 100644 > --- a/drivers/base/memory.c > +++ b/drivers/base/memory.c > @@ -602,32 +602,31 @@ static int init_memory_block(struct memory_block **memory, > return ret; > } > > -static int add_memory_section(struct mem_section *section, > - struct memory_block **mem_p) > +static int add_memory_block(int base_section_nr) > { > - struct memory_block *mem = NULL; > - int scn_nr = __section_nr(section); > - int ret = 0; > - > - if (mem_p && *mem_p) { > - if (scn_nr >= (*mem_p)->start_section_nr && > - scn_nr <= (*mem_p)->end_section_nr) { > - mem = *mem_p; > - } > - } > + struct memory_block *mem; > + int i, ret, section_count = 0, section_nr; > > - if (mem) > - mem->section_count++; > - else { > - ret = init_memory_block(&mem, section, MEM_ONLINE); > - /* store memory_block pointer for next loop */ > - if (!ret && mem_p) > - *mem_p = mem; > + for (i = base_section_nr; > + (i < base_section_nr + sections_per_block) && i < NR_MEM_SECTIONS; > + i++) { > + if (!present_section_nr(i)) > + continue; > + if (section_count == 0) > + section_nr = i; > + section_count++; > } > > - return ret; > + if (section_count == 0) > + return 0; > + ret = init_memory_block(&mem, __nr_to_section(section_nr), MEM_ONLINE); > + if (ret) > + return ret; > + mem->section_count = section_count; > + return 0; > } > > + > /* > * need an interface for the VM to add new memory regions, > * but without onlining it. > @@ -733,7 +732,6 @@ int __init memory_dev_init(void) > int ret; > int err; > unsigned long block_sz; > - struct memory_block *mem = NULL; > > ret = subsys_system_register(&memory_subsys, memory_root_attr_groups); > if (ret) > @@ -747,12 +745,8 @@ int __init memory_dev_init(void) > * during boot and have been initialized > */ > mutex_lock(&mem_sysfs_mutex); > - for (i = 0; i < NR_MEM_SECTIONS; i++) { > - if (!present_section_nr(i)) > - continue; > - /* don't need to reuse memory_block if only one per block */ > - err = add_memory_section(__nr_to_section(i), > - (sections_per_block == 1) ? NULL : &mem); > + for (i = 0; i < NR_MEM_SECTIONS; i += sections_per_block) { Why do you remove present_setcion_nr() check? > + err = add_memory_block(i); > if (!ret) Thanks, Yasuaki Ishimatasu > ret = err; > } > -- To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to majordomo@kvack.org. For more info on Linux MM, see: http://www.linux-mm.org/ . Don't email: email@kvack.org