Re: [PATCH 4/9] v3 Allow memory blocks to span multiple memory sections

2010-10-04 Thread KAMEZAWA Hiroyuki
On Fri, 01 Oct 2010 14:00:50 -0500
Nathan Fontenot nf...@austin.ibm.com wrote:

 Update the memory sysfs code such that each sysfs memory directory is now
 considered a memory block that can span multiple memory sections per
 memory block.  The default size of each memory block is SECTION_SIZE_BITS
 to maintain the current behavior of having a single memory section per
 memory block (i.e. one sysfs directory per memory section).
 
 For architectures that want to have memory blocks span multiple
 memory sections they need only define their own memory_block_size_bytes()
 routine.
 
This should be commented in code before MEMORY_BLOCK_SIZE declaration.

 Signed-off-by: Nathan Fontenot nf...@austin.ibm.com
 

Reviewed-by: KAMEZAWA Hiroyuki kamezawa.hir...@jp.fujitsu.com




___
Linuxppc-dev mailing list
Linuxppc-dev@lists.ozlabs.org
https://lists.ozlabs.org/listinfo/linuxppc-dev


Re: [PATCH 4/9] v3 Allow memory blocks to span multiple memory sections

2010-10-01 Thread Nathan Fontenot
On 10/01/2010 01:52 PM, Robin Holt wrote:
 On Fri, Oct 01, 2010 at 01:31:51PM -0500, Nathan Fontenot wrote:
 Update the memory sysfs code such that each sysfs memory directory is now
 considered a memory block that can span multiple memory sections per
 memory block.  The default size of each memory block is SECTION_SIZE_BITS
 to maintain the current behavior of having a single memory section per
 memory block (i.e. one sysfs directory per memory section).

 For architectures that want to have memory blocks span multiple
 memory sections they need only define their own memory_block_size_bytes()
 routine.

 Signed-off-by: Nathan Fontenot nf...@austin.ibm.com

 ---
  drivers/base/memory.c |  155 
 ++
  1 file changed, 108 insertions(+), 47 deletions(-)

 Index: linux-next/drivers/base/memory.c
 ===
 --- linux-next.orig/drivers/base/memory.c2010-09-30 14:13:50.0 
 -0500
 +++ linux-next/drivers/base/memory.c 2010-09-30 14:46:00.0 -0500
 ...
 +static unsigned long get_memory_block_size(void)
 +{
 +u32 block_sz;
 ^^^
 
 I think this should be unsigned long.  u32 will work, but everything
 else has been changed to use unsigned long.  If you disagree, I will
 happily acquiesce as nothing is currently broken.  If SGI decides to make
 memory_block_size_bytes more dynamic, we will fix this up at that time.

You're right, that should have been made an unsigned long also.  I'll attach a 
new
patch with that corrected.

-Nathan
___
Linuxppc-dev mailing list
Linuxppc-dev@lists.ozlabs.org
https://lists.ozlabs.org/listinfo/linuxppc-dev


Re: [PATCH 4/9] v3 Allow memory blocks to span multiple memory sections

2010-10-01 Thread Nathan Fontenot
Update the memory sysfs code such that each sysfs memory directory is now
considered a memory block that can span multiple memory sections per
memory block.  The default size of each memory block is SECTION_SIZE_BITS
to maintain the current behavior of having a single memory section per
memory block (i.e. one sysfs directory per memory section).

For architectures that want to have memory blocks span multiple
memory sections they need only define their own memory_block_size_bytes()
routine.

Signed-off-by: Nathan Fontenot nf...@austin.ibm.com

Updated patch to correct get_memory_block_size() variable block_sz to be
an unsigned long.

---
 drivers/base/memory.c |  155 ++
 1 file changed, 108 insertions(+), 47 deletions(-)

Index: linux-next/drivers/base/memory.c
===
--- linux-next.orig/drivers/base/memory.c   2010-09-30 14:13:50.0 
-0500
+++ linux-next/drivers/base/memory.c2010-10-01 13:50:19.0 -0500
@@ -30,6 +30,14 @@
 static DEFINE_MUTEX(mem_sysfs_mutex);
 
 #define MEMORY_CLASS_NAME  memory
+#define MIN_MEMORY_BLOCK_SIZE  (1  SECTION_SIZE_BITS)
+
+static int sections_per_block;
+
+static inline int base_memory_block_id(int section_nr)
+{
+   return section_nr / sections_per_block;
+}
 
 static struct sysdev_class memory_sysdev_class = {
.name = MEMORY_CLASS_NAME,
@@ -84,28 +92,47 @@
  * register_memory - Setup a sysfs device for a memory block
  */
 static
-int register_memory(struct memory_block *memory, struct mem_section *section)
+int register_memory(struct memory_block *memory)
 {
int error;
 
memory-sysdev.cls = memory_sysdev_class;
-   memory-sysdev.id = __section_nr(section);
+   memory-sysdev.id = memory-phys_index / sections_per_block;
 
error = sysdev_register(memory-sysdev);
return error;
 }
 
 static void
-unregister_memory(struct memory_block *memory, struct mem_section *section)
+unregister_memory(struct memory_block *memory)
 {
BUG_ON(memory-sysdev.cls != memory_sysdev_class);
-   BUG_ON(memory-sysdev.id != __section_nr(section));
 
/* drop the ref. we got in remove_memory_block() */
kobject_put(memory-sysdev.kobj);
sysdev_unregister(memory-sysdev);
 }
 
+unsigned long __weak memory_block_size_bytes(void)
+{
+   return MIN_MEMORY_BLOCK_SIZE;
+}
+
+static unsigned long get_memory_block_size(void)
+{
+   unsigned long block_sz;
+
+   block_sz = memory_block_size_bytes();
+
+   /* Validate blk_sz is a power of 2 and not less than section size */
+   if ((block_sz  (block_sz - 1)) || (block_sz  MIN_MEMORY_BLOCK_SIZE)) {
+   WARN_ON(1);
+   block_sz = MIN_MEMORY_BLOCK_SIZE;
+   }
+
+   return block_sz;
+}
+
 /*
  * use this as the physical section index that this memsection
  * uses.
@@ -116,7 +143,7 @@
 {
struct memory_block *mem =
container_of(dev, struct memory_block, sysdev);
-   return sprintf(buf, %08lx\n, mem-phys_index);
+   return sprintf(buf, %08lx\n, mem-phys_index / sections_per_block);
 }
 
 /*
@@ -125,13 +152,16 @@
 static ssize_t show_mem_removable(struct sys_device *dev,
struct sysdev_attribute *attr, char *buf)
 {
-   unsigned long start_pfn;
-   int ret;
+   unsigned long i, pfn;
+   int ret = 1;
struct memory_block *mem =
container_of(dev, struct memory_block, sysdev);
 
-   start_pfn = section_nr_to_pfn(mem-phys_index);
-   ret = is_mem_section_removable(start_pfn, PAGES_PER_SECTION);
+   for (i = 0; i  sections_per_block; i++) {
+   pfn = section_nr_to_pfn(mem-phys_index + i);
+   ret = is_mem_section_removable(pfn, PAGES_PER_SECTION);
+   }
+
return sprintf(buf, %d\n, ret);
 }
 
@@ -184,17 +214,14 @@
  * OK to have direct references to sparsemem variables in here.
  */
 static int
-memory_block_action(struct memory_block *mem, unsigned long action)
+memory_section_action(unsigned long phys_index, unsigned long action)
 {
int i;
-   unsigned long psection;
unsigned long start_pfn, start_paddr;
struct page *first_page;
int ret;
-   int old_state = mem-state;
 
-   psection = mem-phys_index;
-   first_page = pfn_to_page(psection  PFN_SECTION_SHIFT);
+   first_page = pfn_to_page(phys_index  PFN_SECTION_SHIFT);
 
/*
 * The probe routines leave the pages reserved, just
@@ -207,8 +234,8 @@
continue;
 
printk(KERN_WARNING section number %ld page number %d 
-   not reserved, was it already online? \n,
-   psection, i);
+   not reserved, was it already online?\n,
+   phys_index, i);
return -EBUSY;
 

Re: [PATCH 4/9] v3 Allow memory blocks to span multiple memory sections

2010-10-01 Thread Robin Holt
On Fri, Oct 01, 2010 at 01:31:51PM -0500, Nathan Fontenot wrote:
 Update the memory sysfs code such that each sysfs memory directory is now
 considered a memory block that can span multiple memory sections per
 memory block.  The default size of each memory block is SECTION_SIZE_BITS
 to maintain the current behavior of having a single memory section per
 memory block (i.e. one sysfs directory per memory section).
 
 For architectures that want to have memory blocks span multiple
 memory sections they need only define their own memory_block_size_bytes()
 routine.
 
 Signed-off-by: Nathan Fontenot nf...@austin.ibm.com
 
 ---
  drivers/base/memory.c |  155 
 ++
  1 file changed, 108 insertions(+), 47 deletions(-)
 
 Index: linux-next/drivers/base/memory.c
 ===
 --- linux-next.orig/drivers/base/memory.c 2010-09-30 14:13:50.0 
 -0500
 +++ linux-next/drivers/base/memory.c  2010-09-30 14:46:00.0 -0500
...
 +static unsigned long get_memory_block_size(void)
 +{
 + u32 block_sz;
^^^

I think this should be unsigned long.  u32 will work, but everything
else has been changed to use unsigned long.  If you disagree, I will
happily acquiesce as nothing is currently broken.  If SGI decides to make
memory_block_size_bytes more dynamic, we will fix this up at that time.

Robin
___
Linuxppc-dev mailing list
Linuxppc-dev@lists.ozlabs.org
https://lists.ozlabs.org/listinfo/linuxppc-dev


Re: [PATCH 4/9] v3 Allow memory blocks to span multiple memory sections

2010-10-01 Thread Robin Holt
On Fri, Oct 01, 2010 at 02:00:50PM -0500, Nathan Fontenot wrote:
 Update the memory sysfs code such that each sysfs memory directory is now
 considered a memory block that can span multiple memory sections per
 memory block.  The default size of each memory block is SECTION_SIZE_BITS
 to maintain the current behavior of having a single memory section per
 memory block (i.e. one sysfs directory per memory section).
 
 For architectures that want to have memory blocks span multiple
 memory sections they need only define their own memory_block_size_bytes()
 routine.
 
 Signed-off-by: Nathan Fontenot nf...@austin.ibm.com

Reviewed-by: Robin Holt h...@sgi.com
___
Linuxppc-dev mailing list
Linuxppc-dev@lists.ozlabs.org
https://lists.ozlabs.org/listinfo/linuxppc-dev