swsusp: do not use higher order memory allocations on resume
Subsystems (4)
RFC PATCH 1/1 swsusp: do not use higher order memory allocations on resume
Hi,
The following patch is (yet) an(other) attempt to eliminate the need for using higher order memory allocations on resume. It accomplishes this by replacing the array of page backup entries with a list, so it is only necessary to allocate individual memory pages. This approach makes it possible to avoid relocating many memory pages on resume (as a result, much less memory is used) and to simplify the assembly code that restores the image.
The patch is a complement to the patch that I sent some time ago as "swsusp: do not use higher order memory allocations on suspend". It is against 2.6.11-rc2 - on top of the previous patch and on top of the "x86_64: Speed up suspend" patch which are availble at:
http://www.sisk.pl/kernel/patches/2.6.11-rc2/swsusp-use-list-suspend-v2.patch
and at:
http://www.sisk.pl/kernel/patches/2.6.11-rc2/x86_64-Speed-up-suspend.patch
respectively. The patch itself is available at:
http://www.sisk.pl/kernel/patches/2.6.11-rc2/swsusp-use-list-resume-v1.patch
and there is a consolidated patch against 2.6.11-rc2 at:
http://www.sisk.pl/kernel/patches/2.6.11-rc2/2.6.11-rc2-swsusp-use-list.patch
The patch includes the modifications to the assembly code for x86-64 and i386, but it does not modify the ppc code (I have no experience with the ppc architecture and no hardware; if anyone could help, I'd really appreciate it). It has been tested (extensively) on x86-64 and (lightly) on i386. Please let me know if you find any bugs in it. Of course, any comments, suggestions, etc. are welcome.
Greets,
RJW
arch/i386/power/swsusp.S +11 -11
@@ -28,28 +28,28 @@ ret ENTRY(swsusp_arch_resume) - movl $swsusp_pg_dir-__PAGE_OFFSET,%ecx - movl %ecx,%cr3 + movl $swsusp_pg_dir-__PAGE_OFFSET,%ecx + movl %ecx,%cr3 - movl pagedir_nosave, %ebx - xorl %eax, %eax - xorl %edx, %edx + movl pagedir_nosave, %edx + testl %edx, %edx + jz done .p2align 4,,7 copy_loop: - movl 4(%ebx,%edx),%edi - movl (%ebx,%edx),%esi + movl (%edx), %esi + movl 4(%edx), %edi movl $1024, %ecx rep movsl - incl %eax - addl $16, %edx - cmpl nr_copy_pages,%eax - jb copy_loop + movl 12(%edx), %edx + testl %edx, %edx + jnz copy_loop .p2align 4,,7 +done: movl saved_context_esp, %esp movl saved_context_ebp, %ebp movl saved_context_ebx, %ebx
arch/x86_64/kernel/asm-offsets.c +1 -1
@@ -62,8 +62,8 @@ offsetof (struct rt_sigframe32, uc.uc_mcontext));BLANK ();#endif -DEFINE (SIZEOF_PBE ,sizeof (struct pbe ));DEFINE (pbe_address, offsetof(struct pbe , address));DEFINE (pbe_orig_address, offsetof(struct pbe , orig_address)); +DEFINE (pbe_next, offsetof(struct pbe , next));return 0 ; }
arch/x86_64/kernel/suspend_asm.S +9 -13
@@ -1,6 +1,9 @@ -/* Originally gcc generated, modified by hand +/* Copyright 2004,2005 Pavel Machek <[email protected]>, Andi Kleen <[email protected]>, Rafael J. Wysocki <[email protected]> * - * This may not use any stack, nor any variable that is not "NoSave": + * Distribute under GPLv2. + * + * swsusp_arch_resume may not use any stack, nor any variable that is + * not "NoSave" during copying pages: * * Its rewriting one kernel image with another. What is stack in "old" * image could very well be data page in "new" image, and overwriting
@@ -51,15 +54,8 @@ movq %rax, %cr4; # turn PGE back on movq pagedir_nosave(%rip), %rdx - /* compute the limit */ - movl nr_copy_pages(%rip), %eax - testl %eax, %eax + testq %rdx, %rdx jz done - movq %rdx,%r8 - movl $SIZEOF_PBE,%r9d - mul %r9 # with rax, clobbers rdx - movq %r8, %rdx - addq %r8, %rax loop: /* get addresses from the pbe and copy the page */ movq pbe_address(%rdx), %rsi
@@ -69,9 +65,9 @@ movsq /* progress to the next pbe */ - addq $SIZEOF_PBE, %rdx - cmpq %rax, %rdx - jb loop + movq pbe_next(%rdx), %rdx + testq %rdx, %rdx + jnz loop done: movl $24, %eax movl %eax, %ds
kernel/power/swsusp.c +224 -92
390 lines not on this page · raw message
Signature · 3 lines
- Would you tell me, please, which way I ought to go from here? - That depends a good deal on where you want to get to. -- Lewis Carroll "Alice's Adventures in Wonderland"
Re: [RFC][PATCH] swsusp: do not use higher order memory allocations [update]
Hi,
Quoted 9 lines · Rafael J. Wysocki
Hi,
The following patch is (yet) an(other) attempt to eliminate the need for using higher order memory allocations on resume. It accomplishes this by replacing the array of page backup entries with a list, so it is only necessary to allocate individual memory pages. This approach makes it possible to avoid relocating many memory pages on resume (as a result, much less memory is used) and to simplify the assembly code that restores the image.
Quoted 11 lines
The patch is a complement to the patch that I sent some time ago as "swsusp: do not use higher order memory allocations on suspend". It is against 2.6.11-rc2 - on top of the previous patch and on top of the "
x86_64: Speed up suspend" patch which are availble at:
http://www.sisk.pl/kernel/patches/2.6.11-rc2/swsusp-use-list-suspend-v2.patch
and at:
http://www.sisk.pl/kernel/patches/2.6.11-rc2/x86_64-Speed-up-suspend.patch
respectively. The patch itself is available at:
http://www.sisk.pl/kernel/patches/2.6.11-rc2/swsusp-use-list-resume-v1.patch
and there is a consolidated patch against 2.6.11-rc2 at:
http://www.sisk.pl/kernel/patches/2.6.11-rc2/2.6.11-rc2-swsusp-use-list.patch
I have updated the patches to include a bugfix from Pavel Machek (thanks, Pavel!). Affected are the "suspend" patch and the "consolidated" patch. The updated patches are available at:
http://www.sisk.pl/kernel/patches/2.6.11-rc2/swsusp-use-list-suspend-v3.patch
http://www.sisk.pl/kernel/patches/2.6.11-rc2/2.6.11-rc2-swsusp-use-list-v2.patch
respectively. The other patches remain unchanged.
Greets,
Rafael
Signature · 3 lines
- Would you tell me, please, which way I ought to go from here? - That depends a good deal on where you want to get to. -- Lewis Carroll "Alice's Adventures in Wonderland"
Re: [RFC][PATCH] swsusp: do not use higher order allocations on resume [update 2]
In reply to Rafael J. WysockiHi,
Quoted 8 lines · Rafael J. Wysocki
Hi,
The following patch is (yet) an(other) attempt to eliminate the need for using higher order memory allocations on resume. It accomplishes this by replacing the array of page backup entries with a list, so it is only necessary to allocate individual memory pages. This approach makes it possible to avoid relocating many memory pages on resume (as a result, much less memory is used) and to simplify the assembly code that restores the image.
I have updated the resume patch to apply to the 2.6.11-rc3-mm1 kernel that contains the suspend part and the x86_64-Speed-up-suspend patch. The patch is only for x86-64 and i386.
[Note: without this patch the resume process fails on my box ("out of memory") during every 7th - 8th suspend/resume cycle, on the average.]
I'm going to maintain this patch so that it's available for the next -mm kernels (it will be available under http://www.sisk.pl/kernel/patches/).
The (updated) patch follows.
Greets,
Rafael
arch/i386/power/swsusp.S +11 -11
@@ -28,28 +28,28 @@ ret ENTRY(swsusp_arch_resume) - movl $swsusp_pg_dir-__PAGE_OFFSET,%ecx - movl %ecx,%cr3 + movl $swsusp_pg_dir-__PAGE_OFFSET,%ecx + movl %ecx,%cr3 - movl pagedir_nosave, %ebx - xorl %eax, %eax - xorl %edx, %edx + movl pagedir_nosave, %edx + testl %edx, %edx + jz done .p2align 4,,7 copy_loop: - movl 4(%ebx,%edx),%edi - movl (%ebx,%edx),%esi + movl (%edx), %esi + movl 4(%edx), %edi movl $1024, %ecx rep movsl - incl %eax - addl $16, %edx - cmpl nr_copy_pages,%eax - jb copy_loop + movl 12(%edx), %edx + testl %edx, %edx + jnz copy_loop .p2align 4,,7 +done: movl saved_context_esp, %esp movl saved_context_ebp, %ebp movl saved_context_ebx, %ebx
arch/x86_64/kernel/asm-offsets.c +1 -1
@@ -62,8 +62,8 @@ offsetof (struct rt_sigframe32, uc.uc_mcontext));BLANK ();#endif -DEFINE (SIZEOF_PBE ,sizeof (struct pbe ));DEFINE (pbe_address, offsetof(struct pbe , address));DEFINE (pbe_orig_address, offsetof(struct pbe , orig_address)); +DEFINE (pbe_next, offsetof(struct pbe , next));return 0 ; }
arch/x86_64/kernel/suspend_asm.S +4 -11
@@ -54,15 +54,8 @@ movq %rax, %cr4; # turn PGE back on movq pagedir_nosave(%rip), %rdx - /* compute the limit */ - movl nr_copy_pages(%rip), %eax - testl %eax, %eax + testq %rdx, %rdx jz done - movq %rdx,%r8 - movl $SIZEOF_PBE,%r9d - mul %r9 # with rax, clobbers rdx - movq %r8, %rdx - addq %r8, %rax loop: /* get addresses from the pbe and copy the page */ movq pbe_address(%rdx), %rsi
@@ -72,9 +65,9 @@ movsq /* progress to the next pbe */ - addq $SIZEOF_PBE, %rdx - cmpq %rax, %rdx - jb loop + movq pbe_next(%rdx), %rdx + testq %rdx, %rdx + jnz loop done: movl $24, %eax movl %eax, %ds
kernel/power/swsusp.c +224 -91
389 lines not on this page · raw message
Signature · 3 lines
- Would you tell me, please, which way I ought to go from here? - That depends a good deal on where you want to get to. -- Lewis Carroll "Alice's Adventures in Wonderland"
Re: [RFC][PATCH] swsusp: do not use higher order allocations on resume [update 2]
Hi!
Quoted 7 lines
Quoted 6 lines
The following patch is (yet) an(other) attempt to eliminate the need for using higher order memory allocations on resume. It accomplishes this by replacing the array of page backup entries with a list, so it is only necessary to allocate individual memory pages. This approach makes it possible to avoid relocating many memory pages on resume (as a result, much less memory is used) and to simplify the assembly code that restores the image.
Quoted 6 lines
I have updated the resume patch to apply to the 2.6.11-rc3-mm1 kernel that contains the suspend part and the x86_64-Speed-up-suspend patch. The patch is only for x86-64 and i386.
[Note: without this patch the resume process fails on my box ("out of memory") during every 7th - 8th suspend/resume cycle, on the average.]
Pssst. At this point, solution would be to revert the first part, too. 2.6.11 is too near to do anything else.
Pavel
Signature · 2 lines
People were complaining that M$ turns users into beta-testers... ...jr ghea gurz vagb qrirybcref, naq gurl frrz gb yvxr vg gung jnl!
Re: [RFC][PATCH] swsusp: do not use higher order allocations on resume [update 2]
Hi,
Quoted 15 lines · Pavel Machek
Hi!
Quoted 13 lines
Quoted 6 lines
The following patch is (yet) an(other) attempt to eliminate the need for using higher order memory allocations on resume. It accomplishes this by replacing the array of page backup entries with a list, so it is only necessary to allocate individual memory pages. This approach makes it possible to avoid relocating many memory pages on resume (as a result, much less memory is used) and to simplify the assembly code that restores the image.
I have updated the resume patch to apply to the 2.6.11-rc3-mm1 kernel that contains the suspend part and the x86_64-Speed-up-suspend patch. The patch is only for x86-64 and i386.
[Note: without this patch the resume process fails on my box ("out of memory") during every 7th - 8th suspend/resume cycle, on the average.]
Well, this doesn't depend on the previous patch, apparently. ;-)
Quoted 2 lines
Pssst. At this point, solution would be to revert the first part, too. 2.6.11 is too near to do anything else.
Oh, I didn't mean changing anything now (eg because of the missing ppc assembly part). However, the patch is useful for me so I thought I'd post it in case someone else (using the -mm kernels) needed it.
Greets,
Rafael
Signature · 3 lines
- Would you tell me, please, which way I ought to go from here? - That depends a good deal on where you want to get to. -- Lewis Carroll "Alice's Adventures in Wonderland"
Re: [RFC][PATCH] swsusp: do not use higher order allocations on resume [update 2]
In reply to Rafael J. WysockiHi!
Quoted 1 line
The (updated) patch follows.
Okay, few comments...
Quoted 8 lines
Signed-off-by Rafael J. Wysocki <[email protected]>diff -Nru
linux-2.6.11-rc3-mm1-orig/arch/i386/power/swsusp.Slinux-2.6.11-rc3-mm1/arch/i386/power/swsusp.Sarch/i386/power/swsusp.S +0
-0@@ -28,28 +28,28 @@ ret
arch/i386/power/swsusp.S line 34
Quoted 10 lines
arch/i386/power/swsusp.S +3
-5ENTRY(swsusp_arch_resume) - movl $swsusp_pg_dir-__PAGE_OFFSET,%ecx - movl %ecx,%cr3 + movl $swsusp_pg_dir-__PAGE_OFFSET,%ecx + movl %ecx,%cr3 - movl pagedir_nosave, %ebx - xorl %eax, %eax - xorl %edx, %edx + movl pagedir_nosave, %edx
move copy_loop: here
Quoted 11 lines
arch/i386/power/swsusp.S +4
-2+ testl %edx, %edx + jz done .p2align 4,,7 copy_loop: - movl 4(%ebx,%edx),%edi - movl (%ebx,%edx),%esi + movl (%edx), %esi + movl 4(%edx), %edi movl $1024, %ecx
arch/i386/power/swsusp.S line 49
Quoted 10 lines
arch/i386/power/swsusp.S +3
-4rep movsl - incl %eax - addl $16, %edx - cmpl nr_copy_pages,%eax - jb copy_loop + movl 12(%edx), %edx + testl %edx, %edx + jnz copy_loop
And do unconditional jump here? Also, 12(%edx)... Could it be handled using asm-offsets, like on x86-64?
arch/i386/power/swsusp.S line 50
Quoted 1 line
arch/i386/power/swsusp.S +1
-0+static void __init free_eaten_memory(void) {
Please put { at new line.
arch/i386/power/swsusp.S
Quoted 6 lines
arch/i386/power/swsusp.S +6
-0+ for_each_pbe(p, pblist) + p->address = 0UL; + + for_each_pbe(p, pblist) { + p->address = get_usable_page(GFP_ATOMIC); + if(!p->address)
I'd put space between if and (. And probably do the same for for_each_pbe... it behaves like a while.
Quoted 38 lines
arch/i386/power/swsusp.S +8
-21@@ -966,45 +1018,52 @@ zone->zone_start_pfn)); } - /* Clear orig address */ + /* Clear orig addresses */ - for(i = 0, p = pagedir_nosave; i < nr_copy_pages; i++, p++) { + for_each_pbe(p, pblist) ClearPageNosaveFree(virt_to_page(p->orig_address)); - } - if (!does_collide_order((unsigned long)old_pagedir, pagedir_order)) { - printk("not necessary\n"); - return check_pagedir(); - } + tail = pblist + PB_PAGE_SKIP; - while ((m = (void *) __get_free_pages(GFP_ATOMIC, pagedir_order)) != NULL) { - if (!does_collide_order((unsigned long)m, pagedir_order)) - break; - eaten_memory = m; - printk( "." ); - *eaten_memory = c; - c = eaten_memory; - } + /* Relocate colliding pages */ - if (!m) { - printk("out of memory\n"); - ret = -ENOMEM; - } else { - pagedir_nosave = - memcpy(m, old_pagedir, PAGE_SIZE << pagedir_order); + for_each_pb_page(pbpage, pblist) { + if (does_collide_order((unsigned long)pbpage, 0)) { + m = (void *)get_usable_page(GFP_ATOMIC | __GFP_COLD); + if (!m) {
arch/i386/power/swsusp.S line 1043
Quoted 10 lines
arch/i386/power/swsusp.S +10
-0+ error = -ENOMEM; + break; + } + memcpy(m, (void *)pbpage, PAGE_SIZE); + if (pbpage == pblist) + pblist = (struct pbe *)m; + else + tail->next = (struct pbe *)m; + + free_page((unsigned long)pbpage);
Uh, you free it so that you can allocate it again, and again find out that it is unusable? It will probably end up on list of unusable pages, so it is okay, but...
arch/i386/power/swsusp.S line 1048
Quoted 5 lines
arch/i386/power/swsusp.S +5
-0+ pbpage = (struct pbe *)m; + + /* We have to link the PBEs again */ + + for (p = pbpage ; p < pbpage + PB_PAGE_SKIP ; p++)
I'd avoid " " before ;.
arch/i386/power/swsusp.S line 1053
Quoted 5 lines
arch/i386/power/swsusp.S +5
-0+ p = pbe; + pbe += PB_PAGE_SKIP; + do + p->next = p + 1; + while (p++ < pbe);
I've already seen this code somewhere around in different variant... Perhaps you want to make it inline function?
arch/i386/power/swsusp.S line 1056
Quoted 3 lines
arch/i386/power/swsusp.S +3
-0+ p->next = NULL; + pr_debug("swsusp: Read %d pages, allocated %d PBEs\n", i, num); + error = (i != swsusp_info.pagedir_pages); /* a sanity check */
If it is sanity check, do BUG_ON().
arch/i386/power/swsusp.S line 1058
Quoted 2 lines
arch/i386/power/swsusp.S +2
-0+ if(!(p = read_pagedir())) + return -EFAULT;
Is the value used? By using pointers instead of normal ints, you kill possibility of meaningfull error reporting...
arch/i386/power/swsusp.S line 1060
Quoted 2 lines
arch/i386/power/swsusp.S +2
-0+ if(!(pagedir_nosave = swsusp_pagedir_relocate(p))) + return -ENOMEM;
Same here.
Pavel
Signature · 2 lines
People were complaining that M$ turns users into beta-testers... ...jr ghea gurz vagb qrirybcref, naq gurl frrz gb yvxr vg gung jnl!
Re: [RFC][PATCH] swsusp: do not use higher order allocations on resume [update 2]
Hi,
Quoted 21 lines · Pavel Machek
Hi!
Quoted 1 line
The (updated) patch follows.
Okay, few comments...
Quoted 14 lines
Signed-off-by Rafael J. Wysocki <[email protected]>diff -Nru
linux-2.6.11-rc3-mm1-orig/arch/i386/power/swsusp.Slinux-2.6.11-rc3-mm1/arch/i386/power/swsusp.Sarch/i386/power/swsusp.S +2
-2@@ -28,28 +28,28 @@ ret ENTRY(swsusp_arch_resume) - movl $swsusp_pg_dir-__PAGE_OFFSET,%ecx - movl %ecx,%cr3 + movl $swsusp_pg_dir-__PAGE_OFFSET,%ecx + movl %ecx,%cr3
Quoted 6 lines
arch/i386/power/swsusp.S line 34
Quoted 4 lines
arch/i386/power/swsusp.S +1
-3- movl pagedir_nosave, %ebx - xorl %eax, %eax - xorl %edx, %edx + movl pagedir_nosave, %edxmove
copy_loop: here
OK
Quoted 14 lines
Quoted 14 lines
arch/i386/power/swsusp.S +4
-2+ testl %edx, %edx + jz done .p2align 4,,7 copy_loop: - movl 4(%ebx,%edx),%edi - movl (%ebx,%edx),%esi + movl (%edx), %esi + movl 4(%edx), %edi movl $1024, %ecx rep movsl
Quoted 9 lines
arch/i386/power/swsusp.S line 49
Quoted 7 lines
arch/i386/power/swsusp.S +3
-4- incl %eax - addl $16, %edx - cmpl nr_copy_pages,%eax - jb copy_loop + movl 12(%edx), %edx + testl %edx, %edx + jnz copy_loopAnd do unconditional jump here?
OK (I did the same for x86-64).
Quoted 1 line
Also, 12(%edx)... Could it be handled using asm-offsets, like on x86-64?
Yes, and so I did.
Quoted 4 lines
arch/i386/power/swsusp.S line 50
Quoted 1 line
arch/i386/power/swsusp.S +1
-0+static void __init free_eaten_memory(void) {Please put { at new line.
Quoted 9 lines
arch/i386/power/swsusp.S
Quoted 6 lines
arch/i386/power/swsusp.S +6
-0+ for_each_pbe(p, pblist) + p->address = 0UL; + + for_each_pbe(p, pblist) { + p->address = get_usable_page(GFP_ATOMIC); + if(!p->address)I'd put space between if and (. And probably do the same for
for_each_pbe... it behaves like a while.
OK
[-- snip --]
Quoted 10 lines
Quoted 10 lines
arch/i386/power/swsusp.S +10
-0+ for_each_pb_page(pbpage, pblist) { + if (does_collide_order((unsigned long)pbpage, 0)) { + m = (void *)get_usable_page(GFP_ATOMIC | __GFP_COLD); + if (!m) { + error = -ENOMEM; + break; + } + memcpy(m, (void *)pbpage, PAGE_SIZE); + if (pbpage == pblist) + pblist = (struct pbe *)m;
Quoted 8 lines
arch/i386/power/swsusp.S
Quoted 4 lines
arch/i386/power/swsusp.S +4
-0+ else + tail->next = (struct pbe *)m; + + free_page((unsigned long)pbpage);Uh, you free it so that you can allocate it again, and again find out that it is unusable? It will probably end up on list of unusable pages,
That's because I wanted the page to end up on this list.
Quoted 1 line
so it is okay, but...
... I could have done it more elegantly. You're right, I've now introduced a function eat_page() that adds a page to the list of unusable pages and used it instead of the free_page() here.
Quoted 7 lines
arch/i386/power/swsusp.S
Quoted 5 lines
arch/i386/power/swsusp.S +5
-0+ pbpage = (struct pbe *)m; + + /* We have to link the PBEs again */ + + for (p = pbpage ; p < pbpage + PB_PAGE_SKIP ; p++)I'd avoid " " before ;.
OK
Quoted 8 lines
arch/i386/power/swsusp.S
Quoted 5 lines
arch/i386/power/swsusp.S +5
-0+ p = pbe; + pbe += PB_PAGE_SKIP; + do + p->next = p + 1; + while (p++ < pbe);I've already seen this code somewhere around in different variant... Perhaps you want to make it inline function?
I tried to avoid modifying the suspend part, but if it's not a problem, why don't we go farther and reuse alloc_pagedir() in the resume code?
It has the advantage that read_pagedir() is then much simpler, and it returns an integer. However, for this purpose, it's better to split alloc_pagedir() into two functions, one of which allocates memory pages, and the second puts the list structure on them.
Quoted 5 lines
arch/i386/power/swsusp.S
Quoted 3 lines
arch/i386/power/swsusp.S +3
-0+ p->next = NULL; + pr_debug("swsusp: Read %d pages, allocated %d PBEs\n", i, num); + error = (i != swsusp_info.pagedir_pages); /* a sanity check */If it is sanity check, do
BUG_ON().
OK
Quoted 5 lines
arch/i386/power/swsusp.S
Quoted 2 lines
arch/i386/power/swsusp.S +2
-0+ if(!(p = read_pagedir())) + return -EFAULT;Is the value used? By using pointers instead of normal ints, you kill possibility of meaningfull error reporting...
Yes, but it is fixed easily if alloc_pagedir() is reused in the resume code.
Quoted 4 lines
arch/i386/power/swsusp.S
Quoted 2 lines
arch/i386/power/swsusp.S +2
-0+ if(!(pagedir_nosave = swsusp_pagedir_relocate(p))) + return -ENOMEM;Same here.
The value is used in error reporting and the only reason why this function may fail is the lack of memory (the same applies to alloc_pagedir()).
The revised (not as thoroughly tested as the previous one, but hopefully nicer) patch follows.
Greets,
Rafael
arch/i386/kernel/asm-offsets.c +6 -0
@@ -7,6 +7,7 @@#include <linux/sched.h> #include <linux/signal.h> #include <linux/personality.h> +#include <linux/suspend.h> #include <asm/ucontext.h> #include "sigframe.h" #include <asm/fixmap.h>
@@ -56,6 +57,11 @@OFFSET (EXEC_DOMAIN_handler, exec_domain, handler);OFFSET (RT_SIGFRAME_sigcontext, rt_sigframe, uc.uc_mcontext); +BLANK (); + + OFFSET(pbe_address, struct pbe, address); + OFFSET(pbe_orig_address, struct pbe, orig_address); + OFFSET(pbe_next, struct pbe, next);/* Offset from the sysenter stack to tss.esp0 */ DEFINE(TSS_sysenter_esp0, offsetof(struct tss_struct, esp0) -
arch/i386/power/swsusp.S +12 -11
@@ -12,6 +12,7 @@ #include <linux/linkage.h> #include <asm/segment.h> #include <asm/page.h> +#include <asm/asm_offsets.h> .text
@@ -28,28 +29,28 @@ ret ENTRY(swsusp_arch_resume) - movl $swsusp_pg_dir-__PAGE_OFFSET,%ecx - movl %ecx,%cr3 + movl $swsusp_pg_dir-__PAGE_OFFSET,%ecx + movl %ecx,%cr3 - movl pagedir_nosave, %ebx - xorl %eax, %eax - xorl %edx, %edx + movl pagedir_nosave, %edx .p2align 4,,7 copy_loop: - movl 4(%ebx,%edx),%edi - movl (%ebx,%edx),%esi + testl %edx, %edx + jz done + + movl pbe_address(%edx), %esi + movl pbe_orig_address(%edx), %edi movl $1024, %ecx rep movsl - incl %eax - addl $16, %edx - cmpl nr_copy_pages,%eax - jb copy_loop + movl pbe_next(%edx), %edx + jmp copy_loop .p2align 4,,7 +done: movl saved_context_esp, %esp movl saved_context_ebp, %ebp movl saved_context_ebx, %ebx
arch/x86_64/kernel/asm-offsets.c +1 -1
@@ -62,8 +62,8 @@ offsetof (struct rt_sigframe32, uc.uc_mcontext));BLANK ();#endif -DEFINE (SIZEOF_PBE ,sizeof (struct pbe ));DEFINE (pbe_address, offsetof(struct pbe , address));DEFINE (pbe_orig_address, offsetof(struct pbe , orig_address)); +DEFINE (pbe_next, offsetof(struct pbe , next));return 0 ; }
arch/x86_64/kernel/suspend_asm.S +5 -12
@@ -54,16 +54,10 @@ movq %rax, %cr4; # turn PGE back on movq pagedir_nosave(%rip), %rdx - /* compute the limit */ - movl nr_copy_pages(%rip), %eax - testl %eax, %eax - jz done - movq %rdx,%r8 - movl $SIZEOF_PBE,%r9d - mul %r9 # with rax, clobbers rdx - movq %r8, %rdx - addq %r8, %rax loop: + testq %rdx, %rdx + jz done + /* get addresses from the pbe and copy the page */ movq pbe_address(%rdx), %rsi movq pbe_orig_address(%rdx), %rdi
@@ -72,9 +66,8 @@ movsq /* progress to the next pbe */ - addq $SIZEOF_PBE, %rdx - cmpq %rax, %rdx - jb loop + movq pbe_next(%rdx), %rdx + jmp loop done: movl $24, %eax movl %eax, %ds
kernel/power/swsusp.c +238 -98
443 lines not on this page · raw message
Signature · 3 lines
- Would you tell me, please, which way I ought to go from here? - That depends a good deal on where you want to get to. -- Lewis Carroll "Alice's Adventures in Wonderland"
Re: [RFC][PATCH] swsusp: do not use higher order allocations on resume [update 2]
Hi!
Quoted 5 lines
Quoted 1 line
so it is okay, but...
... I could have done it more elegantly. You're right, I've now introduced a function
eat_page()that adds a page to the list of unusable pages and used it instead of thefree_page()here.
Thanks.
Quoted 9 lines
Quoted 8 lines
Review
Quoted 5 lines
(quoted diff) +5
-0+ p = pbe; + pbe += PB_PAGE_SKIP; + do + p->next = p + 1; + while (p++ < pbe);I've already seen this code somewhere around in different variant... Perhaps you want to make it inline function?
Quoted 7 lines
I tried to avoid modifying the suspend part, but if it's not a problem, why don't we go farther and reuse
alloc_pagedir()in the resume code?It has the advantage that
read_pagedir()is then much simpler, and it returns an integer. However, for this purpose, it's better to splitalloc_pagedir()into two functions, one of which allocates memory pages, and the second puts the list structure on them.
I guess that modifying suspend part is okay. We do not want to have two copies of similar code...
Quoted 10 lines
Quoted 4 lines
Review
Quoted 2 lines
(quoted diff) +2
-0+ if(!(pagedir_nosave = swsusp_pagedir_relocate(p))) + return -ENOMEM;Same here.
The value is used in error reporting and the only reason why this function may fail is the lack of memory (the same applies to
alloc_pagedir()).The revised (not as thoroughly tested as the previous one, but hopefully nicer) patch follows.
I guess I'll wait for "reuse alloc_pagedir" version.
Pavel
Signature · 2 lines
People were complaining that M$ turns users into beta-testers... ...jr ghea gurz vagb qrirybcref, naq gurl frrz gb yvxr vg gung jnl!
Re: [RFC][PATCH] swsusp: do not use higher order allocations on resume [update 2]
Quoted 35 lines · Pavel Machek
Hi!
Quoted 5 lines
Quoted 1 line
so it is okay, but...
... I could have done it more elegantly. You're right, I've now introduced a function
eat_page()that adds a page to the list of unusable pages and used it instead of thefree_page()here.Thanks.
Quoted 9 lines
Quoted 8 lines
Review
Quoted 5 lines
(quoted diff) +5
-0+ p = pbe; + pbe += PB_PAGE_SKIP; + do + p->next = p + 1; + while (p++ < pbe);I've already seen this code somewhere around in different variant... Perhaps you want to make it inline function?
Quoted 7 lines
I tried to avoid modifying the suspend part, but if it's not a problem, why don't we go farther and reuse
alloc_pagedir()in the resume code?It has the advantage that
read_pagedir()is then much simpler, and it returns an integer. However, for this purpose, it's better to splitalloc_pagedir()into two functions, one of which allocates memory pages, and the second puts the list structure on them.I guess that modifying suspend part is okay. We do not want to have two copies of similar code...
Quoted 5 lines
Quoted 4 lines
Review
Quoted 2 lines
(quoted diff) +2
-0+ if(!(pagedir_nosave = swsusp_pagedir_relocate(p))) + return -ENOMEM;Same here.
Quoted 7 lines
Quoted 5 lines
The value is used in error reporting and the only reason why this function may fail is the lack of memory (the same applies to
alloc_pagedir()).The revised (not as thoroughly tested as the previous one, but hopefully nicer) patch follows.
I guess I'll wait for "reuse
alloc_pagedir" version.
It's this one. :-)
Greets,
Rafael
Signature · 3 lines
- Would you tell me, please, which way I ought to go from here? - That depends a good deal on where you want to get to. -- Lewis Carroll "Alice's Adventures in Wonderland"
Re: [RFC][PATCH] swsusp: do not use higher order allocations on resume [update 2]
In reply to Rafael J. WysockiHi!
Quoted 1 line
+static inline void
eat_page(void *page){
Please put { on new line.
Okay, as you can see, I could find very little wrong with this patch. That hopefully means it is okay ;-). I should still check error handling, but I guess I'll do it when it is applied because it is hard to do on a diff. I guess it should go into -mm just after 2.6.11 is released...
Pavel
Signature · 2 lines
People were complaining that M$ turns users into beta-testers... ...jr ghea gurz vagb qrirybcref, naq gurl frrz gb yvxr vg gung jnl!
Re: [RFC][PATCH] swsusp: do not use higher order allocations on resume [update 2]
Quoted 5 lines · Pavel Machek
Hi!
Quoted 1 line
+static inline void
eat_page(void *page){Please put { on new line.
Oh, I still tend to forget about this. Corrected in the patch that is available on the web
(http://www.sisk.pl/kernel/patches/2.6.11-rc3-mm1/swsusp-use-list-resume-v4.patch).
Quoted 5 lines
Okay, as you can see, I could find very little wrong with this patch. That hopefully means it is okay ;-). I should still check error handling, but I guess I'll do it when it is applied because it is hard to do on a diff. I guess it should go into -mm just after 2.6.11 is released...
That would be great!
Greets,
Rafael
Signature · 3 lines
- Would you tell me, please, which way I ought to go from here? - That depends a good deal on where you want to get to. -- Lewis Carroll "Alice's Adventures in Wonderland"
Re: [RFC][PATCH] swsusp: do not use higher order allocations on resume [update 2]
Quoted 18 lines · Rafael J. Wysocki
Quoted 5 lines · Pavel Machek
Hi!
Quoted 1 line
+static inline void
eat_page(void *page){Please put { on new line.
Oh, I still tend to forget about this. Corrected in the patch that is available on the web
(http://www.sisk.pl/kernel/patches/2.6.11-rc3-mm1/swsusp-use-list-resume-v4.patch).Quoted 5 lines
Okay, as you can see, I could find very little wrong with this patch. That hopefully means it is okay ;-). I should still check error handling, but I guess I'll do it when it is applied because it is hard to do on a diff. I guess it should go into -mm just after 2.6.11 is released...
Quoted 4 lines
That would be great!
Greets,
Rafael
Here is powerpc port support for that. Thanks for greate patch.
arch/ppc/Kconfig +2 -0
@@ -1068,6 +1068,8 @@ config PROC_HARDWARE source "drivers/zorro/Kconfig" +source kernel/power/Kconfig + endmenu menu "Bus options"
arch/ppc/kernel/Makefile +1 -0
@@ -16,6 +16,7 @@ obj-y := entry.o traps.o irq.o idle.o semaphore.o syscalls.o setup.o \ cputable.o ppc_htab.o perfmon.o obj-$(CONFIG_6xx) += l2cr.o cpu_setup_6xx.o +obj-$(CONFIG_SOFTWARE_SUSPEND) += swsusp.o obj-$(CONFIG_POWER4) += cpu_setup_power4.o obj-$(CONFIG_MODULES) += module.o ppc_ksyms.o obj-$(CONFIG_NOT_COHERENT_CACHE) += dma-mapping.o
arch/ppc/kernel/signal.c +10 -0
@@ -28,6 +28,7 @@#include <linux/elf.h> #include <linux/tty.h> #include <linux/binfmts.h> +#include <linux/suspend.h> #include <asm/ucontext.h> #include <asm/uaccess.h> #include <asm/pgtable.h>
@@ -704,6 +705,14 @@ int do_signal(sigset_t *oldset, struct punsigned long frame, newsp;int signr, ret; +if (current->flags &PF_FREEZE ) { +refrigerator (PF_FREEZE ); + signr =0 ; + ret = regs->gpr[3 ]; +if (!signal_pending (current)) + goto no_signal; + } +if (!oldset) oldset = ¤t->blocked;
@@ -726,6 +735,7 @@ int do_signal(sigset_t *oldset, struct p regs->gpr[3 ] =EINTR ;/* note that the cr0.SO bit is already set */ }else { +no_signal: regs->nip -=4 ;/* Back up & retry system call */ regs->result =0 ; regs->trap =0 ;
arch/ppc/kernel/swsusp.S new file +349 -0
349 lines not on this page · raw message
arch/ppc/kernel/vmlinux.lds.S +6 -0
@@ -74,6 +74,12 @@ SECTIONS CONSTRUCTORS } + . = ALIGN(4096); + __nosave_begin = .; + .data_nosave : { *(.data.nosave) } + . = ALIGN(4096); + __nosave_end = .; + . = ALIGN(32); .data.cacheline_aligned : { *(.data.cacheline_aligned) }
drivers/macintosh/via-pmu.c +84 -2
110 lines not on this page · raw message
arch/ppc/platforms/pmac_setup.c +55 -0
77 lines not on this page · raw message
include/asm-ppc/suspend.h new file +12 -0
@@ -0,0 +1,12 @@ +static inline int arch_prepare_suspend (void ) +{ +return 0 ; +} + +static inline void save_processor_state (void ) +{ +} + +static inline void restore_processor_state (void ) +{ +}
include/linux/suspend.h +1 -1
@@ -1,7 +1,7 @@#ifndef _LINUX_SWSUSP_H#define _LINUX_SWSUSP_H -#if defined(CONFIG_X86 ) || defined(CONFIG_FRV ) +#if defined(CONFIG_X86 ) || defined(CONFIG_FRV ) || defined(CONFIG_PPC32 )#include <asm/suspend.h> #endif #include <linux/swap.h>
Signature · 5 lines
Hu Gang .-.
/v\
// \\
Linux User /( )\ [204016]
GPG Key ID ^^-^^ http://soulinfo.com/~hugang/hugang.ascRe: [RFC][PATCH] swsusp: do not use higher order allocations on resume [update 2]
Quoted 19 lines · On Sun, Feb 13, 2005 at 01:04:56PM +0706, [email protected] wrote:
Quoted 18 lines · Rafael J. Wysocki
Quoted 5 lines · Pavel Machek
Hi!
Quoted 1 line
+static inline void
eat_page(void *page){Please put { on new line.
Oh, I still tend to forget about this. Corrected in the patch that is available on the web
(http://www.sisk.pl/kernel/patches/2.6.11-rc3-mm1/swsusp-use-list-resume-v4.patch).Quoted 5 lines
Okay, as you can see, I could find very little wrong with this patch. That hopefully means it is okay ;-). I should still check error handling, but I guess I'll do it when it is applied because it is hard to do on a diff. I guess it should go into -mm just after 2.6.11 is released...
Quoted 7 lines
Quoted 4 lines
That would be great!
Greets,
RafaelHere is powerpc port support for that. Thanks for greate patch.
Sorry I forgot this one.
arch/ppc/kernel/asm-offsets.c +5 -0
@@ -16,6 +16,7 @@#include <linux/string.h> #include <linux/types.h> #include <linux/ptrace.h> +#include <linux/suspend.h> #include <linux/mman.h> #include <linux/mm.h> #include <asm/io.h>
@@ -136,6 +137,10 @@ main(void)DEFINE (TI_CPU , offsetof(struct thread_info , cpu));DEFINE (TI_PREEMPT , offsetof(struct thread_info , preempt_count)); +DEFINE (pbe_address, offsetof(struct pbe , address)); +DEFINE (pbe_orig_address, offsetof(struct pbe , orig_address)); +DEFINE (pbe_next, offsetof(struct pbe , next)); +DEFINE (NUM_USER_SEGMENTS ,TASK_SIZE >>28 );return 0 ; }
Signature · 5 lines
Hu Gang .-.
/v\
// \\
Linux User /( )\ [204016]
GPG Key ID ^^-^^ http://soulinfo.com/~hugang/hugang.asc