Commit 9dbd80b7 authored by Pavel Machek's avatar Pavel Machek Committed by Linus Torvalds

[PATCH] swsusp: remove O(n^2) algorithm in page relocation

This removes another O(n^2) algorithm from page relocation in swsusp.
Relocation took as long as reading pages from disk on my machine, and it
took minutes for some poor testers.
Signed-off-by: default avatarAndrew Morton <akpm@osdl.org>
Signed-off-by: default avatarLinus Torvalds <torvalds@osdl.org>
parent 699510ad
...@@ -893,26 +893,18 @@ int swsusp_resume(void) ...@@ -893,26 +893,18 @@ int swsusp_resume(void)
return error; return error;
} }
/* More restore stuff */ /* More restore stuff */
#define does_collide(addr) does_collide_order(pagedir_nosave, addr, 0)
/* /*
* Returns true if given address/order collides with any orig_address * Returns true if given address/order collides with any orig_address
*/ */
static int __init does_collide_order(suspend_pagedir_t *pagedir, unsigned long addr, static int __init does_collide_order(unsigned long addr, int order)
int order)
{ {
int i; int i;
unsigned long addre = addr + (PAGE_SIZE<<order);
for (i=0; i < nr_copy_pages; i++) for (i=0; i < (1<<order); i++)
if ((pagedir+i)->orig_address >= addr && if (!PageNosaveFree(virt_to_page(addr + i * PAGE_SIZE)))
(pagedir+i)->orig_address < addre)
return 1; return 1;
return 0; return 0;
} }
...@@ -931,7 +923,7 @@ static int __init check_pagedir(void) ...@@ -931,7 +923,7 @@ static int __init check_pagedir(void)
addr = get_zeroed_page(GFP_ATOMIC); addr = get_zeroed_page(GFP_ATOMIC);
if(!addr) if(!addr)
return -ENOMEM; return -ENOMEM;
} while (does_collide(addr)); } while (does_collide_order(addr, 0));
(pagedir_nosave+i)->address = addr; (pagedir_nosave+i)->address = addr;
} }
...@@ -948,16 +940,34 @@ static int __init swsusp_pagedir_relocate(void) ...@@ -948,16 +940,34 @@ static int __init swsusp_pagedir_relocate(void)
void **eaten_memory = NULL; void **eaten_memory = NULL;
void **c = eaten_memory, *m, *f; void **c = eaten_memory, *m, *f;
int ret = 0; int ret = 0;
struct zone *zone;
int i;
struct pbe *p;
unsigned long zone_pfn;
printk("Relocating pagedir "); printk("Relocating pagedir ");
if (!does_collide_order(old_pagedir, (unsigned long)old_pagedir, pagedir_order)) { /* Set page flags */
for_each_zone(zone) {
for (zone_pfn = 0; zone_pfn < zone->spanned_pages; ++zone_pfn)
SetPageNosaveFree(pfn_to_page(zone_pfn +
zone->zone_start_pfn));
}
/* Clear orig address */
for(i = 0, p = pagedir_nosave; i < nr_copy_pages; i++, p++) {
ClearPageNosaveFree(virt_to_page(p->orig_address));
}
if (!does_collide_order((unsigned long)old_pagedir, pagedir_order)) {
printk("not necessary\n"); printk("not necessary\n");
return check_pagedir(); return check_pagedir();
} }
while ((m = (void *) __get_free_pages(GFP_ATOMIC, pagedir_order)) != NULL) { while ((m = (void *) __get_free_pages(GFP_ATOMIC, pagedir_order)) != NULL) {
if (!does_collide_order(old_pagedir, (unsigned long)m, pagedir_order)) if (!does_collide_order((unsigned long)m, pagedir_order))
break; break;
eaten_memory = m; eaten_memory = m;
printk( "." ); printk( "." );
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment