Skip to content

Commit 5409d2c

Browse files
antonblanchardgregkh
authored andcommitted
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 <anton@samba.org> Signed-off-by: Greg Kroah-Hartman <gregkh@suse.de>
1 parent 1f8e1cd commit 5409d2c

1 file changed

Lines changed: 8 additions & 16 deletions

File tree

‎drivers/base/memory.c‎

Lines changed: 8 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -229,10 +229,11 @@ int memory_isolate_notify(unsigned long val, void *v)
229229
* OK to have direct references to sparsemem variables in here.
230230
*/
231231
static int
232-
memory_section_action(unsigned long phys_index, unsigned long action)
232+
memory_block_action(unsigned long phys_index, unsigned long action)
233233
{
234234
int i;
235235
unsigned long start_pfn, start_paddr;
236+
unsigned long nr_pages = PAGES_PER_SECTION * sections_per_block;
236237
struct page *first_page;
237238
int ret;
238239

@@ -244,7 +245,7 @@ memory_section_action(unsigned long phys_index, unsigned long action)
244245
* that way.
245246
*/
246247
if (action == MEM_ONLINE) {
247-
for (i = 0; i < PAGES_PER_SECTION; i++) {
248+
for (i = 0; i < nr_pages; i++) {
248249
if (PageReserved(first_page+i))
249250
continue;
250251

@@ -258,12 +259,12 @@ memory_section_action(unsigned long phys_index, unsigned long action)
258259
switch (action) {
259260
case MEM_ONLINE:
260261
start_pfn = page_to_pfn(first_page);
261-
ret = online_pages(start_pfn, PAGES_PER_SECTION);
262+
ret = online_pages(start_pfn, nr_pages);
262263
break;
263264
case MEM_OFFLINE:
264265
start_paddr = page_to_pfn(first_page) << PAGE_SHIFT;
265266
ret = remove_memory(start_paddr,
266-
PAGES_PER_SECTION << PAGE_SHIFT);
267+
nr_pages << PAGE_SHIFT);
267268
break;
268269
default:
269270
WARN(1, KERN_WARNING "%s(%ld, %ld) unknown action: "
@@ -289,20 +290,11 @@ static int memory_block_change_state(struct memory_block *mem,
289290
if (to_state == MEM_OFFLINE)
290291
mem->state = MEM_GOING_OFFLINE;
291292

292-
for (i = 0; i < sections_per_block; i++) {
293-
ret = memory_section_action(mem->start_section_nr + i,
294-
to_state);
295-
if (ret)
296-
break;
297-
}
298-
299-
if (ret) {
300-
for (i = 0; i < sections_per_block; i++)
301-
memory_section_action(mem->start_section_nr + i,
302-
from_state_req);
293+
ret = memory_block_action(mem->start_section_nr, to_state);
303294

295+
if (ret)
304296
mem->state = from_state_req;
305-
} else
297+
else
306298
mem->state = to_state;
307299

308300
out:

0 commit comments

Comments
 (0)