2011-05-11 17:02:59

by Anton Blanchard

[permalink] [raw]
Subject: [PATCH] memory hotplug: Speed up add/remove when blocks are larger than PAGES_PER_SECTION


On ppc64 the minimum memory section for hotplug is 16MB but most
recent machines have a memory block size of 256MB. This means
memory_block_change_state does 16 separate calls to
memory_section_action.

This also means we call the notifiers 16 times and the hook
in the ehea network driver is quite costly. To offline one 256MB
region takes:

# time echo offline > /sys/devices/system/memory/memory32/state
7.9s

This patch removes the loop and calls online_pages or
remove_memory once for the entire region and in doing so makes
the logic simpler since we don't have to back out if things fail
part way through.

The same test to offline one region now takes:

# time echo online > /sys/devices/system/memory/memory32/state
0.67s

Over 11 times faster.

Signed-off-by: Anton Blanchard <[email protected]>
---

Index: linux-2.6-work/drivers/base/memory.c
===================================================================
--- linux-2.6-work.orig/drivers/base/memory.c 2011-05-11 14:04:46.878078801 +1000
+++ linux-2.6-work/drivers/base/memory.c 2011-05-11 14:10:52.134521072 +1000
@@ -228,10 +228,11 @@ int memory_isolate_notify(unsigned long
* OK to have direct references to sparsemem variables in here.
*/
static int
-memory_section_action(unsigned long phys_index, unsigned long action)
+memory_block_action(unsigned long phys_index, unsigned long action)
{
int i;
unsigned long start_pfn, start_paddr;
+ unsigned long nr_pages = PAGES_PER_SECTION * sections_per_block;
struct page *first_page;
int ret;

@@ -243,7 +244,7 @@ memory_section_action(unsigned long phys
* that way.
*/
if (action == MEM_ONLINE) {
- for (i = 0; i < PAGES_PER_SECTION; i++) {
+ for (i = 0; i < nr_pages; i++) {
if (PageReserved(first_page+i))
continue;

@@ -257,12 +258,12 @@ memory_section_action(unsigned long phys
switch (action) {
case MEM_ONLINE:
start_pfn = page_to_pfn(first_page);
- ret = online_pages(start_pfn, PAGES_PER_SECTION);
+ ret = online_pages(start_pfn, nr_pages);
break;
case MEM_OFFLINE:
start_paddr = page_to_pfn(first_page) << PAGE_SHIFT;
ret = remove_memory(start_paddr,
- PAGES_PER_SECTION << PAGE_SHIFT);
+ nr_pages << PAGE_SHIFT);
break;
default:
WARN(1, KERN_WARNING "%s(%ld, %ld) unknown action: "
@@ -288,20 +289,11 @@ static int memory_block_change_state(str
if (to_state == MEM_OFFLINE)
mem->state = MEM_GOING_OFFLINE;

- for (i = 0; i < sections_per_block; i++) {
- ret = memory_section_action(mem->start_section_nr + i,
- to_state);
- if (ret)
- break;
- }
-
- if (ret) {
- for (i = 0; i < sections_per_block; i++)
- memory_section_action(mem->start_section_nr + i,
- from_state_req);
+ ret = memory_block_action(mem->start_section_nr, to_state);

+ if (ret)
mem->state = from_state_req;
- } else
+ else
mem->state = to_state;

out:


2011-05-11 15:58:24

by Greg KH

[permalink] [raw]
Subject: Re: [PATCH] memory hotplug: Speed up add/remove when blocks are larger than PAGES_PER_SECTION

On Wed, May 11, 2011 at 05:25:14PM +1000, Anton Blanchard wrote:
>
> On ppc64 the minimum memory section for hotplug is 16MB but most
> recent machines have a memory block size of 256MB. This means
> memory_block_change_state does 16 separate calls to
> memory_section_action.
>
> This also means we call the notifiers 16 times and the hook
> in the ehea network driver is quite costly. To offline one 256MB
> region takes:
>
> # time echo offline > /sys/devices/system/memory/memory32/state
> 7.9s
>
> This patch removes the loop and calls online_pages or
> remove_memory once for the entire region and in doing so makes
> the logic simpler since we don't have to back out if things fail
> part way through.
>
> The same test to offline one region now takes:
>
> # time echo online > /sys/devices/system/memory/memory32/state
> 0.67s
>
> Over 11 times faster.

Very nice job, I'll queue this up for .40.

thanks,

greg k-h

2011-05-11 22:23:14

by Greg KH

[permalink] [raw]
Subject: Re: [PATCH] memory hotplug: Speed up add/remove when blocks are larger than PAGES_PER_SECTION

On Wed, May 11, 2011 at 05:25:14PM +1000, Anton Blanchard wrote:
>
> On ppc64 the minimum memory section for hotplug is 16MB but most
> recent machines have a memory block size of 256MB. This means
> memory_block_change_state does 16 separate calls to
> memory_section_action.
>
> This also means we call the notifiers 16 times and the hook
> in the ehea network driver is quite costly. To offline one 256MB
> region takes:
>
> # time echo offline > /sys/devices/system/memory/memory32/state
> 7.9s
>
> This patch removes the loop and calls online_pages or
> remove_memory once for the entire region and in doing so makes
> the logic simpler since we don't have to back out if things fail
> part way through.
>
> The same test to offline one region now takes:
>
> # time echo online > /sys/devices/system/memory/memory32/state
> 0.67s
>
> Over 11 times faster.
>
> Signed-off-by: Anton Blanchard <[email protected]>

Your patch introduced a compiler warning, care to send a follow-on patch
fixing this up:
drivers/base/memory.c: In function ‘memory_block_change_state’:
drivers/base/memory.c:281:6: warning: unused variable ‘i’

thanks,

greg k-h