aboutsummaryrefslogtreecommitdiffstats
path: root/kernel/power/swsusp.c
diff options
context:
space:
mode:
authorRafael J. Wysocki <rjw@sisk.pl>2005-11-09 00:34:39 -0500
committerLinus Torvalds <torvalds@g5.osdl.org>2005-11-09 10:55:52 -0500
commit054bd4c18853f3a3851bd97aa90e11022a69dc42 (patch)
tree6d4aa1416b4837930ed517aa8c6e741ff45e5d9b /kernel/power/swsusp.c
parenta31751e04ea738acc8042e5aa1a825901aa7b97f (diff)
[PATCH] swsusp: reduce code duplication
The changes made by this patch are necessary for the pagedir relocation simplification in the next patch.  Additionally, these changes allow us to drop check_pagedir() and make get_safe_page() be a one-line wrapper around alloc_image_page() (get_safe_page() goes to snapshot.c, because alloc_image_page() is static and it does not make sense to export it). Signed-off-by: Rafael J. Wysocki <rjw@sisk.pl> Cc: Pavel Machek <pavel@ucw.cz> Signed-off-by: Andrew Morton <akpm@osdl.org> Signed-off-by: Linus Torvalds <torvalds@osdl.org>
Diffstat (limited to 'kernel/power/swsusp.c')
-rw-r--r--kernel/power/swsusp.c57
1 files changed, 2 insertions, 55 deletions
diff --git a/kernel/power/swsusp.c b/kernel/power/swsusp.c
index e1ab28b9b217..a456ffe7a3c8 100644
--- a/kernel/power/swsusp.c
+++ b/kernel/power/swsusp.c
@@ -629,59 +629,6 @@ int swsusp_resume(void)
629} 629}
630 630
631/** 631/**
632 * On resume, for storing the PBE list and the image,
633 * we can only use memory pages that do not conflict with the pages
634 * which had been used before suspend.
635 *
636 * We don't know which pages are usable until we allocate them.
637 *
638 * Allocated but unusable (ie eaten) memory pages are marked so that
639 * swsusp_free() can release them
640 */
641
642unsigned long get_safe_page(gfp_t gfp_mask)
643{
644 unsigned long m;
645
646 do {
647 m = get_zeroed_page(gfp_mask);
648 if (m && PageNosaveFree(virt_to_page(m)))
649 /* This is for swsusp_free() */
650 SetPageNosave(virt_to_page(m));
651 } while (m && PageNosaveFree(virt_to_page(m)));
652 if (m) {
653 /* This is for swsusp_free() */
654 SetPageNosave(virt_to_page(m));
655 SetPageNosaveFree(virt_to_page(m));
656 }
657 return m;
658}
659
660/**
661 * check_pagedir - We ensure here that pages that the PBEs point to
662 * won't collide with pages where we're going to restore from the loaded
663 * pages later
664 */
665
666static int check_pagedir(struct pbe *pblist)
667{
668 struct pbe *p;
669
670 /* This is necessary, so that we can free allocated pages
671 * in case of failure
672 */
673 for_each_pbe (p, pblist)
674 p->address = 0UL;
675
676 for_each_pbe (p, pblist) {
677 p->address = get_safe_page(GFP_ATOMIC);
678 if (!p->address)
679 return -ENOMEM;
680 }
681 return 0;
682}
683
684/**
685 * swsusp_pagedir_relocate - It is possible, that some memory pages 632 * swsusp_pagedir_relocate - It is possible, that some memory pages
686 * occupied by the list of PBEs collide with pages where we're going to 633 * occupied by the list of PBEs collide with pages where we're going to
687 * restore from the loaded pages later. We relocate them here. 634 * restore from the loaded pages later. We relocate them here.
@@ -990,7 +937,7 @@ static int read_suspend_image(void)
990 int error = 0; 937 int error = 0;
991 struct pbe *p; 938 struct pbe *p;
992 939
993 if (!(p = alloc_pagedir(nr_copy_pages))) 940 if (!(p = alloc_pagedir(nr_copy_pages, GFP_ATOMIC, 0)))
994 return -ENOMEM; 941 return -ENOMEM;
995 942
996 if ((error = read_pagedir(p))) 943 if ((error = read_pagedir(p)))
@@ -1003,7 +950,7 @@ static int read_suspend_image(void)
1003 950
1004 /* Allocate memory for the image and read the data from swap */ 951 /* Allocate memory for the image and read the data from swap */
1005 952
1006 error = check_pagedir(pagedir_nosave); 953 error = alloc_data_pages(pagedir_nosave, GFP_ATOMIC, 1);
1007 954
1008 if (!error) 955 if (!error)
1009 error = data_read(pagedir_nosave); 956 error = data_read(pagedir_nosave);