linux-mm.kvack.org archive mirror
 help / color / mirror / Atom feed
From: Dave Hansen <dave@sr71.net>
To: Seth Jennings <sjenning@linux.vnet.ibm.com>
Cc: Greg Kroah-Hartman <gregkh@linuxfoundation.org>,
	Nathan Fontenot <nfont@linux.vnet.ibm.com>,
	Cody P Schafer <cody@linux.vnet.ibm.com>,
	Andrew Morton <akpm@linux-foundation.org>,
	Lai Jiangshan <laijs@cn.fujitsu.com>,
	"Rafael J. Wysocki" <rafael.j.wysocki@intel.com>,
	linux-kernel@vger.kernel.org, linux-mm@kvack.org
Subject: Re: [RFC][PATCH] drivers: base: dynamic memory block creation
Date: Wed, 14 Aug 2013 13:47:27 -0700	[thread overview]
Message-ID: <520BECDF.8060501@sr71.net> (raw)
In-Reply-To: <1376508705-3188-1-git-send-email-sjenning@linux.vnet.ibm.com>

On 08/14/2013 12:31 PM, Seth Jennings wrote:
> There was a significant amount of refactoring to allow for this but
> IMHO, the code is much easier to understand now.
...
>  drivers/base/memory.c  | 248 +++++++++++++++++++++++++++++++++++++------------
>  include/linux/memory.h |   1 -
>  2 files changed, 188 insertions(+), 61 deletions(-)

Adding 120 lines of code made it easier to understand? ;)

> diff --git a/drivers/base/memory.c b/drivers/base/memory.c
> index 2b7813e..392ccd3 100644
> --- a/drivers/base/memory.c
> +++ b/drivers/base/memory.c
> @@ -30,7 +30,7 @@ static DEFINE_MUTEX(mem_sysfs_mutex);
>  
>  #define MEMORY_CLASS_NAME	"memory"
>  
> -static int sections_per_block;
> +static int sections_per_block __read_mostly;
>  
>  static inline int base_memory_block_id(int section_nr)
>  {
> @@ -47,6 +47,9 @@ static struct bus_type memory_subsys = {
>  	.offline = memory_subsys_offline,
>  };
>  
> +static unsigned long *memblock_present;
> +static bool largememory_enable __read_mostly;

How would you see this getting used in practice?  Are you just going to
set this by default on ppc?  Or, would you ask the distros to put it on
the command-line by default?  Would it only affect machines larger than
a certain size?

This approach breaks the ABI, right?.  An existing tool would not work
with this patch (plus boot option) since it would not know how to
show/hide things.  It lets _part_ of those existing tools get reused
since they only have to be taught how to show/hide things.

I'd find this really intriguing if you found a way to keep even the old
tools working.  Instead of having an explicit show/hide, why couldn't
you just create the entries on open(), for instance?

>  int register_memory_notifier(struct notifier_block *nb)
> @@ -565,16 +568,13 @@ static const struct attribute_group *memory_memblk_attr_groups[] = {
>  static
>  int register_memory(struct memory_block *memory)
>  {
> -	int error;
> -
>  	memory->dev.bus = &memory_subsys;
>  	memory->dev.id = memory->start_section_nr / sections_per_block;
>  	memory->dev.release = memory_block_release;
>  	memory->dev.groups = memory_memblk_attr_groups;
>  	memory->dev.offline = memory->state == MEM_OFFLINE;
>  
> -	error = device_register(&memory->dev);
> -	return error;
> +	return device_register(&memory->dev);
>  }

This kind of simplification could surely stand in its own patch.

>  static int init_memory_block(struct memory_block **memory,
> @@ -582,67 +582,72 @@ static int init_memory_block(struct memory_block **memory,
>  {
>  	struct memory_block *mem;
>  	unsigned long start_pfn;
> -	int scn_nr;
> -	int ret = 0;
> +	int scn_nr, ret, memblock_id;
>  
> +	*memory = NULL;
>  	mem = kzalloc(sizeof(*mem), GFP_KERNEL);
>  	if (!mem)
>  		return -ENOMEM;
>  
>  	scn_nr = __section_nr(section);
> +	memblock_id = base_memory_block_id(scn_nr);
>  	mem->start_section_nr =
>  			base_memory_block_id(scn_nr) * sections_per_block;
>  	mem->end_section_nr = mem->start_section_nr + sections_per_block - 1;
>  	mem->state = state;
> -	mem->section_count++;
>  	mutex_init(&mem->state_mutex);
>  	start_pfn = section_nr_to_pfn(mem->start_section_nr);
>  	mem->phys_device = arch_get_memory_phys_device(start_pfn);
>  
>  	ret = register_memory(mem);
> +	if (ret) {
> +		kfree(mem);
> +		return ret;
> +	}
>  
>  	*memory = mem;
> -	return ret;
> +	return 0;
>  }

memblock_id doesn't appear to ever get used.  This also appears to
change the conventions about where the 'memory_block' is allocated and
freed.  It isn't immediately clear why it needed to be changed.

Looking at the rest, this _really_ needs to get refactored before it's
reviewable.

> +static ssize_t memory_present_show(struct device *dev,
> +				  struct device_attribute *attr, char *buf)
> +{
> +	int n_bits, ret;
> +
> +	n_bits = NR_MEM_SECTIONS / sections_per_block;
> +	ret = bitmap_scnlistprintf(buf, PAGE_SIZE - 2,
> +				memblock_present, n_bits);
> +	buf[ret++] = '\n';
> +	buf[ret] = '\0';
> +
> +	return ret;
> +}

Doesn't this break the one-value-per-file rule?

--
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: <a href=mailto:"dont@kvack.org"> email@kvack.org </a>

  parent reply	other threads:[~2013-08-14 20:47 UTC|newest]

Thread overview: 19+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2013-08-14 19:31 Seth Jennings
2013-08-14 19:40 ` Greg Kroah-Hartman
2013-08-16 19:07   ` Seth Jennings
2013-08-14 19:43 ` Greg Kroah-Hartman
2013-08-14 20:05   ` Dave Hansen
2013-08-14 20:35     ` Greg Kroah-Hartman
2013-08-14 21:16       ` Seth Jennings
2013-08-14 21:37       ` Yinghai Lu
2013-08-14 21:52         ` Seth Jennings
2013-08-14 23:20           ` Yinghai Lu
2013-08-15  2:12           ` Michael Ellerman
2013-08-14 20:40 ` Nathan Fontenot
2013-08-14 20:47 ` Dave Hansen [this message]
2013-08-14 21:14   ` Seth Jennings
2013-08-14 21:36     ` Dave Hansen
2013-08-14 21:37     ` Cody P Schafer
2013-08-14 21:49       ` Dave Hansen
2013-08-15  0:01 ` Rafael J. Wysocki
2013-08-16 18:41   ` Seth Jennings

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=520BECDF.8060501@sr71.net \
    --to=dave@sr71.net \
    --cc=akpm@linux-foundation.org \
    --cc=cody@linux.vnet.ibm.com \
    --cc=gregkh@linuxfoundation.org \
    --cc=laijs@cn.fujitsu.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-mm@kvack.org \
    --cc=nfont@linux.vnet.ibm.com \
    --cc=rafael.j.wysocki@intel.com \
    --cc=sjenning@linux.vnet.ibm.com \
    /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